@Test public void testWaypoints() throws URISyntaxException, NoSuchAuthorityCodeException, ServiceException, FactoryException { File file = new File(getClass().getResource("waypoints.gpx").toURI()); GPXParser parser = new GPXParser(); SimpleFeatureCollection fc = parser.parse(file, null, DefaultGeographicCRS.WGS84); assertEquals(2, fc.size()); SimpleFeatureIterator it = fc.features(); try { int i = 1; while (it.hasNext()) { SimpleFeature f = it.next(); assertEquals("name" + i, f.getAttribute("name")); assertEquals("cmt" + i, f.getAttribute("cmt")); assertEquals("desc" + i, f.getAttribute("desc")); assertEquals("src" + i, f.getAttribute("src")); assertEquals("http: assertEquals("linktext" + i, f.getAttribute("linkText")); assertEquals("WayPoint", f.getAttribute("type")); i++; } } 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; }