Is there any way to check if the point/coordinate to handle the exception and the problem described below.
I have tried creating an envelope from the grid coverage (from the raster file), but that doesnt seem to work.
GridCoverage2D c1 = geography.getCoverage("layer1"); // this is a raster layer
Envelope2D e1 = c1.getEnvelope2D();
DirectPosition pos = new DirectPosition2D(lat, lon);
if(e1.contains(pos))
//point is valid
I get the following exception in spite of checking the point location as shown in the code:
org.opengis.coverage.PointOutsideCoverageException: Coordinate (42.82, 10.608) is outside coverage.
at org.geotools.coverage.grid.GridCoverage2D.evaluate(GridCoverage2D.java:479)
at org.geotools.coverage.grid.GridCoverage2D.evaluate(GridCoverage2D.java:414)
at org.geotools.coverage.grid.GridCoverage2D.evaluate(GridCoverage2D.java:355)