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 = new GeometryCoordinateSequenceTransformer();
/** * 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 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 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)); }
private static GeometryCoordinateSequenceTransformer createTransformer(CoordinateReferenceSystem crs, CoordinateReferenceSystem modelCrs) { GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); try { MathTransform reprojTransform = CRS.findMathTransform(crs, modelCrs, true); transformer.setMathTransform(reprojTransform); return transformer; } catch (FactoryException e) { throw new IllegalStateException("Could not create math transform", e); } }
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(); }
/** * 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 static GeometryCoordinateSequenceTransformer getTransform(CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCrs) { GeometryCoordinateSequenceTransformer transformer; try { MathTransform transform = CRS.findMathTransform(sourceCrs, targetCrs, true); transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(transform); transformer.setCoordinateReferenceSystem(targetCrs); } catch (FactoryException e) { throw new IllegalStateException(e); } return transformer; }
private Geometry transformGeometry(Geometry sourceGeom, CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCrs) throws FactoryException, TransformException { MathTransform mt = CRS.findMathTransform(sourceCrs, targetCrs, true); GeometryCoordinateSequenceTransformer gcst = new GeometryCoordinateSequenceTransformer(); gcst.setMathTransform(mt); return gcst.transform(sourceGeom); }
private Geometry transformGeometry(Geometry sourceGeom, CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCrs) throws FactoryException, TransformException { MathTransform mt = CRS.findMathTransform(sourceCrs, targetCrs, true); GeometryCoordinateSequenceTransformer gcst = new GeometryCoordinateSequenceTransformer(); gcst.setMathTransform(mt); return gcst.transform(sourceGeom); }
public ReprojectingFeatureCollection( FeatureCollection delegate, CoordinateReferenceSystem source, CoordinateReferenceSystem target ) { this.delegate = delegate; this.target = target; FeatureType schema = delegate.getSchema(); this.schema = reType(schema, target); FeatureType featureType = delegate.getFeatureType(); this.featureType = reType(featureType, 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 setupTransformation(ReferencedEnvelope extent) { CoordinateReferenceSystem horCRS = CRS.getHorizontalCRS(sourceCRS); if (isGeographic && (horCRS instanceof GeographicCRS)) { try { this.distanceUnit = SI.METER; // default this.areaUnit = SI.SQUARE_METRE; // default // GeographicCRS to UTM Coordinate p = extent.centre(); CoordinateReferenceSystem forcedCRS = CRS.decode("AUTO:42001," + p.x + "," + p.y); this.transformer = new GeometryCoordinateSequenceTransformer(); this.transformer.setMathTransform(transform(sourceCRS, forcedCRS, true)); this.transformer.setCoordinateReferenceSystem(forcedCRS); } catch (NoSuchAuthorityCodeException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } catch (FactoryException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } } }
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)); }