VectorToRasterProcess fails for point data

Description

Reported Mike O'Toole on the user list - rasterizing point features always results in a grid coverage where all cells are zero. The problem is that the AWT methods used to draw vectors into the backing image only make sense for polygons and lines.

The following code produced a correct result with Mike's data:

GridCoverageFactory gcf =
CoverageFactoryFinder.getGridCoverageFactory();
WritableRaster raster =
RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT, numCols,
numRows, 1, java.awt.Point(0, 0));
GridCoverage2D cov = gcf.create(
ReferencedEnvelope(minx, maxx, miny, maxy, crs));

GridGeometry2D gg = cov.getGridGeometry();
SimpleFeatureIterator iter = collection.features();

{
(iter.hasNext()) {
SimpleFeature feature = iter.next();
Geometry p = (Geometry) feature.getDefaultGeometry();
);

Coordinate pcoord = p.getCoordinate();
DirectPosition pos = DirectPosition2D(pcoord.x, pcoord.y);

GridCoordinates2D gc = gg.worldToGrid(pos);
raster.setSample(gc.x, gc.y, 0, value);
}
} {
iter.close();
}

Put this into VectorToRasterProcess to deal with point data.

Environment

None

Activity

Show:
codehaus
April 10, 2015, 3:12 PM

CodeHaus Comment From: mbedward - Time: Wed, 13 Apr 2011 01:22:59 -0500
---------------------
Ended up using different logic to the code snippet - more compatible with the existing code. Added a test for point data.

Committed to 2.7.x branch (r36916) and trunk (r36917).

Fixed

Assignee

Unassigned

Reporter

codehaus

Triage

None

Fix versions

Affects versions

Priority

Medium
Configure