for (int n = 0; n < coords.length; n++) { worldPos.setLocation(coords[n].x, coords[n].y); GridCoordinates2D gridPos = gridGeom.worldToGrid(worldPos); coordGridX[n] = gridPos.x; coordGridY[n] = gridPos.y;
public static JGrassRegion getJGrassRegionFromGridCoverage(GridCoverage2D gridCoverage2D) throws InvalidGridGeometryException, TransformException { Envelope2D env = gridCoverage2D.getEnvelope2D(); GridEnvelope2D worldToGrid = gridCoverage2D.getGridGeometry().worldToGrid(env); double xRes = env.getWidth() / worldToGrid.getWidth(); double yRes = env.getHeight() / worldToGrid.getHeight(); JGrassRegion region = new JGrassRegion( env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), xRes, yRes); return region; }
/** * Writes the {@link GridCoverage2D supplied coverage} to disk. * * <p>Note that this also takes care to cloes the file handle after writing to disk. * * @param gridCoverage2D the coverage to write. * @throws IOException */ public void writeRaster(GridCoverage2D gridCoverage2D) throws IOException { try { Envelope2D env = gridCoverage2D.getEnvelope2D(); GridEnvelope2D worldToGrid = gridCoverage2D.getGridGeometry().worldToGrid(env); double xRes = env.getWidth() / worldToGrid.getWidth(); double yRes = env.getHeight() / worldToGrid.getHeight(); JGrassRegion region = new JGrassRegion( env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), xRes, yRes); GrassBinaryImageWriterSpi writerSpi = new GrassBinaryImageWriterSpi(); GrassBinaryImageWriter writer = new GrassBinaryImageWriter(writerSpi, monitor); RenderedImage renderedImage = gridCoverage2D.getRenderedImage(); writer.setOutput(output, region); writer.write(renderedImage); writer.dispose(); } catch (Exception e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e); } }
public double getSlope(Point position, SlopeType slopeType) { double retVal = noData; GridGeometry2D gg2D = grid2D.getGridGeometry(); CoordinateReferenceSystem crs = grid2D.getCoordinateReferenceSystem(); Coordinate coord = position.getCoordinate(); DirectPosition gdPos = new DirectPosition2D(crs, coord.x, coord.y); try { GridCoordinates2D pos = gg2D.worldToGrid(gdPos); retVal = this.getSlope(pos); if (slopeType == SlopeType.Degree) { retVal = Math.toDegrees(retVal); } else { retVal = Math.tan(retVal) * 100; } } catch (InvalidGridGeometryException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } catch (TransformException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } return retVal; }
public double getAspect(Point position) { double retVal = noData; GridGeometry2D gg2D = grid2D.getGridGeometry(); CoordinateReferenceSystem crs = grid2D.getCoordinateReferenceSystem(); Coordinate coord = position.getCoordinate(); DirectPosition gdPos = new DirectPosition2D(crs, coord.x, coord.y); try { GridCoordinates2D pos = gg2D.worldToGrid(gdPos); retVal = this.getAspect(pos); } catch (InvalidGridGeometryException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } catch (TransformException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } return retVal; }
for (int n = 0; n < coords.length; n++) { worldPos.setLocation(coords[n].x, coords[n].y); GridCoordinates2D gridPos = gridGeom.worldToGrid(worldPos); coordGridX[n] = gridPos.x; coordGridY[n] = gridPos.y;
public double getElevation(Coord coord) { GridGeometry2D gg = grid.getGridGeometry(); Coord transformedCoord = ct.transform(coord); GridCoordinates2D posGrid = null; try { posGrid = gg.worldToGrid(new DirectPosition2D(transformedCoord.getX(), transformedCoord.getY())); } catch (InvalidGridGeometryException e) { e.printStackTrace(); } catch (TransformException e) { e.printStackTrace(); } double[] pixel = new double[1]; double[] data = gridData.getPixel(posGrid.x, posGrid.y, pixel); return data[0]; } }