public ReprojectingFeatureCollection( SimpleFeatureCollection delegate, CoordinateReferenceSystem target) throws SchemaException, OperationNotFoundException, FactoryRegistryException, FactoryException { super(delegate); this.target = target; this.schema = FeatureTypes.transform(delegate.getSchema(), target); // create transform cache transformers = new HashMap(); // cache "default" transform CoordinateReferenceSystem source = delegate.getSchema().getCoordinateReferenceSystem(); if (source != null) { MathTransform tx = ReferencingFactoryFinder.getCoordinateOperationFactory(hints) .createOperation(source, target) .getMathTransform(); GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); transformers.put(source, transformer); } else { throw new RuntimeException( "Source was null in trying to create a reprojected feature collection!"); } }
/** * Forces the specified CRS on all geometry attributes * * @param schema the original schema * @param crs the forced crs * @return * @throws SchemaException */ public static SimpleFeatureType transform( SimpleFeatureType schema, CoordinateReferenceSystem crs) throws SchemaException { return transform(schema, crs, false); }
private SimpleFeatureType reType(SimpleFeatureType type, CoordinateReferenceSystem target) { try { return FeatureTypes.transform(type, target); } catch (SchemaException e) { throw new IllegalArgumentException("Could not transform source schema", e); } }
if (srsHandling == ProjectionPolicy.FORCE_DECLARED) { defaultCRS = declaredCRS; nativeFeatureType = FeatureTypes.transform(nativeFeatureType, declaredCRS); } else if (srsHandling == ProjectionPolicy.REPROJECT_TO_DECLARED) { defaultCRS = declaredCRS;
private static SimpleFeatureType forceType( SimpleFeatureType startingType, CoordinateReferenceSystem forcedCS) throws SchemaException { if (forcedCS == null) { throw new NullPointerException("CoordinateSystem required"); } CoordinateReferenceSystem originalCs = startingType.getGeometryDescriptor().getCoordinateReferenceSystem(); if (forcedCS.equals(originalCs)) { return startingType; } else { return FeatureTypes.transform(startingType, forcedCS); } }
try { if (!CRS.equalsIgnoreMetadata(resultCRS, schema.getCoordinateReferenceSystem())) schema = FeatureTypes.transform(schema, resultCRS); } catch (Exception e) { throw new DataSourceException("Problem forcing CRS onto feature type", e);
private static SimpleFeatureType forceType( SimpleFeatureType startingType, CoordinateReferenceSystem forcedCS, boolean forceOnlyMissing) throws SchemaException { if (forcedCS == null) { throw new NullPointerException("CoordinateSystem required"); } CoordinateReferenceSystem originalCs = startingType.getGeometryDescriptor() != null ? startingType.getGeometryDescriptor().getCoordinateReferenceSystem() : null; if (forcedCS.equals(originalCs)) { return startingType; } else { return FeatureTypes.transform(startingType, forcedCS, forceOnlyMissing); } }
/** * Builds a new ForceCoordinateSystemFeatureReader * * @param reader * @param cs * @throws SchemaException * @throws NullPointerException DOCUMENT ME! * @throws IllegalArgumentException DOCUMENT ME! */ public ForceCoordinateSystemIterator( FeatureIterator<SimpleFeature> reader, SimpleFeatureType type, CoordinateReferenceSystem cs) throws SchemaException { if (cs == null) { throw new NullPointerException("CoordinateSystem required"); } CoordinateReferenceSystem originalCs = type.getGeometryDescriptor().getCoordinateReferenceSystem(); if (!cs.equals(originalCs)) { type = FeatureTypes.transform(type, cs); } builder = new SimpleFeatureBuilder(type); this.reader = reader; }
/** * Builds a new ForceCoordinateSystemFeatureReader * * @param reader * @param cs * @throws SchemaException * @throws NullPointerException DOCUMENT ME! * @throws IllegalArgumentException DOCUMENT ME! */ public ForceCoordinateSystemFeatureReader( FeatureReader<SimpleFeatureType, SimpleFeature> reader, CoordinateReferenceSystem cs, boolean forceOnlyMissing) throws SchemaException { if (cs == null) { throw new NullPointerException("CoordinateSystem required"); } SimpleFeatureType type = reader.getFeatureType(); CoordinateReferenceSystem originalCs = type.getCoordinateReferenceSystem(); if (!cs.equals(originalCs)) { type = FeatureTypes.transform(type, cs, forceOnlyMissing); } this.builder = new SimpleFeatureBuilder(type); this.reader = reader; }
/** * Constructor that will generate schema and mathTransform for the results. * * @param reader original reader * @param cs Target coordinate reference system; will be used to create the target FeatureType * and MathTransform used to transform the data */ public ReprojectFeatureReader( FeatureReader<SimpleFeatureType, SimpleFeature> reader, CoordinateReferenceSystem cs) throws SchemaException, OperationNotFoundException, NoSuchElementException, FactoryException { if (cs == null) { throw new NullPointerException("CoordinateSystem required"); } SimpleFeatureType type = reader.getFeatureType(); CoordinateReferenceSystem original = type.getGeometryDescriptor().getCoordinateReferenceSystem(); if (cs.equals(original)) { throw new IllegalArgumentException( "CoordinateSystem " + cs + " already used (check before using wrapper)"); } this.schema = FeatureTypes.transform(type, cs); this.reader = reader; transformer.setMathTransform(CRS.findMathTransform(original, cs, true)); }
/** * Forces the specified CRS on all geometry attributes * @param schema the original schema * @param crs the forced crs * @return * @throws SchemaException */ public static SimpleFeatureType transform( SimpleFeatureType schema, CoordinateReferenceSystem crs ) throws SchemaException { return transform(schema, crs, false); }
/** * Forces the specified CRS on all geometry attributes * @param schema the original schema * @param crs the forced crs * @return * @throws SchemaException */ public static FeatureType transform( FeatureType schema, CoordinateReferenceSystem crs ) throws SchemaException { return transform(schema, crs, false); }
public void testSpecNotIdentifiable() throws Exception { String spec = "id:String,polygonProperty:Polygon:srid=32615"; SimpleFeatureType ft = DataUtilities.createType("testType", spec); CoordinateReferenceSystem crsNoId = CRS.parseWKT( "PROJCS[\"Geoscience Australia Standard National Scale Lambert Projection\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1978\",6378135,298.26],TOWGS84[0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Decimal_Degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"central_meridian\",134.0],PARAMETER[\"latitude_of_origin\",0.0],PARAMETER[\"standard_parallel_1\",-18.0],PARAMETER[\"standard_parallel_2\",-36.0],UNIT[\"Meter\",1]]"); SimpleFeatureType transformedFt = FeatureTypes.transform(ft, crsNoId); // since we cannot go back to a code with do a best effort encoding String expected = "id:String,polygonProperty:Polygon"; String spec2 = DataUtilities.encodeType(transformedFt); // System.out.println(" BEFORE:"+spec); // System.out.println("EXPECTED:"+expected); // System.out.println(" AFTER:"+spec2); assertEquals(expected, spec2); }
private SimpleFeatureType reType(SimpleFeatureType type, CoordinateReferenceSystem target) { try { return FeatureTypes.transform(type, target); } catch (SchemaException e) { throw new IllegalArgumentException( "Could not transform source schema", e); } }
private FeatureType reType(FeatureType type, CoordinateReferenceSystem target) { try { return FeatureTypes.transform(type, target); } catch (SchemaException e) { throw new IllegalArgumentException( "Could not transform source schema"); } }
Polygon nativeFootprint = JTS.toGeometry(envelope); SimpleFeatureType ftNative = FeatureTypes.transform( indexSchema, reader.getCoordinateReferenceSystem()); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(ftNative);
private static SimpleFeatureType forceType( SimpleFeatureType startingType, CoordinateReferenceSystem forcedCS ) throws SchemaException{ if (forcedCS == null) { throw new NullPointerException("CoordinateSystem required"); } CoordinateReferenceSystem originalCs = startingType.getGeometryDescriptor().getCoordinateReferenceSystem(); if (forcedCS.equals(originalCs)) { return startingType; } else { return FeatureTypes.transform(startingType, forcedCS); } }
private static FeatureType forceType( FeatureType startingType, CoordinateReferenceSystem forcedCS ) throws SchemaException{ if (forcedCS == null) { throw new NullPointerException("CoordinateSystem required"); } CoordinateReferenceSystem originalCs = startingType.getDefaultGeometry().getCoordinateSystem(); if (forcedCS.equals(originalCs)) { return startingType; } else { return FeatureTypes.transform(startingType, forcedCS); } }
public void testBboxReprojectNoNativeAuthority() throws Exception { // like WGS84, but no authority String wkt = "GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137.0, 298.257223563]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH]]"; CoordinateReferenceSystem crs = CRS.parseWKT(wkt); SimpleFeatureType newFt = FeatureTypes.transform(ft, crs); reprojector = new ReprojectingFilterVisitor(ff, newFt); BBOX bbox = ff.bbox(ff.property("geom"), 10, 15, 20, 25, "urn:x-ogc:def:crs:EPSG:6.11.2:4326"); Filter clone = (Filter) bbox.accept(reprojector, null); assertNotSame(bbox, clone); BBOX clonedBbox = (BBOX) clone; assertEquals(bbox.getPropertyName(), clonedBbox.getPropertyName()); assertTrue(15 == clonedBbox.getMinX()); assertTrue(10 == clonedBbox.getMinY()); assertTrue(25 == clonedBbox.getMaxX()); assertTrue(20 == clonedBbox.getMaxY()); // the srs code cannot be found, but it's legal to use a WKT description instead // CoordinateReferenceSystem reprojected = CRS.parseWKT(clonedBbox.getSRS()); // assertTrue(CRS.equalsIgnoreMetadata(crs, reprojected)); }