Element testing = (Element) XPath.selectSingleNode(gpxDoc, "/gpx/trk/@*");
private void LoadGPXTracks(File importFile) throws JDOMException, IOException, ParseException { //XML-Datei einladen Document gpxDoc = new SAXBuilder().build(importFile); Namespace gpx_ns = Namespace.getNamespace("http://www.topografix.com/GPX/1/1"); Element gpx_root = gpxDoc.getRootElement(); int j = 0; for (Iterator it = gpx_root.getChildren("trk", gpx_ns).iterator(); it.hasNext();) { Element trk = (Element) it.next(); if("trk".equals(trk.getName())) { IFeature feature = _featureClassTracks.createFeature(); int contractorFieldIndex = _featureClassTracks.findField("objname"); if (contractorFieldIndex >= 0) feature.setValue(contractorFieldIndex, trk.getChildText("name", gpx_ns).toString()); contractorFieldIndex = _featureClassTracks.findField("kern_id"); if (contractorFieldIndex >= 0) feature.setValue(contractorFieldIndex, j++); IGeometryBridge2 pGeoBrg = new GeometryEnvironment(); IPointCollection4 pPointColl = new Polyline(); //List<?> trackSegsInfo = XPath.selectNodes(gpxDoc, "/gpx/trk/trkseg/"); int i = 0; Element trk_seg = null; for (Iterator it_seg = trk.getChildren("trkseg", gpx_ns).iterator(); it_seg.hasNext();) { trk_seg = (Element) it_seg.next(); for (Iterator trk_pt_count = trk_seg.getChildren("trkpt", gpx_ns).iterator(); trk_pt_count.hasNext();) { Element trk_pt_count_elem = (Element) trk_pt_count.next(); i++; } } Point point_help = new Point(); IPoint aPointBuffer = point_help; IPoint[] aPointBufferArray = new Point; i = 0; for (Iterator it_pt = trk_seg.getChildren("trkpt", gpx_ns).iterator(); it_pt.hasNext();) { Element trk_pt = (Element) it_pt.next(); String longitude = null; String latitude = null; Iterator it_trk_pt_attr = trk_pt.getAttributes().iterator(); it_trk_pt_attr.hasNext(); Attribute trk_pt_attr = (Attribute) it_trk_pt_attr.next(); latitude = trk_pt_attr.getValue().toString(); trk_pt_attr = (Attribute) it_trk_pt_attr.next(); longitude = trk_pt_attr.getValue().toString(); String elevation = trk_pt.getChildText("ele", gpx_ns).toString(); String time = trk_pt.getChildText("time", gpx_ns).toString(); Point point = CreatePoint(longitude, latitude, elevation != null ? elevation : "0"); aPointBuffer = point; aPointBufferArray = aPointBuffer; IFeature trkPntFeature = _featureClassTrackPoints.createFeature(); trkPntFeature.setShapeByRef(point); if (time != null) { DateFormat format = new SimpleDateFormat("yyyy'-'MM'-'dd'T'hh:mm:ss"); Date d = format.parse(time); trkPntFeature.setValue(trkPntFeature.getFields().findField("time"), d); } trkPntFeature.store(); i++; } pGeoBrg.setPoints(pPointColl, aPointBufferArray); feature.setShapeByRef((IPolyline) pPointColl); feature.store(); } it.next(); } }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.