@Test public void testReprojectWithUserData() throws Exception { SimpleFeatureType featureType = DataUtilities.createType("feature", "id:string,geometry:Point:srid=4326"); SimpleFeature feature = DataUtilities.createFeature(featureType, "1|POINT(1 2)"); ListFeatureCollection features = new ListFeatureCollection(featureType); features.add(feature); feature.getUserData().put("someKey", "someValue"); CoordinateReferenceSystem sphericalMercator = CRS.decode("EPSG:3857"); FeatureReader<SimpleFeatureType, SimpleFeature> reader = DataUtilities.reader((SimpleFeatureCollection) features); int featuresCount = 0; try (ReprojectFeatureReader reprojected = new ReprojectFeatureReader(reader, sphericalMercator)) { SimpleFeature reprojectedFeature = reprojected.next(); assertThat(reprojectedFeature, notNullValue()); Point geometry = (Point) reprojectedFeature.getDefaultGeometry(); checkDoubleValue(geometry.getX(), 222638.9816, 0.0001); checkDoubleValue(geometry.getY(), 111325.1429, 0.0001); assertThat(reprojectedFeature.getUserData().get("someKey"), is("someValue")); featuresCount++; } assertThat(featuresCount, is(1)); }
public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (reader == null) { throw new IllegalStateException("Reader has already been closed"); } SimpleFeature next = reader.next(); Object[] attributes = next.getAttributes().toArray(); try { for (int i = 0; i < attributes.length; i++) { if (attributes[i] instanceof Geometry) { attributes[i] = transformer.transform((Geometry) attributes[i]); } } } catch (TransformException e) { throw new DataSourceException( "A transformation exception occurred while reprojecting data on the fly", e); } SimpleFeature reprojected = SimpleFeatureBuilder.build(schema, attributes, next.getID()); if (next.hasUserData()) { reprojected.getUserData().putAll(next.getUserData()); } return reprojected; }
ReprojectFeatureReader implements DelegatingFeatureReader<SimpleFeatureType, SimpleFeature> { public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (reader == null) { throw new IllegalStateException("Reader has already been closed"); } SimpleFeature next = reader.next(); Object[] attributes = next.getAttributes().toArray(); try { for (int i = 0; i < attributes.length; i++) { if (attributes[i] instanceof Geometry) { attributes[i] = transformer.transform((Geometry) attributes[i]); } } } catch (TransformException e) { throw new DataSourceException( "A transformation exception occurred while reprojecting data on the fly", e); } SimpleFeature reprojected = SimpleFeatureBuilder.build(schema, attributes, next.getID()); if (next.hasUserData()) { reprojected.getUserData().putAll(next.getUserData()); } return reprojected; } }
ReprojectFeatureReader implements DelegatingFeatureReader<SimpleFeatureType, SimpleFeature> { public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (reader == null) { throw new IllegalStateException("Reader has already been closed"); } SimpleFeature next = reader.next(); Object[] attributes = next.getAttributes().toArray(); try { for (int i = 0; i < attributes.length; i++) { if (attributes[i] instanceof Geometry) { attributes[i] = transformer.transform((Geometry) attributes[i]); } } } catch (TransformException e) { throw new DataSourceException( "A transformation exception occurred while reprojecting data on the fly", e); } SimpleFeature reprojected = SimpleFeatureBuilder.build(schema, attributes, next.getID()); if (next.hasUserData()) { reprojected.getUserData().putAll(next.getUserData()); } return reprojected; } ReprojectFeatureReader(
            FeatureReader<SimpleFeatureType, SimpleFeature> reader,
            SimpleFeatureType schema,
            MathTransform transform);  ReprojectFeatureReader(
            FeatureReader<SimpleFeatureType, SimpleFeature> reader, CoordinateReferenceSystem cs); }
ReprojectFeatureReader implements DelegatingFeatureReader<SimpleFeatureType, SimpleFeature> { public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (reader == null) { throw new IllegalStateException("Reader has already been closed"); } SimpleFeature next = reader.next(); Object[] attributes = next.getAttributes().toArray(); try { for (int i = 0; i < attributes.length; i++) { if (attributes[i] instanceof Geometry) { attributes[i] = transformer.transform((Geometry) attributes[i]); } } } catch (TransformException e) { throw new DataSourceException( "A transformation exception occurred while reprojecting data on the fly", e); } SimpleFeature reprojected = SimpleFeatureBuilder.build(schema, attributes, next.getID()); if (next.hasUserData()) { reprojected.getUserData().putAll(next.getUserData()); } return reprojected; } ReprojectFeatureReader(
            FeatureReader<SimpleFeatureType, SimpleFeature> reader,
            SimpleFeatureType schema,
            MathTransform transform);  ReprojectFeatureReader(
            FeatureReader<SimpleFeatureType, SimpleFeature> reader, CoordinateReferenceSystem cs); FeatureReader<SimpleFeatureType, SimpleFeature> getDelegate(); SimpleFeatureType getFeatureType(); SimpleFeature next(); boolean hasNext(); void close(); }
ReprojectFeatureReader implements DelegatingFeatureReader<SimpleFeatureType, SimpleFeature> { public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (reader == null) { throw new IllegalStateException("Reader has already been closed"); } SimpleFeature next = reader.next(); Object[] attributes = next.getAttributes().toArray(); try { for (int i = 0; i < attributes.length; i++) { if (attributes[i] instanceof Geometry) { attributes[i] = transformer.transform((Geometry) attributes[i]); } } } catch (TransformException e) { throw new DataSourceException( "A transformation exception occurred while reprojecting data on the fly", e); } SimpleFeature reprojected = SimpleFeatureBuilder.build(schema, attributes, next.getID()); if (next.hasUserData()) { reprojected.getUserData().putAll(next.getUserData()); } return reprojected; } ReprojectFeatureReader(
            FeatureReader<SimpleFeatureType, SimpleFeature> reader,
            SimpleFeatureType schema,
            MathTransform transform);  ReprojectFeatureReader(
            FeatureReader<SimpleFeatureType, SimpleFeature> reader, CoordinateReferenceSystem cs); FeatureReader<SimpleFeatureType, SimpleFeature> getDelegate(); SimpleFeatureType getFeatureType(); SimpleFeature next(); boolean hasNext(); void close();  }