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!"); } }
transformer.setMathTransform(tx); transformers.put(crs, transformer);
public ReprojectingIterator( Iterator<SimpleFeature> delegate, MathTransform transform, SimpleFeatureType schema, GeometryCoordinateSequenceTransformer transformer) throws OperationNotFoundException, FactoryRegistryException, FactoryException { this.delegate = delegate; this.schema = schema; tx = transformer; tx.setMathTransform((MathTransform2D) transform); }
public ReprojectingFeatureIterator( SimpleFeatureIterator delegate, MathTransform transform, SimpleFeatureType schema, GeometryCoordinateSequenceTransformer transformer) throws OperationNotFoundException, FactoryRegistryException, FactoryException { this.delegate = delegate; this.schema = schema; tx = transformer; tx.setMathTransform((MathTransform2D) transform); }
/** * Direct constructor reprojecting the provided reader into the schema indicated (using the * supplied math transformation). * * <p>Please note schema is that of the expected results, You may need to use * FeatureTypes.transform( FeatureType, crs ) to create the schema provider. * * @param reader original reader with results in the original coordinate reference system * @param schema This is the target schema describing the results in the expected coordinate * reference system * @param transform the math transform used to go from reader coordinate reference system to the * provided schema coordinate reference system */ public ReprojectFeatureReader( FeatureReader<SimpleFeatureType, SimpleFeature> reader, SimpleFeatureType schema, MathTransform transform) { this.reader = reader; this.schema = schema; transformer.setMathTransform(transform); } /**
public ReprojectFeatureIterator( FeatureIterator<SimpleFeature> reader, SimpleFeatureType schema, MathTransform transform) { this.reader = reader; this.schema = schema; transformer.setMathTransform(transform); // set hte target coordinate system transformer.setCoordinateReferenceSystem(schema.getCoordinateReferenceSystem()); }
/** * Transforms the geometry using the default transformer. * * @param geom The geom to transform * @param transform the transform to use during the transformation. * @return the transformed geometry. It will be a new geometry. * @throws MismatchedDimensionException if the geometry doesn't have the expected dimension for * the specified transform. * @throws TransformException if a point can't be transformed. */ public static Geometry transform(final Geometry geom, final MathTransform transform) throws MismatchedDimensionException, TransformException { final GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(transform); return transformer.transform(geom); }
public ReprojectingFeatureIterator( SimpleFeatureIterator delegate, CoordinateReferenceSystem source, CoordinateReferenceSystem target, SimpleFeatureType schema, GeometryCoordinateSequenceTransformer transformer) throws OperationNotFoundException, FactoryRegistryException, FactoryException { this.delegate = delegate; this.target = target; this.schema = schema; tx = transformer; MathTransform transform = ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(source, target) .getMathTransform(); tx.setMathTransform(transform); }
public ReprojectingIterator( Iterator<SimpleFeature> delegate, CoordinateReferenceSystem source, CoordinateReferenceSystem target, SimpleFeatureType schema, GeometryCoordinateSequenceTransformer transformer) throws OperationNotFoundException, FactoryRegistryException, FactoryException { this.delegate = delegate; this.target = target; this.schema = schema; tx = transformer; MathTransform transform = ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(source, target) .getMathTransform(); tx.setMathTransform(transform); }
/** * 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)); }
public PullParserFeatureReader( final Configuration wfsConfiguration, final InputStream getFeatureResponseStream, final FeatureType featureType, String axisOrder) throws IOException { this.inputStream = getFeatureResponseStream; this.featureType = featureType; this.axisOrder = axisOrder; this.parser = new PullParser( wfsConfiguration, getFeatureResponseStream, new QName( featureType.getName().getNamespaceURI(), featureType.getName().getLocalPart())); transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(new AffineTransform2D(0, 1, 1, 0, 0, 0)); }
protected void setUp() throws Exception { super.setUp(); target = CRS.decode("EPSG:3005"); MathTransform2D tx = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(crs, target) .getMathTransform(); transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); }
@Test public void testFlipAxisOnCurved() throws Exception { CircularString cs = (CircularString) new CurvedGeometryFactory(0.1).createCurvedGeometry(2, 0, 1, 1, 2, 2, 1); GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); CoordinateReferenceSystem crsLatLon = CRS.decode("urn:ogc:def:crs:EPSG:4326"); CoordinateReferenceSystem crsLonLat = CRS.decode("EPSG:4326", true); transformer.setCoordinateReferenceSystem(crsLatLon); MathTransform trans = CRS.findMathTransform(crsLonLat, crsLatLon); transformer.setMathTransform(trans); Geometry transformed = transformer.transform(cs); assertTrue(transformed instanceof CircularString); CircularString tcs = (CircularString) transformed; assertArrayEquals(new double[] {1, 0, 2, 1, 1, 2}, tcs.getControlPoints(), 0d); }
@Test public void testFullTransformOnCurved() throws Exception { CircularString cs = (CircularString) new CurvedGeometryFactory(0.1).createCurvedGeometry(2, 0, 1, 1, 2, 2, 1); GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3857"); CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326", true); transformer.setCoordinateReferenceSystem(targetCRS); MathTransform trans = CRS.findMathTransform(sourceCRS, targetCRS); transformer.setMathTransform(trans); Geometry transformed = transformer.transform(cs); assertFalse(transformed instanceof CircularString); LineString ls = (LineString) transformed; assertTrue(ls.getCoordinateSequence().size() > 3); }
protected void setUp() throws Exception { super.setUp(); target = CRS.parseWKT( "PROJCS[\"BC_Albers\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101],TOWGS84[0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Albers_Conic_Equal_Area\"],PARAMETER[\"False_Easting\",1000000],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-126],PARAMETER[\"Standard_Parallel_1\",50],PARAMETER[\"Standard_Parallel_2\",58.5],PARAMETER[\"Latitude_Of_Origin\",45],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"42102\"]]"); MathTransform2D tx = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(crs, target) .getMathTransform(); transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); transformer.setCoordinateReferenceSystem(target); }
/** * Check transformation correctness by transforming forwards and backwards using inverse * MathTransforms. * * @param g * @throws TransformException */ private void checkTransform(Geometry g) throws TransformException { GeometryCoordinateSequenceTransformer gcsTrans = new GeometryCoordinateSequenceTransformer(); gcsTrans.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); MathTransform trans = ProjectiveTransform.createTranslation(2, 100); gcsTrans.setMathTransform(trans); GeometryCoordinateSequenceTransformer gcsTransInv = new GeometryCoordinateSequenceTransformer(); gcsTransInv.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); MathTransform transInv = ProjectiveTransform.createTranslation(2, -100); gcsTransInv.setMathTransform(transInv); Geometry gTrans = gcsTrans.transform(g); Geometry g2 = gcsTransInv.transform(gTrans); // result better be a different geometry assertTrue(g != g2); assertTrue(hasSameValuesAndStructure(g, g2)); }
transformer.setMathTransform(CRS.findMathTransform(nativeCRS, reprojectCRS, true)); } else { transformer.setMathTransform(CRS.findMathTransform(forcedCRS, reprojectCRS, true));
public ReprojectingIterator( Iterator delegate, CoordinateReferenceSystem source, CoordinateReferenceSystem target, SimpleFeatureType schema, GeometryCoordinateSequenceTransformer transformer ) throws OperationNotFoundException, FactoryRegistryException, FactoryException { this.delegate = delegate; this.target = target; this.schema = schema; tx = transformer; MathTransform transform = ReferencingFactoryFinder.getCoordinateOperationFactory( null).createOperation(source, target).getMathTransform(); tx.setMathTransform((MathTransform2D) transform); }
public ReprojectingIterator( Iterator delegate, CoordinateReferenceSystem source, CoordinateReferenceSystem target, FeatureType schema, GeometryCoordinateSequenceTransformer transformer ) throws OperationNotFoundException, FactoryRegistryException, FactoryException { this.delegate = delegate; this.target = target; this.schema = schema; tx = transformer; MathTransform transform = ReferencingFactoryFinder.getCoordinateOperationFactory( null).createOperation(source, target).getMathTransform(); tx.setMathTransform((MathTransform2D) transform); }
public ReprojectFeatureIterator(FeatureIterator reader, FeatureType schema, MathTransform transform) { this.reader = reader; this.schema = schema; transformer.setMathTransform((MathTransform2D)transform); //set hte target coordinate system if ( schema.getDefaultGeometry() != null ) { transformer.setCoordinateReferenceSystem(schema.getDefaultGeometry().getCoordinateSystem()); } }