Open CGenie opened 2 weeks ago
Almost all functions, except if stated otherwise (like those suffixed with _sphere
or _spheroid
) do not care what axis order or coordinate system you use. In the planar case, it doesn't matter. DuckDB doesn't track or store the SRID of geometries so it is up to you to know what coordinate system you use and what the axis order convention is.
Like stated, ST_Distance_Sphere
will only give correct results when the x is the latitude, and y is the longitude. If you plan to work with spherical distances you should construct your points in that order. In contrast you might find yourself working with geometries in e.g. EPSG:3857
in which case the CRS mandates that geometries should use easting/northing axis order, but since it is a planar coordinate system it doesn't actually matter when computing e.g. distances or areas.
You may want to read my posts in this thread https://github.com/duckdb/duckdb_spatial/issues/16#issuecomment-2327011935
Hello,
Maybe it's a silly question but I'm kind of lost on how to use
ST_Point2D
. Is itST_Point2D(lat, lon)
orST_Point2D(lon, lat)
? It seems postgis prefers thelon, lat
ordering. However, it distinguishes betweenGEOMETRY
(i.e. planar points) andGEOGRAPHY
(i.e. spherical lat/lon) coordinates and, at least in the latter case, thelon, lat
ordering is used.DuckDB has the
ST_Distance
function https://duckdb.org/docs/extensions/spatial/functions.html#st_distance_sphere and the docs say:Similarly, there are 2 functions:
ST_Point2D
which returnsST_POINT2D
andST_Point
which returnsGEOMETRY
.I made some tests some time ago, where I used this as a tool: https://www.calculator.net/distance-calculator.html
My experiments showed more correct results when using
ST_Point2D(lat, lon)
for theST_Distance
function than when usingST_Point2D(lon, lat)
.