public void setRasterValue(Coordinate coordinate, int value) { checkState(); if (!boundingBox.contains(coordinate.x, coordinate.y)) { throw new IllegalArgumentException("Can only add raster values for coordinates (" + coordinate + ") within the bounding box (" + boundingBox + ")"); } Point p = this.gridCellSize.getCell(boundingBox, coordinate); LOGGER.log(Level.FINEST, "raster value set to {0} on cell {1}", new Object[]{value, p}); this.raster.setSample(p.x, p.y, 0, value); dirty = true; }
/** * get the cell point (0 index raster position) for the given coordinate * * @param boundingBox * @param coordinate * @return */ public Point getCell(BoundingBox boundingBox, Coordinate coordinate) { assert boundingBox.contains(coordinate.x, coordinate.y):"ERROR:cell requested for coordinate "+coordinate+" outside boundingbox "+boundingBox; int leftRow = new Double(Math.ceil((boundingBox.getMinX() + 180) / (factor * ONE_METER_DEGREE))).intValue(); int bottomRow = new Double(Math.ceil((boundingBox.getMinY() + 90) / (factor * ONE_METER_DEGREE))).intValue(); int cellX = new Double(Math.ceil((coordinate.x + 180) / (factor * ONE_METER_DEGREE))).intValue(); int cellY = new Double(Math.ceil((coordinate.y + 90) / (factor * ONE_METER_DEGREE))).intValue(); int x = cellX - (leftRow); int y = cellY - (bottomRow); Dimension dimension = getDimension(boundingBox); y = Math.abs(y - (dimension.height-1)); // y axis in a raster starts at the top instead of the bottom, so we need to flip the y value assert (x >= 0 && x <= dimension.width) : "x position ("+x+") of cell not within raster bounds (0-"+dimension.width+")"; assert (y >= 0 && y <= dimension.height) : "y position ("+y+")of cell not within raster bounds (0-"+dimension.height+")"; return new Point(x, y); } }
/** * get the cell point (0 index raster position) for the given coordinate * * @param boundingBox * @param coordinate * @return */ public Point getCell(BoundingBox boundingBox, Coordinate coordinate) { assert boundingBox.contains(coordinate.x, coordinate.y):"ERROR:cell requested for coordinate "+coordinate+" outside boundingbox "+boundingBox; int leftRow = new Double(Math.ceil((boundingBox.getMinX() + 180) / (factor * ONE_METER_DEGREE))).intValue(); int bottomRow = new Double(Math.ceil((boundingBox.getMinY() + 90) / (factor * ONE_METER_DEGREE))).intValue(); int cellX = new Double(Math.ceil((coordinate.x + 180) / (factor * ONE_METER_DEGREE))).intValue(); int cellY = new Double(Math.ceil((coordinate.y + 90) / (factor * ONE_METER_DEGREE))).intValue(); int x = cellX - (leftRow); int y = cellY - (bottomRow); Dimension dimension = getDimension(boundingBox); y = Math.abs(y - (dimension.height-1)); // y axis in a raster starts at the top instead of the bottom, so we need to flip the y value assert (x >= 0 && x <= dimension.width) : "x position ("+x+") of cell not within raster bounds (0-"+dimension.width+")"; assert (y >= 0 && y <= dimension.height) : "y position ("+y+")of cell not within raster bounds (0-"+dimension.height+")"; return new Point(x, y); } }
public void setRasterValue(Coordinate coordinate, int value) { checkState(); if (!boundingBox.contains(coordinate.x, coordinate.y)) { throw new IllegalArgumentException("Can only add raster values for coordinates (" + coordinate + ") within the bounding box (" + boundingBox + ")"); } Point p = this.gridCellSize.getCell(boundingBox, coordinate); // LOGGER.log(Level.FINEST, "raster value set to {0} on cell {1}", new Object[]{value, p}); WritableRenderedImage raster = getRenderedImage(); WritableRaster tile = raster.getWritableTile(p.x, p.y); try { tile.setSample(p.x, p.y, 0, value); } catch (ArrayIndexOutOfBoundsException e) { LOGGER.log(Level.WARNING, "ArrayIndexOutOfBoundsException for p.x={0} and p.y={1}", new Object[]{p.x, p.y}); } raster.releaseWritableTile(p.x, p.y); }
/** * Get the cell point (0 index raster position) for the given coordinate. * * @param boundingBox * @param coordinate * @return */ public Point getCell(BoundingBox boundingBox, Coordinate coordinate) { assert boundingBox.contains(coordinate.x, coordinate.y):"ERROR:cell requested for coordinate "+coordinate+" outside boundingbox "+boundingBox; int minX = xIndex(boundingBox.getMinX()); int minY = yIndex(boundingBox.getMinY()); int cellX = xIndex(coordinate.x); int cellY = yIndex(coordinate.y); int x = cellX - minX; int y = cellY - minY; Dimension dimension = getDimension(boundingBox); y = (dimension.height-1) - y; // y axis in a raster starts at the top instead of the bottom, so we need to flip the y value assert (x >= 0 && x < dimension.width) : "x position ("+x+") of cell not within raster bounds (0-"+(dimension.width-1)+")"; assert (y >= 0 && y < dimension.height) : "y position ("+y+") of cell not within raster bounds (0-"+(dimension.height-1)+")"; return new Point(x, y); }