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()); }
@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)); }
public ReprojectFeatureIterator(FeatureIterator<SimpleFeature> reader, SimpleFeatureType schema, MathTransform transform) { this.reader = reader; this.schema = schema; transformer.setMathTransform((MathTransform2D)transform); //set hte target coordinate system transformer.setCoordinateReferenceSystem(schema.getCoordinateReferenceSystem()); }
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; }
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()); } }
public ReprojectFeatureCollection(SimpleFeatureCollection delegate, CoordinateReferenceSystem forcedCRS, CoordinateReferenceSystem targetCRS, boolean lenient) { super(delegate); SimpleFeatureType schema = delegate.getSchema(); if (forcedCRS == null) { forcedCRS = schema.getCoordinateReferenceSystem(); if (forcedCRS == null) { throw new NullPointerException("forcedCRS CoordinateReferenceSystem"); } } if (targetCRS == null) { throw new NullPointerException("targetCRS CoordinateReferenceSystem"); } transform = transform(forcedCRS, targetCRS, lenient); this.transformer.setMathTransform(transform); this.transformer.setCoordinateReferenceSystem(targetCRS); this.schema = FeatureTypes.build(schema, schema.getTypeName(), targetCRS); }
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 XYCalculationFeatureCollection(SimpleFeatureCollection delegate, String xField, String yField, boolean useInside, CoordinateReferenceSystem targetCRS) { super(delegate); if (xField == null || xField.isEmpty()) { throw new NullPointerException("x field is null"); } if (yField == null || yField.isEmpty()) { throw new NullPointerException("y field is null"); } this.xField = xField; this.yField = yField; this.useInside = useInside; this.schema = FeatureTypes.build(delegate, delegate.getSchema().getTypeName()); this.schema = FeatureTypes.add(schema, xField, Double.class, 38); this.schema = FeatureTypes.add(schema, yField, Double.class, 38); if (targetCRS != null) { CoordinateReferenceSystem forcedCRS = getSchema().getCoordinateReferenceSystem(); if (forcedCRS == null) { throw new NullPointerException("source crs is null"); } transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(transform(forcedCRS, targetCRS, true)); transformer.setCoordinateReferenceSystem(targetCRS); } }
private static FeatureCollection<SimpleFeatureType, SimpleFeature> transformPixelPosToGeoPos(FeatureCollection<SimpleFeatureType, SimpleFeature> fc, GeoCoding geoCoding) { Iterator<SimpleFeature> iterator = fc.iterator(); FeatureCollection<SimpleFeatureType, SimpleFeature> transformedFc = new DefaultFeatureCollection(fc.getID(), fc.getSchema()); while (iterator.hasNext()) { SimpleFeature sourceFeature = iterator.next(); Geometry geometry = (Geometry) sourceFeature.getDefaultGeometry(); GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(geoCoding.getImageToMapTransform()); transformer.setCoordinateReferenceSystem(geoCoding.getMapCRS()); try { geometry = transformer.transform(geometry); } catch (TransformException e) { throw new IllegalStateException(e); } sourceFeature.setDefaultGeometry(geometry); transformedFc.add(sourceFeature); } return transformedFc; } }
transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(transform); transformer.setCoordinateReferenceSystem(targetCRS); if (transformer != null) { transformer.setMathTransform(transform.inverse()); transformer.setCoordinateReferenceSystem(sourceCRS);
transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(transform); transformer.setCoordinateReferenceSystem(targetCRS); if (transformer != null) { transformer.setMathTransform(transform.inverse()); transformer.setCoordinateReferenceSystem(sourceCRS);
transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(transform); transformer.setCoordinateReferenceSystem(targetCRS); if (transformer != null) { transformer.setMathTransform(transform.inverse()); transformer.setCoordinateReferenceSystem(sourceCRS);