marineenergy / apps

shiny apps for marineenergy.app
https://marineenergy.github.io/apps/
MIT License
3 stars 1 forks source link

Spatial query funky for cetacean-bia #20

Closed bbest closed 3 years ago

bbest commented 3 years ago

Hey @geocoug,

Something seems amiss with our spatial query for cetacean-bia in spatial | marineenergy.app - Google Sheets or in the R code (see marineenergy/api#3, marineenergy/api#4). I'm getting all kinds of locations outside the targeted area when querying, eg the Gulf of Maine:

image

3.3 Marine Mammals: Biologically Important Areas for Cetaceans

image

geocoug commented 3 years ago

The AOI passed into the PostGIS ST_BUFFER() needs to be cast as geography instead of geometry in functions.R.

Current buffer syntax, which is capturing the entire planet, and therefore all available records in a dataset: select ST_BUFFER({aoi_sql}, {ds$buffer_nm} * 1852) as geom ),

Fix: select ST_BUFFER(({aoi_sql})::geography, {ds$buffer_nm} * 1852) as geom ),

This shorthand type cast requires that only 1 row to be returned in aoi_sql. When the user draws multiple polygons, we use ST_COLLECT() which dissolves polygons into a single feature (versus a UNION which would return a row per polygon).

@bbest - Also noticing we didn't add the nautical mile conversion for all of our buffer distances.

bbest commented 3 years ago

Awesome find @geocoug 🥳 Shall I implement the fixes or are you okay proceeding?