use of org.geotoolkit.geometry.jts.transform.GeometryScaleTransformer 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();
}
use of org.geotoolkit.geometry.jts.transform.GeometryScaleTransformer in project geotoolkit by Geomatys.
the class GenericQueryFeatureIterator method wrap.
public static FeatureReader wrap(FeatureReader reader, final Query remainingParameters) throws DataStoreException {
final long start = remainingParameters.getOffset();
final long max = remainingParameters.getLimit().orElse(-1);
Filter filter = remainingParameters.getSelection();
if (filter == null)
filter = Filter.include();
final String[] properties = remainingParameters.getPropertyNames();
final SortProperty[] sorts = QueryUtilities.getSortProperties(remainingParameters.getSortBy());
final double[] resampling = remainingParameters.getResolution();
final Hints hints = remainingParameters.getHints();
// that may cause out of memory errors.
if (sorts != null && sorts.length != 0) {
reader = FeatureStreams.sort(reader, sorts);
}
// we must keep the filter first since it impacts the start index and max feature
if (filter != null && filter != Filter.include()) {
if (filter == Filter.exclude()) {
// filter that exclude everything, use optimzed reader
reader = FeatureStreams.emptyReader(reader.getFeatureType());
// close original reader
reader.close();
} else {
reader = FeatureStreams.filter(reader, filter);
}
}
// wrap start index -----------------------------------------------------
if (start > 0) {
reader = FeatureStreams.skip(reader, (int) start);
}
// wrap max -------------------------------------------------------------
if (max != -1) {
if (max == 0) {
// use an optimized reader
reader = FeatureStreams.emptyReader(reader.getFeatureType());
// close original reader
reader.close();
} else {
reader = FeatureStreams.limit(reader, (int) max);
}
}
// wrap properties -----------------------------------------------------
final FeatureType original = reader.getFeatureType();
if (properties != null && !FeatureTypeExt.isAllProperties(original, properties)) {
try {
reader = FeatureStreams.decorate(reader, new ViewMapper(original, properties), hints);
} catch (MismatchedFeatureException | IllegalStateException ex) {
throw new DataStoreException(ex);
}
}
// wrap resampling ------------------------------------------------------
if (resampling != null) {
final GeometryScaleTransformer trs = new GeometryScaleTransformer(resampling[0], resampling[1]);
final TransformMapper ttype = new TransformMapper(reader.getFeatureType(), trs);
reader = FeatureStreams.decorate(reader, ttype, hints);
}
return reader;
}
use of org.geotoolkit.geometry.jts.transform.GeometryScaleTransformer in project geotoolkit by Geomatys.
the class AbstractFeatureCollection method subset.
@Override
public FeatureCollection subset(final Query remainingParameters) throws DataStoreException {
FeatureCollection result = this;
final long start = remainingParameters.getOffset();
final long max = remainingParameters.getLimit().orElse(-1);
Filter filter = remainingParameters.getSelection();
if (filter == null)
filter = Filter.include();
final String[] properties = remainingParameters.getPropertyNames();
final SortProperty[] sorts = QueryUtilities.getSortProperties(remainingParameters.getSortBy());
final double[] resampling = remainingParameters.getResolution();
final Hints hints = remainingParameters.getHints();
// that may cause out of memory errors.
if (sorts != null && sorts.length != 0) {
result = FeatureStreams.sort(result, sorts);
}
// we must keep the filter first since it impacts the start index and max feature
if (filter != null && filter != Filter.include()) {
if (filter == Filter.exclude()) {
// filter that exclude everything, use optimzed reader
result = FeatureStreams.emptyCollection(result);
} else {
result = FeatureStreams.filter(result, filter);
}
}
// wrap start index -----------------------------------------------------
if (start > 0) {
result = FeatureStreams.skip(result, (int) start);
}
// wrap max -------------------------------------------------------------
if (max != -1) {
if (max == 0) {
// use an optimized reader
result = FeatureStreams.emptyCollection(result);
} else {
result = FeatureStreams.limit(result, (int) max);
}
}
// wrap properties --------------------
final FeatureType original = result.getType();
FeatureType mask = original;
if (properties != null && FeatureTypeExt.isAllProperties(original, properties)) {
try {
result = FeatureStreams.decorate(result, new ViewMapper(mask, properties));
} catch (MismatchedFeatureException | IllegalStateException ex) {
throw new DataStoreException(ex);
}
}
// wrap resampling ------------------------------------------------------
if (resampling != null) {
final GeometryScaleTransformer trs = new GeometryScaleTransformer(resampling[0], resampling[1]);
final TransformMapper ttype = new TransformMapper(result.getType(), trs);
result = FeatureStreams.decorate(result, ttype);
}
return result;
}
Aggregations