use of org.geotoolkit.geometry.jts.transform.GeometryTransformer in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testTransformFeatureIterator.
@Test
public void testTransformFeatureIterator() throws DataStoreException {
FeatureType originalType = buildOriginalFT();
final FeatureTypeBuilder builder = new FeatureTypeBuilder();
final GenericName name = NamesExt.create("http://test.com", "TestSchema");
builder.setName(name);
builder.addAttribute(String.class).setName(AttributeConvention.IDENTIFIER_PROPERTY);
builder.addAttribute(LineString.class).setName("att_geom").setCRS(CommonCRS.WGS84.normalizedGeographic()).addRole(AttributeRole.DEFAULT_GEOMETRY);
final FeatureType type = builder.build();
final LineString geom = GF.createLineString(new Coordinate[] { new Coordinate(0, 0), // dx 15 , dy 12
new Coordinate(15, 12), // dx 7 , dy 16
new Coordinate(8, 28), // dx 1 , dy 3
new Coordinate(9, 31), // dx 14 , dy 20
new Coordinate(-5, 11), // dx 4 , dy 2
new Coordinate(-1, 9) });
final FeatureCollection collection = FeatureStoreUtilities.collection("id", type);
Feature sf = type.newInstance();
sf.setPropertyValue("att_geom", geom);
collection.add(sf);
// get the reader -------------------------------------------------------
Query query = new Query(originalType.getName());
FeatureReader reader = collection.getSession().getFeatureStore().getFeatureReader(query);
// create the decimate reader -------------------------------------------
final Hints hints = new Hints();
GeometryTransformer decim = new GeometryScaleTransformer(10, 10);
final TransformMapper ttype = new TransformMapper(reader.getFeatureType(), decim);
FeatureReader retyped = FeatureStreams.decorate(reader, ttype, hints);
assertTrue(retyped.hasNext());
LineString decimated = (LineString) retyped.next().getPropertyValue(AttributeConvention.GEOMETRY);
assertFalse(retyped.hasNext());
retyped.close();
assertEquals(4, decimated.getNumPoints());
assertEquals(geom.getGeometryN(0).getCoordinate(), decimated.getGeometryN(0).getCoordinate());
assertEquals(geom.getGeometryN(1).getCoordinate(), decimated.getGeometryN(1).getCoordinate());
assertEquals(geom.getGeometryN(2).getCoordinate(), decimated.getGeometryN(2).getCoordinate());
assertEquals(geom.getGeometryN(4).getCoordinate(), decimated.getGeometryN(3).getCoordinate());
// check the original geometry has not been modified
reader = collection.getSession().getFeatureStore().getFeatureReader(query);
assertTrue(reader.hasNext());
LineString notDecimated = (LineString) reader.next().getPropertyValue(AttributeConvention.GEOMETRY);
assertEquals(6, notDecimated.getNumPoints());
assertFalse(reader.hasNext());
reader.close();
// same test but with reuse hint ---------------------------------------
reader = collection.getSession().getFeatureStore().getFeatureReader(query);
decim = new GeometryScaleTransformer(10, 10);
retyped = FeatureStreams.decorate(reader, new TransformMapper(reader.getFeatureType(), decim), hints);
assertTrue(retyped.hasNext());
decimated = (LineString) retyped.next().getPropertyValue(AttributeConvention.GEOMETRY);
assertFalse(retyped.hasNext());
retyped.close();
assertEquals(4, decimated.getNumPoints());
assertEquals(geom.getGeometryN(0).getCoordinate(), decimated.getGeometryN(0).getCoordinate());
assertEquals(geom.getGeometryN(1).getCoordinate(), decimated.getGeometryN(1).getCoordinate());
assertEquals(geom.getGeometryN(2).getCoordinate(), decimated.getGeometryN(2).getCoordinate());
assertEquals(geom.getGeometryN(4).getCoordinate(), decimated.getGeometryN(3).getCoordinate());
// check the original geometry has not been modified
reader = collection.getSession().getFeatureStore().getFeatureReader(query);
assertTrue(reader.hasNext());
notDecimated = (LineString) reader.next().getPropertyValue(AttributeConvention.GEOMETRY);
assertEquals(6, notDecimated.getNumPoints());
assertFalse(reader.hasNext());
reader.close();
}
Aggregations