1

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)
MyStackRunnethOver
  • 4,872
  • 2
  • 28
  • 42
Swapna
  • 31
  • 1
  • Could you include your code following `if(e1.contains(pos))`? It would also be helpful if you could include and point out the line that throws the top-level `PointOutsideCoverageException` – MyStackRunnethOver Aug 14 '19 at 22:21

1 Answers1

1

I think you need to switch the order of lat,lon in the DirectPosition2d constructor so that it reads:

DirectPosition pos = new DirectPosition2D(lon, lat); 

The exception is not being thrown from the code sample you posted, rather it occurs later when you call coverage.evaluate(pos) because the position is actually not valid. Geotools expects a (lon,lat) axis order by default - see https://docs.geotools.org/latest/userguide/library/referencing/order.html

Eric Tatara
  • 715
  • 3
  • 12