duckdb / duckdb_spatial

MIT License
489 stars 40 forks source link

Spherical Geometry for All Operations #376

Closed jaredlander closed 3 months ago

jaredlander commented 3 months ago

I was originally going to ask for a specific function such as st_buffer_spheroid() which would allow me to create a buffer around a polygon (or point or linestring) with the buffer size specified in meters instead of degrees. While I very much want that in order to avoid changing the projection 3857, computing the buffer then changing back to 4326.

While I really want that one particular function, I know that I'll eventually need the other functions to be spherical as well. It would be nice to have a spherical option for all the spatial operations, either by a *-spheroid() function, an argument to existing functions or a global setting.

R's {sf} does this globally be setting sf_use_s2(TRUE) (the default) and PostGIS does it with the GEOGRAPHY type.

So, this is a feature request not an issue, and I would love for there to be an st_buffer_spheroid() function and even better if other operations had spherical options too.

Maxxen commented 3 months ago

We're probably doing a GEOGRAPHY type at some point in the future that defaults to spherical (not ellipsoidal as with _spheroid) operations. I don't know of any system or library that can compute buffers on an ellipsoid. AFAIK PostGIS st_buffer implementation for geographies does a reprojection to planar space, computes the buffer and then converts it back to the original projection, although by automatically trying to figure out a fitting planar projection to minimize distortion. I guess we could probably look at implementing something similar after I rework projection handling in general (planned as the next big work-item after i finish up spatial indexes).