public Object evaluate(Object object) { String targetCRS = getAttribute(object, 0, String.class, true); try { CoordinateReferenceSystem crs = CRS.decode(targetCRS); return new ReprojectingFeatureCollection((SimpleFeatureCollection) object, crs); } catch (Exception e) { throw new RuntimeException("Failed to reproject the collection"); } }
public void testLenient() throws Exception { CoordinateReferenceSystem lenientTarget; lenientTarget = CRS.parseWKT( "PROJCS[\"MGI (Ferro) / Austria GK West Zone\",GEOGCS[\"MGI (Ferro)\",DATUM[\"Militar_Geographische_Institut_Ferro\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",\"7004\"]],AUTHORITY[\"EPSG\",\"6805\"]],PRIMEM[\"Ferro\",-17.66666666666667,AUTHORITY[\"EPSG\",\"8909\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4805\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",28],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",-5000000],AUTHORITY[\"EPSG\",\"31251\"],AXIS[\"Y\",EAST],AXIS[\"X\",NORTH]]"); SimpleFeatureIterator reproject = new ReprojectingFeatureCollection(delegate, lenientTarget).features(); reproject.close(); }
public SimpleFeatureCollection subCollection(Filter filter) { // reproject the filter to the delegate native crs CoordinateReferenceSystem crs = getSchema().getCoordinateReferenceSystem(); CoordinateReferenceSystem crsDelegate = delegate.getSchema().getCoordinateReferenceSystem(); if (crs != null) { DefaultCRSFilterVisitor defaulter = new DefaultCRSFilterVisitor(FF, crs); filter = (Filter) filter.accept(defaulter, null); if (crsDelegate != null && !CRS.equalsIgnoreMetadata(crs, crsDelegate)) { ReprojectingFilterVisitor reprojector = new ReprojectingFilterVisitor(FF, delegate.getSchema()); filter = (Filter) filter.accept(reprojector, null); } } return new ReprojectingFeatureCollection(delegate.subCollection(filter), target); }
public ReprojectingFeatureCollection( SimpleFeatureCollection delegate, CoordinateReferenceSystem source, CoordinateReferenceSystem target) { super(delegate); this.target = target; SimpleFeatureType schema = delegate.getSchema(); this.schema = reType(schema, target); if (source == null) { throw new NullPointerException("source crs"); } if (target == null) { throw new NullPointerException("destination crs"); } this.transform = transform(source, target); transformer = new GeometryCoordinateSequenceTransformer(); }
public void testBounds() throws Exception { ReprojectingFeatureCollection rfc = new ReprojectingFeatureCollection(delegate, target); ReferencedEnvelope bounds = delegate.getBounds(); // the reprojection of the full bounds is going to be bigger than the sum of the // feature by feature reprojected bounds assertTrue(bounds.transform(target, true).contains((BoundingBox) rfc.getBounds())); // make sure that the reprojected bounds contain the target CRS assertEquals(target, rfc.getBounds().getCoordinateReferenceSystem()); }
replay(delegate); ReprojectingFeatureCollection rfc = new ReprojectingFeatureCollection(delegate, target); rfc.accepts(vis, null); verify(delegate); replay(delegate); rfc = new ReprojectingFeatureCollection(delegate, target); rfc.accepts(vis, null); verify(delegate);
public FeatureCollection subCollection(Filter filter) { Filter unFilter = unFilter(filter); return new ReprojectingFeatureCollection(delegate .subCollection(unFilter), target); // TODO: return new delegate.subCollection( filter ).reproject( target // ); }
public void testFilter() throws Exception { ReprojectingFeatureCollection rfc = new ReprojectingFeatureCollection(delegate, target); ReferencedEnvelope bounds = delegate.getBounds(); ReferencedEnvelope rbounds = bounds.transform(target, true); // check the bounds filtering works the same way in the standard and reprojected case BBOX filter = ff.bbox( "", bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY(), CRS.toSRS(delegate.getSchema().getCoordinateReferenceSystem())); BBOX rfilter = ff.bbox( "", rbounds.getMinX(), rbounds.getMinY(), rbounds.getMaxX(), rbounds.getMaxY(), CRS.toSRS(target)); assertEquals(delegate.subCollection(filter).size(), rfc.subCollection(rfilter).size()); }
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a) { List<T> list = new ArrayList<T>(); SimpleFeatureIterator i = features(); try { while (i.hasNext()) { list.add((T) i.next()); } return list.toArray(a); } finally { i.close(); } }
public SimpleFeatureIterator features() { return new DelegateSimpleFeatureIterator(this, iterator()); }
public ReprojectingFeatureCollection( SimpleFeatureCollection delegate, CoordinateReferenceSystem source, CoordinateReferenceSystem target) { super(delegate); this.target = target; SimpleFeatureType schema = delegate.getSchema(); this.schema = reType(schema, target); if (source == null) { throw new NullPointerException("source crs"); } if ( target == null ) { throw new NullPointerException("destination crs"); } this.transform = transform(source, target); transformer = new GeometryCoordinateSequenceTransformer(); }
/** * This method computes reprojected bounds the hard way, but computing them feature by feature. * This method could be faster if computed the reprojected bounds by reprojecting the original * feature bounds a Shape object, thus getting the true shape of the reprojected envelope, and * then computing the minimum and maximum coordinates of that new shape. The result would not a * true representation of the new bounds. * * @see org.geotools.data.FeatureResults#getBounds() */ public ReferencedEnvelope getBounds() { SimpleFeatureIterator r = features(); try { Envelope newBBox = new Envelope(); Envelope internal; SimpleFeature feature; while (r.hasNext()) { feature = r.next(); final Geometry geom = ((Geometry) feature.getDefaultGeometry()); if (geom != null) { internal = geom.getEnvelopeInternal(); newBBox.expandToInclude(internal); } } return new ReferencedEnvelope(newBBox, target); } catch (Exception e) { throw new RuntimeException("Exception occurred while computing reprojected bounds", e); } finally { r.close(); } }
public FeatureIterator features() { return new DelegateFeatureIterator(this, iterator()); }
features = new ReprojectingFeatureCollection(features, targetCRS);
public void testNormal() throws Exception { SimpleFeatureIterator reproject = new ReprojectingFeatureCollection(delegate, target).features(); SimpleFeatureIterator reader = delegate.features(); try { while (reader.hasNext()) { SimpleFeature normal = (SimpleFeature) reader.next(); SimpleFeature reprojected = (SimpleFeature) reproject.next(); Point p1 = (Point) normal.getAttribute("defaultGeom"); Point p2 = (Point) reprojected.getAttribute("defaultGeom"); if (p1 != null) { p1 = (Point) transformer.transform(p1); assertTrue(p1.equalsExact(p2)); } else { assertNull(p2); } LineString l1 = (LineString) normal.getAttribute("otherGeom"); LineString l2 = (LineString) reprojected.getAttribute("otherGeom"); if (l1 != null) { l1 = (LineString) transformer.transform(l1); assertTrue(l1.equalsExact(l2)); } else { assertNull(l2); } } } finally { reproject.close(); reader.close(); } }
public SimpleFeatureCollection subCollection(Filter filter) { // reproject the filter to the delegate native crs CoordinateReferenceSystem crs = getSchema().getCoordinateReferenceSystem(); CoordinateReferenceSystem crsDelegate = delegate.getSchema().getCoordinateReferenceSystem(); if(crs != null) { DefaultCRSFilterVisitor defaulter = new DefaultCRSFilterVisitor(FF, crs); filter = (Filter) filter.accept(defaulter, null); if(crsDelegate != null && !CRS.equalsIgnoreMetadata(crs, crsDelegate)) { ReprojectingFilterVisitor reprojector = new ReprojectingFilterVisitor(FF, delegate.getSchema()); filter = (Filter) filter.accept(reprojector, null); } } return new ReprojectingFeatureCollection(delegate.subCollection(filter), target); }