@Test public void testTrack10() throws ServiceException, URISyntaxException { File file = new File(getClass().getResource("track_10.gpx").toURI()); GPXParser parser = new GPXParser(); SimpleFeatureCollection fc = parser.parse(file, null, DefaultGeographicCRS.WGS84); assertEquals(1, fc.size()); SimpleFeatureIterator it = fc.features(); try { while (it.hasNext()) { SimpleFeature f = it.next(); MultiLineString track = (MultiLineString) f.getDefaultGeometry(); assertEquals(1, track.getNumGeometries()); LineString tracksegment = (LineString) track.getGeometryN(0); CoordinateSequence csq = tracksegment.getCoordinateSequence(); assertEquals(2, csq.size()); assertEquals(25.704601407051086, csq.getX(0), 1e-8); assertEquals(62.494332790374756, csq.getY(0), 1e-8); assertEquals(152.50732421875, csq.getOrdinate(0, 2), 1e-8); assertEquals(25.704869627952576, csq.getX(1), 1e-8); assertEquals(62.49429523944855, csq.getY(1), 1e-8); assertEquals(149.7603759765625, csq.getOrdinate(1, 2), 1e-8); } } finally { it.close(); } }
@Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { try { sourceCRS = CRS.decode("EPSG:4326", true); } catch (FactoryException e) { throw new ServiceException("Failed to decode sourceCrs (EPSG:4326) for GPXParser"); } try { SimpleFeatureCollection parsed; parsed = parse(file, GPX.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } return parsed; } catch (Exception e) { throw new UserLayerException("Failed to parse GPX: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } }
GPXParser implements FeatureCollectionParser { @Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { try { sourceCRS = CRS.decode("EPSG:4326", true); } catch (FactoryException e) { throw new ServiceException("Failed to decode sourceCrs (EPSG:4326) for GPXParser"); } try { SimpleFeatureCollection parsed; parsed = parse(file, GPX.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } return parsed; } catch (Exception e) { throw new UserLayerException("Failed to parse GPX: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } } }
GPXParser implements FeatureCollectionParser { @Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { try { sourceCRS = CRS.decode("EPSG:4326", true); } catch (FactoryException e) { throw new ServiceException("Failed to decode sourceCrs (EPSG:4326) for GPXParser"); } try { SimpleFeatureCollection parsed; parsed = parse(file, GPX.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } return parsed; } catch (Exception e) { throw new UserLayerException("Failed to parse GPX: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } }  }
GPXParser implements FeatureCollectionParser { @Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { try { sourceCRS = CRS.decode("EPSG:4326", true); } catch (FactoryException e) { throw new ServiceException("Failed to decode sourceCrs (EPSG:4326) for GPXParser"); } try { SimpleFeatureCollection parsed; parsed = parse(file, GPX.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } return parsed; } catch (Exception e) { throw new UserLayerException("Failed to parse GPX: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } }  @Override SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS,
            CoordinateReferenceSystem targetCRS); @Override String getSuffix(); }
GPXParser implements FeatureCollectionParser { @Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { try { sourceCRS = CRS.decode("EPSG:4326", true); } catch (FactoryException e) { throw new ServiceException("Failed to decode sourceCrs (EPSG:4326) for GPXParser"); } try { SimpleFeatureCollection parsed; parsed = parse(file, GPX.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.trkType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.rteType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse(file, GPX.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } parsed = parse10(file, GPX10.wptType); if (!parsed.isEmpty()) { return new ReprojectingFeatureCollection(parsed, sourceCRS, targetCRS); } return parsed; } catch (Exception e) { throw new UserLayerException("Failed to parse GPX: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } }  @Override SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS,
            CoordinateReferenceSystem targetCRS); @Override String getSuffix(); static final String SUFFIX; }