From 5a13afb38749088c1a28ea2287043a18b5e68cc4 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 6 Oct 2017 15:34:40 +0300 Subject: [PATCH 1/3] Fix #4112 --- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 23 ++ .../src/net/osmand/plus/helpers/kml2gpx.xslt | 223 +++++++++--------- 2 files changed, 140 insertions(+), 106 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index 8d96630b1c..3e64bb2b12 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -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")) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/kml2gpx.xslt b/OsmAnd/src/net/osmand/plus/helpers/kml2gpx.xslt index 8b2677e875..00752ebace 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/kml2gpx.xslt +++ b/OsmAnd/src/net/osmand/plus/helpers/kml2gpx.xslt @@ -6,68 +6,69 @@ http://opensource.org/licenses/gpl-2.0.php --> - + xmlns:gx="http://www.google.com/kml/ext/2.2" + xmlns:kml="http://www.opengis.net/kml/2.2" - + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + version="1.0"> + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -75,66 +76,76 @@ - - + + - - - - + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -142,4 +153,4 @@ - \ No newline at end of file + From 87d48b834487e302c2d4e0eb62f232cf671f4d2e Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 6 Oct 2017 17:32:56 +0300 Subject: [PATCH 2/3] Rename tag and remove adding to stack --- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 19 ++++++++----------- .../src/net/osmand/plus/helpers/kml2gpx.xslt | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index 3e64bb2b12..f0ca4a4756 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -1447,27 +1447,24 @@ public class GPXUtilities { ((TrkSegment) parse).points.add(wptPt); parserState.push(wptPt); } - if (parser.getName().equals("trkptsattrs")) { - String segmentPoints = readText(parser, "trkptsattrs"); + if (parser.getName().equals("csvattributes")) { + String segmentPoints = readText(parser, "csvattributes"); 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) { + if (arrLength > 1) { + WptPt wptPt = new WptPt(); wptPt.lon = Double.parseDouble(pointAttrs[0]); - if (arrLength > 1) { - wptPt.lat = Double.parseDouble(pointAttrs[1]); - if (arrLength > 2) { - wptPt.ele = Double.parseDouble(pointAttrs[2]); - } + wptPt.lat = Double.parseDouble(pointAttrs[1]); + if (arrLength > 2) { + wptPt.ele = Double.parseDouble(pointAttrs[2]); } + ((TrkSegment) parse).points.add(wptPt); } } catch (NumberFormatException e) { } - ((TrkSegment) parse).points.add(wptPt); - parserState.push(wptPt); } } // main object to parse diff --git a/OsmAnd/src/net/osmand/plus/helpers/kml2gpx.xslt b/OsmAnd/src/net/osmand/plus/helpers/kml2gpx.xslt index 00752ebace..2d5b32048a 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/kml2gpx.xslt +++ b/OsmAnd/src/net/osmand/plus/helpers/kml2gpx.xslt @@ -108,7 +108,7 @@ - + From 12d9eab965a3ae732af093ecfce7ca2046700e9c Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 6 Oct 2017 17:37:54 +0300 Subject: [PATCH 3/3] Create point even without elevation --- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index f0ca4a4756..2b49f5c89a 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -1458,10 +1458,10 @@ public class GPXUtilities { WptPt wptPt = new WptPt(); wptPt.lon = Double.parseDouble(pointAttrs[0]); wptPt.lat = Double.parseDouble(pointAttrs[1]); + ((TrkSegment) parse).points.add(wptPt); if (arrLength > 2) { wptPt.ele = Double.parseDouble(pointAttrs[2]); } - ((TrkSegment) parse).points.add(wptPt); } } catch (NumberFormatException e) { }