ajnisbet / opentopodata

Open alternative to the Google Elevation API!
https://www.opentopodata.org
MIT License
314 stars 68 forks source link

Diagnostic issues with locations outside of raster bounds #26

Closed janusw closed 3 years ago

janusw commented 3 years ago

If I query a location outside of the region covered by the EU-DEM data on my own server, I get:

curl "https://myserver/v1/eudem25m?locations=0,0"       
{
  "error": "Location '0.0,0.0' has latitude outside of raster bounds", 
  "status": "INVALID_REQUEST"
}

If I do the same on opentopodata.org, the reply is different:

curl "https://api.opentopodata.org/v1/ned10m?locations=0,0"       
{
  "results": [
    {
      "elevation": null, 
      "location": {
        "lat": 0.0, 
        "lng": 0.0
      }
    }
  ], 
  "status": "OK"
}

So my first question is: Where does this difference come from? Seems to be another undocumented config aspect of the EU-DEM data (and apparently affects other data sets as well).

And then there is an additional problem with the error message above. If I combine a valid and an invalid point, the error message always refers to valid one:

curl "https://myserver/v1/eudem25m?locations=0,0|50,10"
{
  "error": "Location '50.0,10.0' has latitude outside of raster bounds", 
  "status": "INVALID_REQUEST"
}

This was already noticed in #24, where I suspected that this is simply an of-by-one error. However, no matter how many invalid locations I add, the error message always mentions the only valid point in the request:

curl "https://myserver/v1/eudem25m?locations=0,0|0,0|50,10|0,0|0,0|0,0"
{
  "error": "Location '50.0,10.0' has latitude outside of raster bounds", 
  "status": "INVALID_REQUEST"
}

This behavior is very weird! Unfortunately I was not able to reproduce this with the server at opentopodata.org. (In fact I was not able to trigger this error message at all, as explained above.)

ajnisbet commented 3 years ago

The error message was returning the first correct location, rather than the first incorrect one! That is fixed in https://github.com/ajnisbet/opentopodata/commit/e05edc6139c71ad66c62a0679c8b01a305669197

As for the main issue: that error message should only be shown if the location corresponds to a tile filename and that file doesn't contain the location. There's two reasons for this

So for EU-DEM on api.opentopodata.org not only did I add a buffer, but I increased the size (with NULL data) to make the tiles full squares. I'll fix that by better documenting the EU-DEM ingestion process.

I'm not sure what the best thing is to do in the case of a tile with partial coverage. I'm inclined to return null instead of raising an exception, which would be consistent with querying a location far outside the bounds of the dataset. Do you have any thoughts about that?

What I can't explain is why you would get that error at 0,0 for EU-DEM. That location shouldn't correspond to an EU-DEM tile, and locations without a tile should get a None elevation :

https://github.com/ajnisbet/opentopodata/blob/e05edc6139c71ad66c62a0679c8b01a305669197/opentopodata/backend.py#L185-L187

ajnisbet commented 3 years ago

Fixed in https://github.com/ajnisbet/opentopodata/commit/b3377846caf7c8b20f149e2b6acd03331df1a346

janusw commented 3 years ago

And then there is an additional problem with the error message above. If I combine a valid and an invalid point, the error message always refers to valid one:

curl "https://myserver/v1/eudem25m?locations=0,0|50,10"
{
  "error": "Location '50.0,10.0' has latitude outside of raster bounds", 
  "status": "INVALID_REQUEST"
}

This was already noticed in #24, where I suspected that this is simply an of-by-one error. However, no matter how many invalid locations I add, the error message always mentions the only valid point in the request:

curl "https://myserver/v1/eudem25m?locations=0,0|0,0|50,10|0,0|0,0|0,0"
{
  "error": "Location '50.0,10.0' has latitude outside of raster bounds", 
  "status": "INVALID_REQUEST"
}

Alright, I can confirm that this secondary problem (i.e. the wrong location being mentioned in the error message) is fixed with e05edc6139c71ad66c62a0679c8b01a305669197. Many thanks for the fix, and sorry that it took me so long to confirm.

Unfortunately you have not mentioned this issue (#26) in the commit message. It would be good practice to do that (in order to have a link from the commit back to the discussion here, for future reference), and I strongly recommend to adopt this practise for future commits :)

janusw commented 3 years ago

If I query a location outside of the region covered by the EU-DEM data on my own server, I get:

curl "https://myserver/v1/eudem25m?locations=0,0"       
{
  "error": "Location '0.0,0.0' has latitude outside of raster bounds", 
  "status": "INVALID_REQUEST"
}

On then for the original ('primary') problem reported here: Yes, this is fixed with b3377846caf7c8b20f149e2b6acd03331df1a346. Thanks a bunch!

The big advantage of returning a NULL value (as opposed to an invalid-request error), is that for multi-location requests, one still obtains the elevation values for the other (valid) locations.