Add support for gpx metadata bounds
This commit is contained in:
parent
ef178c7b0d
commit
444f6c02a5
1 changed files with 40 additions and 0 deletions
|
@ -323,6 +323,7 @@ public class GPXUtilities {
|
||||||
public long time = 0;
|
public long time = 0;
|
||||||
public Author author = null;
|
public Author author = null;
|
||||||
public Copyright copyright = null;
|
public Copyright copyright = null;
|
||||||
|
public Bounds bounds = null;
|
||||||
|
|
||||||
public String getArticleTitle() {
|
public String getArticleTitle() {
|
||||||
return getExtensionsToRead().get("article_title");
|
return getExtensionsToRead().get("article_title");
|
||||||
|
@ -345,6 +346,13 @@ public class GPXUtilities {
|
||||||
public String license;
|
public String license;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Bounds extends GPXExtensions {
|
||||||
|
public double minlat;
|
||||||
|
public double minlon;
|
||||||
|
public double maxlat;
|
||||||
|
public double maxlon;
|
||||||
|
}
|
||||||
|
|
||||||
public static class GPXTrackAnalysis {
|
public static class GPXTrackAnalysis {
|
||||||
public float totalDistance = 0;
|
public float totalDistance = 0;
|
||||||
public int totalTracks = 0;
|
public int totalTracks = 0;
|
||||||
|
@ -1438,6 +1446,11 @@ public class GPXUtilities {
|
||||||
writeNotNullText(serializer, "time", format.format(new Date(file.metadata.time)));
|
writeNotNullText(serializer, "time", format.format(new Date(file.metadata.time)));
|
||||||
}
|
}
|
||||||
writeNotNullText(serializer, "keywords", file.metadata.keywords);
|
writeNotNullText(serializer, "keywords", file.metadata.keywords);
|
||||||
|
if (file.metadata.bounds != null) {
|
||||||
|
serializer.startTag(null, "bounds");
|
||||||
|
writeBounds(serializer, file.metadata.bounds);
|
||||||
|
serializer.endTag(null, "bounds");
|
||||||
|
}
|
||||||
writeExtensions(serializer, file.metadata);
|
writeExtensions(serializer, file.metadata);
|
||||||
}
|
}
|
||||||
serializer.endTag(null, "metadata");
|
serializer.endTag(null, "metadata");
|
||||||
|
@ -1577,6 +1590,13 @@ public class GPXUtilities {
|
||||||
writeNotNullText(serializer, "license", copyright.license);
|
writeNotNullText(serializer, "license", copyright.license);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void writeBounds(XmlSerializer serializer, Bounds bounds) throws IOException {
|
||||||
|
serializer.attribute(null, "minlat", latLonFormat.format(bounds.minlat));
|
||||||
|
serializer.attribute(null, "minlon", latLonFormat.format(bounds.minlon));
|
||||||
|
serializer.attribute(null, "maxlat", latLonFormat.format(bounds.maxlat));
|
||||||
|
serializer.attribute(null, "maxlon", latLonFormat.format(bounds.maxlon));
|
||||||
|
}
|
||||||
|
|
||||||
public static class GPXFileResult {
|
public static class GPXFileResult {
|
||||||
public ArrayList<List<Location>> locations = new ArrayList<List<Location>>();
|
public ArrayList<List<Location>> locations = new ArrayList<List<Location>>();
|
||||||
public ArrayList<WptPt> wayPoints = new ArrayList<>();
|
public ArrayList<WptPt> wayPoints = new ArrayList<>();
|
||||||
|
@ -1794,6 +1814,11 @@ public class GPXUtilities {
|
||||||
if (tag.equals("keywords")) {
|
if (tag.equals("keywords")) {
|
||||||
((Metadata) parse).keywords = readText(parser, "keywords");
|
((Metadata) parse).keywords = readText(parser, "keywords");
|
||||||
}
|
}
|
||||||
|
if (tag.equals("bounds")) {
|
||||||
|
Bounds bounds = parseBoundsAttributes(parser);
|
||||||
|
((Metadata) parse).bounds = bounds;
|
||||||
|
parserState.push(bounds);
|
||||||
|
}
|
||||||
} else if (parse instanceof Author) {
|
} else if (parse instanceof Author) {
|
||||||
if (tag.equals("name")) {
|
if (tag.equals("name")) {
|
||||||
((Author) parse).name = readText(parser, "name");
|
((Author) parse).name = readText(parser, "name");
|
||||||
|
@ -1945,6 +1970,9 @@ public class GPXUtilities {
|
||||||
} else if (tag.equals("copyright")) {
|
} else if (tag.equals("copyright")) {
|
||||||
Object pop = parserState.pop();
|
Object pop = parserState.pop();
|
||||||
assert pop instanceof Copyright;
|
assert pop instanceof Copyright;
|
||||||
|
} else if (tag.equals("bounds")) {
|
||||||
|
Object pop = parserState.pop();
|
||||||
|
assert pop instanceof Bounds;
|
||||||
} else if (tag.equals("trkpt")) {
|
} else if (tag.equals("trkpt")) {
|
||||||
Object pop = parserState.pop();
|
Object pop = parserState.pop();
|
||||||
assert pop instanceof WptPt;
|
assert pop instanceof WptPt;
|
||||||
|
@ -2014,6 +2042,18 @@ public class GPXUtilities {
|
||||||
return wpt;
|
return wpt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Bounds parseBoundsAttributes(XmlPullParser parser) {
|
||||||
|
Bounds bounds = new Bounds();
|
||||||
|
try {
|
||||||
|
bounds.minlat = Double.parseDouble(parser.getAttributeValue("", "minlat"));
|
||||||
|
bounds.minlon = Double.parseDouble(parser.getAttributeValue("", "minlon"));
|
||||||
|
bounds.maxlat = Double.parseDouble(parser.getAttributeValue("", "maxlat"));
|
||||||
|
bounds.maxlon = Double.parseDouble(parser.getAttributeValue("", "maxlon"));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
public static void mergeGPXFileInto(GPXFile to, GPXFile from) {
|
public static void mergeGPXFileInto(GPXFile to, GPXFile from) {
|
||||||
if (from == null) {
|
if (from == null) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue