@Test public void testParse() throws ServiceException, URISyntaxException, NoSuchAuthorityCodeException, FactoryException { SimpleFeature shp16 = getSHP16(); Geometry geom = (Geometry) shp16.getDefaultGeometry(); assertTrue(geom instanceof MultiPolygon); MultiPolygon mp = (MultiPolygon) geom; assertEquals(14, mp.getNumGeometries()); Polygon p = (Polygon) mp.getGeometryN(0); CoordinateSequence exterior = p.getExteriorRing().getCoordinateSequence(); Coordinate first = exterior.getCoordinate(0); assertEquals(194831.89, first.x, 1e6); assertEquals(6947066.665, first.y, 1e6); assertTrue(Double.isNaN(first.z)); }
@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; }