Hi Daniele, I should have added more context. My source positions don't come from another Grid, they are just point geometries (x,y) in the same CRS for which I must query the intersecting cell value. The GeoTiff is tagged to have "AREA" pixels (see GDAL output [1] below), so I assumed that the GridCoverage's evaluate() method would lookup values anywhere in that cell. Is that not the case? -Matthias
[1]:Driver: GTiff/GeoTIFFFiles: continents.tif continents.tif.aux.xmlSize is 18000, 9000Coordinate System is:GEOGCS["WGS 84", DATUM["WGS_1984", SPHEROID["WGS 84",6378137,298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich",0], UNIT["degree", 0.0174532925199433], AUTHORITY["EPSG","4326"]]Origin = (- 180.000000000000000,90.000000000000000)Pixel Size = (0.020000000000000,-0.020000000000000)Metadata: AREA_OR_POINT=Area TIFFTAG_SOFTWARE=GRASS GIS 7.4.0 with GDAL 2.2.3Image Structure Metadata: COMPRESSION=DEFLATE INTERLEAVE=BANDCorner Coordinates:Upper Left (-180.0000000, 90.0000000) (180d 0' 0.00"W, 90d 0' 0.00"N)Lower Left (-180.0000000, -90.0000000) (180d 0' 0.00"W, 90d 0' 0.00"S)Upper Right ( 180.0000000, 90.0000000) (180d 0' 0.00"E, 90d 0' 0.00"N)Lower Right ( 180.0000000, -90.0000000) (180d 0' 0.00"E, 90d 0' 0.00"S)Center ( 0.0000000, 0.0000000) ( 0d 0' 0.01"E, 0d 0' 0.01"N) Am Freitag, den 22.03.2019, 18:28 +0100 schrieb Daniele Romagnoli: > Hi Matthias,sorry for the late reply. > > I think this is related to PixelIsCorner vs PixelIsCenter convention. > http://docs.geotools.org/stable/javadocs/org/geotools/geometry/GeneralEnvelope.html > In OGC, the grid to CRS transform maps the cell center. > I think that when using the evaluate method you should provide the > cell's center coordinates while GeneralEnvelope reports the cell's > corner coordinates. > (So there is an half pixel shift to be taken into account) > > Something like this should work: > > GridGeometry gridGeometry = gridCoverage.getGridGeometry(); > MathTransform transform = gridGeometry.getGridToCRS(); > // supposing you want to get a coverage's corner > DirectPosition2D sourceDp = new > DirectPosition2D(gridGeometry.getGridRange().getLow(0), > gridGeometry.getGridRange().getHigh(1)); > DirectPosition2D targetDp = new DirectPosition2D(); > transform.transform(sourceDp, targetDp); > gridCoverage.evaluate(targetDp); > > Hope this helps. > Daniele > > > > > > On Fri, Feb 8, 2019 at 2:19 PM Matthias Müller < > matthias_muel...@tu-dresden.de> wrote: > > I am trying to lookup 2D point values from a GeoTiff coverage an > > got the following error from /GridCoverage2D.evaluate()/ [1] > > (Geotools 20.2) > > From the GeoTiff's envelope I would assume that the point (0, > > -90) is within the valid extent but /GridCoverage2D.evaluate()/ > > seems to think otherwise. It the output of > > /GridCoverage2D.getEnvelope()/ consistent with the (minimal) > > bounding box of the coverage or must I use a different query to > > obtain the valid extent? > > Thanks,Matthias > > p.s.: I tested this with a few thousand other points, distributed > > world-wide. So the general procedure seems to work. > > [1]:GEOGCS["WGS 84", DATUM["World Geodetic System > > 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, > > AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], > > PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], > > UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", > > EAST], AXIS["Geodetic latitude", NORTH], > > AUTHORITY["EPSG","4326"]]GeneralEnvelope[(-180.0, > > -90.00000000000001), (180.00000000000006, 90.0)] > > ... > > org.opengis.coverage.PointOutsideCoverageException: Coordinate (0, > > -90) is outside coverage. > > at > > org.geotools.coverage.grid.GridCoverage2D.evaluate(GridCoverage2D.j > > ava:454) at > > org.geotools.coverage.grid.GridCoverage2D.evaluate(GridCoverage2D.j > > ava:398) > > > > _______________________________________________ > > > > GeoTools-GT2-Users mailing list > > > > GeoTools-GT2-Users@lists.sourceforge.net > > > > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > > >
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users