/** * Converts geometry from lat/lon (EPSG:4326)) to Spherical Mercator * (EPSG:3857) * * @param geometry the geometry to convert * @return the geometry transformed to EPSG:3857 */ public Geometry lngLatToMeters(Geometry geometry) { GeometryTransformer transformer = new GeometryTransformer() { @Override protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) { Coordinate[] newCoords = new Coordinate[coords.size()]; for (int i = 0; i < coords.size(); ++i) { Coordinate coord = coords.getCoordinate(i); newCoords[i] = lngLatToMeters(coord); } return new CoordinateArraySequence(newCoords); } }; Geometry result = transformer.transform(geometry); return result; }
/** * Converts geometry from Spherical Mercator * (EPSG:3857) to lat/lon (EPSG:4326)) * * @param geometry the geometry to convert * @return the geometry transformed to EPSG:4326 */ public Geometry metersToLngLat(Geometry geometry) { GeometryTransformer transformer = new GeometryTransformer() { @Override protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) { Coordinate[] newCoords = new Coordinate[coords.size()]; for (int i = 0; i < coords.size(); ++i) { Coordinate coord = coords.getCoordinate(i); newCoords[i] = metersToLngLat(coord); } return new CoordinateArraySequence(newCoords); } }; Geometry result = transformer.transform(geometry); return result; }
/** */ public GeometryTransformer getForwardTransformer ();
/** */ public GeometryTransformer getInverseTransformer ();
/** */ public GeometryTransformer getForwardTransformer () { return new ForwardTransformer((AbstractProjection)clone()); }
/** */ public GeometryTransformer getInverseTransformer () { return new InverseTransformer((AbstractProjection)clone()); }
/** */ public RasterDataset (WritableRaster raster, GridDimensions srcDimensions, Projection srcProj, Projection dstProj) { super("RASTER"); GeometryFactory factory = GISExtension.getState().factory(); GeometryTransformer srcToGeog = srcProj.getInverseTransformer(); GeometryTransformer geogToDst = dstProj.getForwardTransformer(); int minCol = Integer.MAX_VALUE; int maxCol = -1; int minRow = Integer.MAX_VALUE; int maxRow = -1; Envelope newEnvelope = new Envelope(); for (int col = 0; col <= srcDimensions.getGridWidth(); col += 2) { for (int row = 0; row <= srcDimensions.getGridHeight(); row += 2) { Point src = factory.createPoint(new Coordinate(srcDimensions.getColumnLeft(col), srcDimensions.getRowBottom(row))); Point dest = (Point)geogToDst.transform(srcToGeog.transform(src)); if (!dest.isEmpty()) { if (col < minCol) { minCol = col; } if (col > maxCol) { maxCol = col; } if (row < minRow) { minRow = row; } if (row > maxRow) { maxRow = row; } newEnvelope.expandToInclude(dest.getCoordinate()); } } } double scale = StrictMath.min((maxCol - minCol) / newEnvelope.getWidth(), (maxRow - minRow) / newEnvelope.getHeight()); _dimensions = new GridDimensions(new Dimension((int)(scale * newEnvelope.getWidth()), (int)(scale * newEnvelope.getHeight())), newEnvelope); ColorModel srcCM = new ValueColorModel(raster); BufferedImage img = new BufferedImage(srcCM, raster, false, null); RenderedImage dstImage = RasterUtils.reproject(img, srcDimensions, srcProj, _dimensions, dstProj, factory, new double[] { Double.NaN }); _raster = (WritableRaster)dstImage.getData(); _interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST); _interpArray = new double[_interpolation.getHeight()][_interpolation.getWidth()]; GISExtension.getState().datasetLoadNotify(); }