Skip to content

Kriging with pMode == 1 leaves a black column to the right #12

Description

@rafaelalmeida

While doing kriging with pMode == 1 (the mode in which you supply a GridGeometry instead of a collection of points to be interpolated), the output image has a black column to the right:

screen shot 2015-07-30 at 2 01 17 pm

This is the code that generates the GridGeometry passed to inInterpolationGrid:

GridEnvelope mapGrid = new GridEnvelope2D(0, 0, areaSizeInPixels[0], areaSizeInPixels[1]);
kriging.inInterpolationGrid = new GridGeometry2D(mapGrid, createEnvelopeFromBoundingBox(bounds));

( Where createEnvelopeFromBoundingBox returns an Envelope2D )

The problem seems to arise from a combination of default GeoTools behaviour and this line:

https://github.com/moovida/jgrasstools/blob/56e8fe50de7647cb579a9b28363842353ec20e13/hortonmachine/src/main/java/org/jgrasstools/hortonmachine/modules/statistics/kriging/OmsKriging.java#L568

According to the default Geotools behavior when the pixel anchor is not specified when creating a grid geometry (as is the case above), Geotools will use the OGC default, which is to consider the anchor to be in the middle of the pixel.

In this case, when the coordinate is minimal, Geotools will actually map its resulting x coordinate to -0.5, not 0.5, as I could verify with the code below:

GridEnvelope grid = new GridEnvelope2D(0, 0, 100, 100);
Envelope2D envelope = new Envelope2D(CRS.decode("EPSG:3857"), 10.0, 10.0, 1.0, 1.0);
GridGeometry2D geom = new GridGeometry2D(grid, envelope);

DirectPosition out = geom.getCRSToGrid2D().transform(
        (DirectPosition) new DirectPosition2D(10.0, 10.0), (DirectPosition) new DirectPosition2D());

System.out.println(out.toString());

Which outputs: DirectPosition2D[-0.5000000000001137, 99.5]

Since the line from the OmsKriging module I linked above just casts the coordinates into an int, it drops the decimal cases from -0.5, which becomes -0, which is equivalent to 0. In the second column, the output becomes 0.5, and dropping the case again we have 0.

I don't know why Geotools behaves this way, or if this behaviour is correct.

Should jgrasstools try to compensate for this behavior or let it up to the user to supply a GridGeometry that behaves the way jgrasstools expects it to do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions