Fix #4112
This commit is contained in:
parent
12b12896b4
commit
5a13afb387
2 changed files with 140 additions and 106 deletions
|
@ -1447,6 +1447,29 @@ public class GPXUtilities {
|
|||
((TrkSegment) parse).points.add(wptPt);
|
||||
parserState.push(wptPt);
|
||||
}
|
||||
if (parser.getName().equals("trkptsattrs")) {
|
||||
String segmentPoints = readText(parser, "trkptsattrs");
|
||||
String[] pointsArr = segmentPoints.split("\n");
|
||||
for (int i = 0; i < pointsArr.length; i++) {
|
||||
String[] pointAttrs = pointsArr[i].split(",");
|
||||
WptPt wptPt = new WptPt();
|
||||
try {
|
||||
int arrLength = pointsArr.length;
|
||||
if (arrLength > 0) {
|
||||
wptPt.lon = Double.parseDouble(pointAttrs[0]);
|
||||
if (arrLength > 1) {
|
||||
wptPt.lat = Double.parseDouble(pointAttrs[1]);
|
||||
if (arrLength > 2) {
|
||||
wptPt.ele = Double.parseDouble(pointAttrs[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
((TrkSegment) parse).points.add(wptPt);
|
||||
parserState.push(wptPt);
|
||||
}
|
||||
}
|
||||
// main object to parse
|
||||
} else if (parse instanceof WptPt) {
|
||||
if (parser.getName().equals("name")) {
|
||||
|
|
|
@ -6,68 +6,69 @@
|
|||
http://opensource.org/licenses/gpl-2.0.php
|
||||
-->
|
||||
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:kml="http://www.opengis.net/kml/2.2"
|
||||
xmlns:gx="http://www.google.com/kml/ext/2.2"
|
||||
<xsl:stylesheet xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:ge="http://earth.google.com/kml/2.2"
|
||||
xmlns:gx="http://www.google.com/kml/ext/2.2"
|
||||
xmlns:kml="http://www.opengis.net/kml/2.2"
|
||||
|
||||
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
version="1.0">
|
||||
|
||||
<xsl:output method="xml"
|
||||
indent="yes" />
|
||||
<xsl:output indent="yes"
|
||||
method="xml"/>
|
||||
|
||||
<xsl:template match="/">
|
||||
<gpx version="1.1"
|
||||
creator="kml2gpx.xslt"
|
||||
<gpx creator="kml2gpx.xslt"
|
||||
version="1.1"
|
||||
xmlns="http://www.topografix.com/GPX/1/1">
|
||||
<metadata>
|
||||
<name><xsl:value-of select="kml:kml/kml:Document/kml:name"/></name>
|
||||
<author>
|
||||
<name>
|
||||
<xsl:value-of select="kml:kml/kml:Document/atom:author/atom:author"/>
|
||||
</name>
|
||||
</author>
|
||||
</metadata>
|
||||
<xsl:for-each select="//ge:Placemark">
|
||||
<xsl:variable name="lonlat" select="ge:Point/ge:coordinates"/>
|
||||
<xsl:variable name="lon" select="substring-before($lonlat,' ')"/>
|
||||
<xsl:variable name="latele" select="substring-after($lonlat,' ')"/>
|
||||
<xsl:variable name="lat">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($latele,' ')">
|
||||
<xsl:value-of select="substring-before($latele,' ')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$latele"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="foldername" select="../ge:name"/>
|
||||
<metadata>
|
||||
<name><xsl:value-of select="kml:kml/kml:Document/kml:name"/></name>
|
||||
<author>
|
||||
<name>
|
||||
<xsl:value-of select="kml:kml/kml:Document/atom:author/atom:author"/>
|
||||
</name>
|
||||
</author>
|
||||
</metadata>
|
||||
<xsl:for-each select="//ge:Placemark">
|
||||
<xsl:variable name="lonlat" select="ge:Point/ge:coordinates"/>
|
||||
<xsl:variable name="lon" select="substring-before($lonlat,' ')"/>
|
||||
<xsl:variable name="latele" select="substring-after($lonlat,' ')"/>
|
||||
<xsl:variable name="lat">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($latele,' ')">
|
||||
<xsl:value-of select="substring-before($latele,' ')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$latele"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="foldername" select="../ge:name"/>
|
||||
|
||||
<xsl:if test="$lon">
|
||||
<wpt lon="{$lon}" lat="{$lat}">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($latele,',')">
|
||||
<ele> <xsl:value-of select="substring-after($latele,',')"/></ele>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
<type>
|
||||
<xsl:value-of select="$foldername"/>
|
||||
</type>
|
||||
<name>
|
||||
<xsl:value-of select="ge:name"/>
|
||||
</name>
|
||||
<xsl:if test="ge:description">
|
||||
<desc>
|
||||
<xsl:value-of select="ge:description"/>
|
||||
</desc>
|
||||
</xsl:if>
|
||||
</wpt>
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
<xsl:for-each select="//kml:Placemark">
|
||||
<xsl:variable name="lonlat" select="kml:Point/kml:coordinates"/>
|
||||
<xsl:if test="$lon">
|
||||
<wpt lon="{$lon}" lat="{$lat}">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($latele,',')">
|
||||
<ele><xsl:value-of select="substring-after($latele,',')"/></ele>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
<type>
|
||||
<xsl:value-of select="$foldername"/>
|
||||
</type>
|
||||
<name>
|
||||
<xsl:value-of select="ge:name"/>
|
||||
</name>
|
||||
<xsl:if test="ge:description">
|
||||
<desc>
|
||||
<xsl:value-of select="ge:description"/>
|
||||
</desc>
|
||||
</xsl:if>
|
||||
</wpt>
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
<xsl:for-each select="//kml:Placemark">
|
||||
<xsl:if test="kml:Point">
|
||||
<xsl:variable name="lonlat" select="kml:Point/kml:coordinates"/>
|
||||
<xsl:variable name="lon" select="substring-before($lonlat,',')"/>
|
||||
<xsl:variable name="latele" select="substring-after($lonlat,',')"/>
|
||||
<xsl:variable name="lat">
|
||||
|
@ -75,66 +76,76 @@
|
|||
<xsl:when test="contains($latele,',')">
|
||||
<xsl:value-of select="substring-before($latele,',')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$latele"/>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$latele"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="foldername" select="../kml:name"/>
|
||||
|
||||
<xsl:if test="$lon">
|
||||
<wpt lon="{$lon}" lat="{$lat}">
|
||||
<xsl:choose>
|
||||
<xsl:if test="$lon">
|
||||
<wpt lon="{$lon}" lat="{$lat}">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($latele,',')">
|
||||
<ele> <xsl:value-of select="substring-after($latele,',')"/></ele>
|
||||
<ele><xsl:value-of select="substring-after($latele,',')"/></ele>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
<type>
|
||||
<xsl:value-of select="$foldername"/>
|
||||
</type>
|
||||
<name>
|
||||
<xsl:value-of select="kml:name"/>
|
||||
</name>
|
||||
<xsl:if test="kml:description">
|
||||
<desc>
|
||||
<xsl:value-of select="kml:description"/>
|
||||
</desc>
|
||||
</xsl:if>
|
||||
</wpt>
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
<xsl:for-each select="//gx:Track">
|
||||
<trk>
|
||||
<trkseg>
|
||||
<xsl:for-each select="gx:coord">
|
||||
<xsl:variable name="i" select="position()"/>
|
||||
<xsl:variable name="lonlat" select="."/>
|
||||
<xsl:variable name="lon" select="substring-before($lonlat,' ')"/>
|
||||
<xsl:variable name="latele" select="substring-after($lonlat,' ')"/>
|
||||
<xsl:variable name="lat">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($latele,' ')">
|
||||
<xsl:value-of select="substring-before($latele,' ')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$latele"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:value-of select="$foldername"/>
|
||||
</type>
|
||||
<name>
|
||||
<xsl:value-of select="kml:name"/>
|
||||
</name>
|
||||
<xsl:if test="kml:description">
|
||||
<desc>
|
||||
<xsl:value-of select="kml:description"/>
|
||||
</desc>
|
||||
</xsl:if>
|
||||
</wpt>
|
||||
</xsl:if>
|
||||
</xsl:if>
|
||||
|
||||
<xsl:if test="kml:MultiGeometry/kml:LineString/kml:coordinates">
|
||||
<trk>
|
||||
<trkseg>
|
||||
<trkptsattrs><xsl:value-of select="kml:MultiGeometry/kml:LineString/kml:coordinates"/></trkptsattrs>
|
||||
</trkseg>
|
||||
</trk>
|
||||
</xsl:if>
|
||||
|
||||
</xsl:for-each>
|
||||
<xsl:for-each select="//gx:Track">
|
||||
<trk>
|
||||
<trkseg>
|
||||
<xsl:for-each select="gx:coord">
|
||||
<xsl:variable name="i" select="position()"/>
|
||||
<xsl:variable name="lonlat" select="."/>
|
||||
<xsl:variable name="lon" select="substring-before($lonlat,' ')"/>
|
||||
<xsl:variable name="latele" select="substring-after($lonlat,' ')"/>
|
||||
<xsl:variable name="lat">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($latele,' ')">
|
||||
<xsl:value-of select="substring-before($latele,' ')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$latele"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<trkpt lon="{$lon}" lat="{$lat}">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($latele,' ')">
|
||||
<ele> <xsl:value-of select="substring-after($latele,' ')"/></ele>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
<xsl:variable name="ts" select="../kml:when[$i]"/>
|
||||
<xsl:if test="$ts">
|
||||
<time><xsl:value-of select="$ts"/></time>
|
||||
</xsl:if>
|
||||
</trkpt>
|
||||
</xsl:for-each>
|
||||
</trkseg>
|
||||
</trk>
|
||||
<trkpt lon="{$lon}" lat="{$lat}">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($latele,' ')">
|
||||
<ele><xsl:value-of select="substring-after($latele,' ')"/></ele>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
<xsl:variable name="ts" select="../kml:when[$i]"/>
|
||||
<xsl:if test="$ts">
|
||||
<time><xsl:value-of select="$ts"/></time>
|
||||
</xsl:if>
|
||||
</trkpt>
|
||||
</xsl:for-each>
|
||||
</trkseg>
|
||||
</trk>
|
||||
</xsl:for-each>
|
||||
</gpx>
|
||||
</xsl:template>
|
||||
|
|
Loading…
Reference in a new issue