This commit is contained in:
PavelRatushny 2017-10-06 15:34:40 +03:00
parent 12b12896b4
commit 5a13afb387
2 changed files with 140 additions and 106 deletions

View file

@ -1447,6 +1447,29 @@ public class GPXUtilities {
((TrkSegment) parse).points.add(wptPt); ((TrkSegment) parse).points.add(wptPt);
parserState.push(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 // main object to parse
} else if (parse instanceof WptPt) { } else if (parse instanceof WptPt) {
if (parser.getName().equals("name")) { if (parser.getName().equals("name")) {

View file

@ -6,68 +6,69 @@
http://opensource.org/licenses/gpl-2.0.php http://opensource.org/licenses/gpl-2.0.php
--> -->
<xsl:stylesheet version="1.0" <xsl:stylesheet xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:kml="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:ge="http://earth.google.com/kml/2.2" xmlns:ge="http://earth.google.com/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:atom="http://www.w3.org/2005/Atom" xmlns:kml="http://www.opengis.net/kml/2.2"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
indent="yes" /> version="1.0">
<xsl:output indent="yes"
method="xml"/>
<xsl:template match="/"> <xsl:template match="/">
<gpx version="1.1" <gpx creator="kml2gpx.xslt"
creator="kml2gpx.xslt" version="1.1"
xmlns="http://www.topografix.com/GPX/1/1"> xmlns="http://www.topografix.com/GPX/1/1">
<metadata> <metadata>
<name><xsl:value-of select="kml:kml/kml:Document/kml:name"/></name> <name><xsl:value-of select="kml:kml/kml:Document/kml:name"/></name>
<author> <author>
<name> <name>
<xsl:value-of select="kml:kml/kml:Document/atom:author/atom:author"/> <xsl:value-of select="kml:kml/kml:Document/atom:author/atom:author"/>
</name> </name>
</author> </author>
</metadata> </metadata>
<xsl:for-each select="//ge:Placemark"> <xsl:for-each select="//ge:Placemark">
<xsl:variable name="lonlat" select="ge:Point/ge:coordinates"/> <xsl:variable name="lonlat" select="ge:Point/ge:coordinates"/>
<xsl:variable name="lon" select="substring-before($lonlat,' ')"/> <xsl:variable name="lon" select="substring-before($lonlat,' ')"/>
<xsl:variable name="latele" select="substring-after($lonlat,' ')"/> <xsl:variable name="latele" select="substring-after($lonlat,' ')"/>
<xsl:variable name="lat"> <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:choose>
<xsl:when test="contains($latele,' ')"> <xsl:when test="contains($latele,',')">
<xsl:value-of select="substring-before($latele,' ')"/> <ele><xsl:value-of select="substring-after($latele,',')"/></ele>
</xsl:when> </xsl:when>
<xsl:otherwise>
<xsl:value-of select="$latele"/>
</xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> <type>
<xsl:variable name="foldername" select="../ge:name"/> <xsl:value-of select="$foldername"/>
</type>
<xsl:if test="$lon"> <name>
<wpt lon="{$lon}" lat="{$lat}"> <xsl:value-of select="ge:name"/>
<xsl:choose> </name>
<xsl:when test="contains($latele,',')"> <xsl:if test="ge:description">
<ele> <xsl:value-of select="substring-after($latele,',')"/></ele> <desc>
</xsl:when> <xsl:value-of select="ge:description"/>
</xsl:choose> </desc>
<type> </xsl:if>
<xsl:value-of select="$foldername"/> </wpt>
</type> </xsl:if>
<name> </xsl:for-each>
<xsl:value-of select="ge:name"/> <xsl:for-each select="//kml:Placemark">
</name> <xsl:if test="kml:Point">
<xsl:if test="ge:description"> <xsl:variable name="lonlat" select="kml:Point/kml:coordinates"/>
<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:variable name="lon" select="substring-before($lonlat,',')"/> <xsl:variable name="lon" select="substring-before($lonlat,',')"/>
<xsl:variable name="latele" select="substring-after($lonlat,',')"/> <xsl:variable name="latele" select="substring-after($lonlat,',')"/>
<xsl:variable name="lat"> <xsl:variable name="lat">
@ -75,66 +76,76 @@
<xsl:when test="contains($latele,',')"> <xsl:when test="contains($latele,',')">
<xsl:value-of select="substring-before($latele,',')"/> <xsl:value-of select="substring-before($latele,',')"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="$latele"/> <xsl:value-of select="$latele"/>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
<xsl:variable name="foldername" select="../kml:name"/> <xsl:variable name="foldername" select="../kml:name"/>
<xsl:if test="$lon"> <xsl:if test="$lon">
<wpt lon="{$lon}" lat="{$lat}"> <wpt lon="{$lon}" lat="{$lat}">
<xsl:choose> <xsl:choose>
<xsl:when test="contains($latele,',')"> <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:when>
</xsl:choose> </xsl:choose>
<type> <type>
<xsl:value-of select="$foldername"/> <xsl:value-of select="$foldername"/>
</type> </type>
<name> <name>
<xsl:value-of select="kml:name"/> <xsl:value-of select="kml:name"/>
</name> </name>
<xsl:if test="kml:description"> <xsl:if test="kml:description">
<desc> <desc>
<xsl:value-of select="kml:description"/> <xsl:value-of select="kml:description"/>
</desc> </desc>
</xsl:if> </xsl:if>
</wpt> </wpt>
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:if>
<xsl:for-each select="//gx:Track">
<trk> <xsl:if test="kml:MultiGeometry/kml:LineString/kml:coordinates">
<trkseg> <trk>
<xsl:for-each select="gx:coord"> <trkseg>
<xsl:variable name="i" select="position()"/> <trkptsattrs><xsl:value-of select="kml:MultiGeometry/kml:LineString/kml:coordinates"/></trkptsattrs>
<xsl:variable name="lonlat" select="."/> </trkseg>
<xsl:variable name="lon" select="substring-before($lonlat,' ')"/> </trk>
<xsl:variable name="latele" select="substring-after($lonlat,' ')"/> </xsl:if>
<xsl:variable name="lat">
<xsl:choose> </xsl:for-each>
<xsl:when test="contains($latele,' ')"> <xsl:for-each select="//gx:Track">
<xsl:value-of select="substring-before($latele,' ')"/> <trk>
</xsl:when> <trkseg>
<xsl:otherwise> <xsl:for-each select="gx:coord">
<xsl:value-of select="$latele"/> <xsl:variable name="i" select="position()"/>
</xsl:otherwise> <xsl:variable name="lonlat" select="."/>
</xsl:choose> <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>
<trkpt lon="{$lon}" lat="{$lat}"> <trkpt lon="{$lon}" lat="{$lat}">
<xsl:choose> <xsl:choose>
<xsl:when test="contains($latele,' ')"> <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:when>
</xsl:choose> </xsl:choose>
<xsl:variable name="ts" select="../kml:when[$i]"/> <xsl:variable name="ts" select="../kml:when[$i]"/>
<xsl:if test="$ts"> <xsl:if test="$ts">
<time><xsl:value-of select="$ts"/></time> <time><xsl:value-of select="$ts"/></time>
</xsl:if> </xsl:if>
</trkpt> </trkpt>
</xsl:for-each> </xsl:for-each>
</trkseg> </trkseg>
</trk> </trk>
</xsl:for-each> </xsl:for-each>
</gpx> </gpx>
</xsl:template> </xsl:template>
@ -142,4 +153,4 @@
<xsl:template match="gx:Track"> <xsl:template match="gx:Track">
</xsl:template> </xsl:template>
</xsl:stylesheet> </xsl:stylesheet>