globalmangrovewatch / gmw-api

https://mangrove-atlas-api.herokuapp.com
MIT License
2 stars 1 forks source link

Add spatial query to dashboard endpoint #81

Closed ghelobytes closed 2 years ago

ghelobytes commented 2 years ago

Related ticket: https://github.com/globalmangrovewatch/gmw-users/issues/241

Tasks

ghelobytes commented 2 years ago

Places are locations shown in this list https://mangrove-atlas-api.herokuapp.com/api/v2/locations

Summary of location_type:

{
  "worldwide": 1,
  "wdpa": 158,
  "country": 102,
  "aoi": 2
}
ghelobytes commented 2 years ago

python

from shapely.geometry import Polygon polygon = Polygon([(0, 0), (1, 1), (1, 0)]) polygon.bounds (0.0, 0.0, 1.0, 1.0)



### OR 
- Accept a `location_id` parameter, query database and grab the `bounds` field: `api/dashboard/sites?location_id=999`
ghelobytes commented 2 years ago

PR: https://github.com/globalmangrovewatch/gmw-api/pull/101 Usage:

api/v2/dashboard/sites?extent=minx,miny,maxx,maxy
api/v2/dashboard/sites?extent=-16.1868953704834,12.640254556428197,-16.183032989501953,12.64259955777063
ghelobytes commented 2 years ago

Generate extent for testing:

>>> from shapely.geometry import shape
>>> poly = {
...         "type": "Polygon",
...         "coordinates": [
...           [
...             [
...               -16.1868953704834,
...               12.640254556428197
...             ],
...             [
...               -16.183032989501953,
...               12.640254556428197
...             ],
...             [
...               -16.183032989501953,
...               12.64259955777063
...             ],
...             [
...               -16.1868953704834,
...               12.64259955777063
...             ],
...             [
...               -16.1868953704834,
...               12.640254556428197
...             ]
...           ]
...         ]
...       }
>>>
>>>
>>> poly
{'type': 'Polygon', 'coordinates': [[[-16.1868953704834, 12.640254556428197], [-16.183032989501953, 12.640254556428197], [-16.183032989501953, 12.64259955777063], [-16.1868953704834, 12.64259955777063], [-16.1868953704834, 12.640254556428197]]]}
>>> poly = shape(poly)
>>> poly
<shapely.geometry.polygon.Polygon object at 0x7fc82737e828>
>>> poly.bounds
(-16.1868953704834, 12.640254556428197, -16.183032989501953, 12.64259955777063)
ghelobytes commented 2 years ago

Implemented. Closing.