@Test public void testParseToDifferentProjecion() throws ServiceException, URISyntaxException, NoSuchAuthorityCodeException, FactoryException { File file = new File(SHPParserTest.class.getResource("SHP2017.shp").toURI()); SHPParser parser = new SHPParser(); SimpleFeatureCollection fc = parser.parse(file, null, CRS.decode("EPSG:4326")); ReferencedEnvelope bounds = fc.getBounds(); CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem(); assertEquals("Bounds is transformed correctly", "EPSG:4326", CRS.toSRS(crs)); assertEquals(59.80841, bounds.getMinX(), 1e-5); assertEquals(19.47275, bounds.getMinY(), 1e-5); assertEquals(70.09210, bounds.getMaxX(), 1e-5); assertEquals(31.58671, bounds.getMaxY(), 1e-5); }
@Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { ShapefileDataStore store = null; try { store = new ShapefileDataStore(file.toURI().toURL()); store.setCharset(getCharset(file)); String typeName = store.getTypeNames()[0]; SimpleFeatureSource source = store.getFeatureSource(typeName); CoordinateReferenceSystem crs = source.getSchema() .getGeometryDescriptor() .getCoordinateReferenceSystem(); if (crs != null) { sourceCRS = crs; } return FeatureCollectionParsers.read(source, sourceCRS, targetCRS); } catch (ServiceException e) { throw e; } catch (Exception e) { throw new UserLayerException("Failed to parse SHP: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } finally { if (store != null) { store.dispose(); } } }
SHPParser implements FeatureCollectionParser { @Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { ShapefileDataStore store = null; try { store = new ShapefileDataStore(file.toURI().toURL()); store.setCharset(getCharset(file)); String typeName = store.getTypeNames()[0]; SimpleFeatureSource source = store.getFeatureSource(typeName); CoordinateReferenceSystem crs = source.getSchema() .getGeometryDescriptor() .getCoordinateReferenceSystem(); if (crs != null) { sourceCRS = crs; } return FeatureCollectionParsers.read(source, sourceCRS, targetCRS); } catch (ServiceException e) { throw e; } catch (Exception e) { throw new UserLayerException("Failed to parse SHP: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } finally { if (store != null) { store.dispose(); } } } }
SHPParser implements FeatureCollectionParser { @Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { ShapefileDataStore store = null; try { store = new ShapefileDataStore(file.toURI().toURL()); store.setCharset(getCharset(file)); String typeName = store.getTypeNames()[0]; SimpleFeatureSource source = store.getFeatureSource(typeName); CoordinateReferenceSystem crs = source.getSchema() .getGeometryDescriptor() .getCoordinateReferenceSystem(); if (crs != null) { sourceCRS = crs; } return FeatureCollectionParsers.read(source, sourceCRS, targetCRS); } catch (ServiceException e) { throw e; } catch (Exception e) { throw new UserLayerException("Failed to parse SHP: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } finally { if (store != null) { store.dispose(); } } }  }
SHPParser implements FeatureCollectionParser { @Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { ShapefileDataStore store = null; try { store = new ShapefileDataStore(file.toURI().toURL()); store.setCharset(getCharset(file)); String typeName = store.getTypeNames()[0]; SimpleFeatureSource source = store.getFeatureSource(typeName); CoordinateReferenceSystem crs = source.getSchema() .getGeometryDescriptor() .getCoordinateReferenceSystem(); if (crs != null) { sourceCRS = crs; } return FeatureCollectionParsers.read(source, sourceCRS, targetCRS); } catch (ServiceException e) { throw e; } catch (Exception e) { throw new UserLayerException("Failed to parse SHP: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } finally { if (store != null) { store.dispose(); } } }  @Override SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS,
            CoordinateReferenceSystem targetCRS); @Override String getSuffix(); }
SHPParser implements FeatureCollectionParser { @Override public SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws ServiceException { ShapefileDataStore store = null; try { store = new ShapefileDataStore(file.toURI().toURL()); store.setCharset(getCharset(file)); String typeName = store.getTypeNames()[0]; SimpleFeatureSource source = store.getFeatureSource(typeName); CoordinateReferenceSystem crs = source.getSchema() .getGeometryDescriptor() .getCoordinateReferenceSystem(); if (crs != null) { sourceCRS = crs; } return FeatureCollectionParsers.read(source, sourceCRS, targetCRS); } catch (ServiceException e) { throw e; } catch (Exception e) { throw new UserLayerException("Failed to parse SHP: " + e.getMessage(), UserLayerException.ErrorType.PARSER, UserLayerException.ErrorType.INVALID_FORMAT); } finally { if (store != null) { store.dispose(); } } }  @Override SimpleFeatureCollection parse(File file, CoordinateReferenceSystem sourceCRS,
            CoordinateReferenceSystem targetCRS); @Override String getSuffix(); static final String SUFFIX; }