ajnisbet / opentopodata

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

Adding support querying many data sets for one location #41

Closed webmap2015 closed 3 years ago

webmap2015 commented 3 years ago

Hi,

Could you add support querying many data sets for one location.

Not like

https://api.opentopodata.org/v1/nzdem8m,mapzen?locations=location1|location2

Like

https://api.opentopodata.org/v1/aster30m,etopo1,eudem25m,mapzen,ned10m,nzdem8m,srtm30m,srtm90,emod2018,gebco2020,bkg200m?locations=39.7471, -104.9963

Result

image

Thanks.

ajnisbet commented 3 years ago

I'm curious what your usecase for this feature would be? Most users I've talked to only use a single dataset.

I would suggest you make concurrent requests, one per dataset.

The simplest way to implement this feature would be to query each dataset sequentially, which would be much slower than concurrent requests. The 'proper' way to implement this would be to spawn processes and query the datasets in parallel, which would complicate the code and probably still be less efficient than letting uwsgi handle the parallelism of concurrent requests.

webmap2015 commented 3 years ago

I would like to find an average value by benchmarking between the result of data sets.

Actually, I found a temporary solution and I'm adding same location to end of query, but max four times.

Because, there is a limitation about querying. "The public API is currently limited to 4 datasets per query."

https://api.opentopodata.org/v1/aster30m,etopo1,eudem25m,mapzen?locations=location1|location1|location1|location1

https://api.opentopodata.org/v1/ned10m,nzdem8m,srtm30m,srtm90?locations=location1|location1|location1|location1

https://api.opentopodata.org/v1/emod2018,gebco2020,bkg200m?locations=location1|location1|location1

ajnisbet commented 3 years ago

I don't think that will work for you, repeating the same location will give an identical result.

For example, https://api.opentopodata.org/v1/aster30m,etopo1,eudem25m,mapzen?locations=39.747114,-104.996334|39.747114,-104.996334|39.747114,-104.996334|39.747114,-104.996334

returns

{
  "results": [
    {
      "dataset": "aster30m", 
      "elevation": 1591.0, 
      "location": {
        "lat": 39.747114, 
        "lng": -104.996334
      }
    }, 
    {
      "dataset": "aster30m", 
      "elevation": 1591.0, 
      "location": {
        "lat": 39.747114, 
        "lng": -104.996334
      }
    }, 
    {
      "dataset": "aster30m", 
      "elevation": 1591.0, 
      "location": {
        "lat": 39.747114, 
        "lng": -104.996334
      }
    }, 
    {
      "dataset": "aster30m", 
      "elevation": 1591.0, 
      "location": {
        "lat": 39.747114, 
        "lng": -104.996334
      }
    }
  ], 
  "status": "OK"
}

As for the 4-dataset limit: multi-dataset queries can be really expensive to compute, and my server was struggling with them. So I put a limit onto the public API only: if you self-host there is no such limit.