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(); }
features = new ReprojectingFeatureCollection(features, targetCRS);
/** * Template method for reprojecting a feature collection from a source crs to a target crs. * <p> * Subclasses may override, the default implementation wraps <param>features</param> in a * {@link ReprojectingFeatureCollection}. * </p> * @param features The feature collection to be reprojected. * * @return the reprojected feature collection. */ protected FeatureCollection reproject( FeatureCollection features, CoordinateReferenceSystem source, CoordinateReferenceSystem target ) { return new ReprojectingFeatureCollection( features, source, target ); }
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 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 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()); }
new ReprojectingFeatureCollection( collection, query.getCoordinateSystemReproject());
new ReprojectingFeatureCollection( features, query.getCoordinateSystemReproject());
public FeatureCollection subCollection(Filter filter) { Filter unFilter = unFilter(filter); return new ReprojectingFeatureCollection(delegate .subCollection(unFilter), target); // TODO: return new delegate.subCollection( filter ).reproject( target // ); }
resultFc = new ReprojectingFeatureCollection(resultFc, targetCRS);
private List<SimpleFeatureCollection> getFeatureCollections(FeatureCollectionResponse featureCollection) { List<FeatureCollection> inputs = featureCollection.getFeatures(); List<SimpleFeatureCollection> result = new ArrayList<SimpleFeatureCollection>(); for (FeatureCollection fc : inputs) { if (!(fc instanceof SimpleFeatureCollection)) { throw new ServiceException( "The KML output format can only be applied to simple features"); } // KML is defined only over wgs84 in lon/lat order, ignore what the WFS thinks the output // crs should be SimpleFeatureCollection sfc = (SimpleFeatureCollection) fc; CoordinateReferenceSystem sourceCRS = sfc.getSchema().getCoordinateReferenceSystem(); if(sourceCRS != null && !CRS.equalsIgnoreMetadata(sourceCRS, DefaultGeographicCRS.WGS84)) { sfc = new ReprojectingFeatureCollection(sfc, DefaultGeographicCRS.WGS84); } result.add(sfc); } return result; }
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 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()); }
@DescribeResult(name = "result", description = "Input feature collection") public SimpleFeatureCollection execute( @DescribeParameter(name = "features", description = "The feature collection that will be reprojected") SimpleFeatureCollection features, @DescribeParameter(name = "forcedCRS", min = 0, description = "Coordinate reference system to use for input feature collection (overrides native one)") CoordinateReferenceSystem forcedCRS, @DescribeParameter(name = "targetCRS", min = 0, description = "Target coordinate reference system to use for reprojection") CoordinateReferenceSystem targetCRS) throws Exception { if (forcedCRS != null) { features = new ForceCoordinateSystemFeatureResults(features, forcedCRS, false); } if (targetCRS != null) { // note, using ReprojectFeatureResults would work. However that would // just work by accident... see GEOS-4072 features = new ReprojectingFeatureCollection(features, targetCRS); } return features; }
private static Map<Class<?>, List<SimpleFeature>> createGeometryToFeaturesListMap(VectorDataNode vectorNode) { FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = vectorNode.getFeatureCollection(); CoordinateReferenceSystem crs = vectorNode.getFeatureType().getCoordinateReferenceSystem(); if (crs == null) { // for pins and GCPs crs is null --> assume image crs crs = vectorNode.getProduct().getGeoCoding().getImageCRS(); } final CoordinateReferenceSystem modelCrs; if (vectorNode.getProduct().getGeoCoding() instanceof CrsGeoCoding) { modelCrs = ImageManager.getModelCrs(vectorNode.getProduct().getGeoCoding()); } else { modelCrs = DefaultGeographicCRS.WGS84; } if (!CRS.equalsIgnoreMetadata(crs, modelCrs)) { // we have to reproject the features featureCollection = new ReprojectingFeatureCollection(featureCollection, crs, modelCrs); } Map<Class<?>, List<SimpleFeature>> featureListMap = new HashMap<>(); final FeatureIterator<SimpleFeature> featureIterator = featureCollection.features(); while (featureIterator.hasNext()) { SimpleFeature feature = featureIterator.next(); Object defaultGeometry = feature.getDefaultGeometry(); Class<?> geometryType = defaultGeometry.getClass(); List<SimpleFeature> featureList = featureListMap.get(geometryType); if (featureList == null) { featureList = new ArrayList<>(); featureListMap.put(geometryType, featureList); } featureList.add(feature); } return featureListMap; }
if (!CRS.equalsIgnoreMetadata(crs, lonLatCrs)) { fc = new ReprojectingFeatureCollection(fc, lonLatCrs);
if(!CRS.equalsIgnoreMetadata(crs, lonLatCrs)) { fc = new ReprojectingFeatureCollection(fc, lonLatCrs);
@Override public void encode(Object input, OutputStream os) throws IOException { ContactInfo contact = geoServer.getSettings().getContact(); GpxEncoder encoder = new GpxEncoder(true); encoder.setCreator(contact.getContactOrganization()); encoder.setLink(contact.getOnlineResource()); try { SimpleFeatureCollection fc = (SimpleFeatureCollection) input; CoordinateReferenceSystem crs = fc.getSchema().getCoordinateReferenceSystem(); // gpx is defined only in wgs84 if (crs != null && !CRS.equalsIgnoreMetadata(crs, DefaultGeographicCRS.WGS84)) { fc = new ReprojectingFeatureCollection(fc, DefaultGeographicCRS.WGS84); } encoder.encode(os, fc); } catch (Exception e) { throw new IOException("Unable to encode in GPX", e); } }
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); }