Changeset 33791 in osm for applications/editors/josm/plugins/opendata
- Timestamp:
- 2017-11-06T00:58:05+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmlReader.java
r33245 r33791 30 30 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 31 31 import org.openstreetmap.josm.plugins.opendata.core.io.ProjectionPatterns; 32 import org.openstreetmap.josm.tools.date.DateUtils; 32 33 33 34 public class KmlReader extends AbstractReader { … … 45 46 public static final String KML_LINEAR_RING = "LinearRing"; 46 47 public static final String KML_COORDINATES = "coordinates"; 48 public static final String KML_WHEN = "when"; 49 50 public static final String KML_EXT_TRACK = "Track"; 51 public static final String KML_EXT_COORD = "coord"; 47 52 // CHECKSTYLE.ON: SingleSpaceSeparator 48 53 … … 93 98 private void parsePlaceMark(DataSet ds) throws XMLStreamException { 94 99 List<OsmPrimitive> list = new ArrayList<>(); 100 long when = 0; 95 101 Way way = null; 96 102 Node node = null; … … 127 133 relation.addMember(new RelationMember(role, way)); 128 134 } 129 } else if (parser.getLocalName().equals(KML_LINE_STRING) ) {135 } else if (parser.getLocalName().equals(KML_LINE_STRING) || parser.getLocalName().equals(KML_EXT_TRACK)) { 130 136 ds.addPrimitive(way = new Way()); 131 137 list.add(way); … … 133 139 String[] tab = parser.getElementText().trim().split("\\s"); 134 140 for (int i = 0; i < tab.length; i++) { 135 String[] values = tab[i].split(","); 136 if (values.length >= 2) { 137 LatLon ll = new LatLon(Double.valueOf(values[1]), Double.valueOf(values[0])).getRoundedToOsmPrecision(); 138 node = nodes.get(ll); 139 if (node == null) { 140 ds.addPrimitive(node = new Node(ll)); 141 nodes.put(ll, node); 142 if (values.length > 2 && !values[2].equals("0")) { 143 node.put("ele", values[2]); 144 } 145 } 146 if (way != null) { 147 way.addNode(node); 148 } 149 } 141 node = parseNode(ds, way, node, tab[i].split(",")); 150 142 } 143 } else if (parser.getLocalName().equals(KML_EXT_COORD)) { 144 node = parseNode(ds, way, node, parser.getElementText().trim().split("\\s")); 145 if (node != null && when > 0) { 146 node.setRawTimestamp((int) when); 147 } 148 } else if (parser.getLocalName().equals(KML_WHEN)) { 149 when = DateUtils.tsFromString(parser.getElementText().trim()); 151 150 } 152 151 } else if (event == XMLStreamConstants.END_ELEMENT) { … … 164 163 } 165 164 } 165 166 private Node parseNode(DataSet ds, Way way, Node node, String[] values) { 167 if (values.length >= 2) { 168 LatLon ll = new LatLon(Double.valueOf(values[1]), Double.valueOf(values[0])).getRoundedToOsmPrecision(); 169 node = nodes.get(ll); 170 if (node == null) { 171 ds.addPrimitive(node = new Node(ll)); 172 nodes.put(ll, node); 173 if (values.length > 2 && !values[2].equals("0")) { 174 node.put("ele", values[2]); 175 } 176 } 177 if (way != null) { 178 way.addNode(node); 179 } 180 } 181 return node; 182 } 166 183 }
Note:
See TracChangeset
for help on using the changeset viewer.