I am having an issue that I have not been able to troubleshoot (see below for code to replicate). I am calculating the area in meters using ST_Area_Spheroid, but I am getting NaN as the result. I don't get NaN when using ST_Area, and I am also able to calculate the area in QGIS, so I am not sure where I am going wrong. Does anybody have any idea what could be causing this issue? I made sure to fix any invalid geometries using PostGIS's ST_MakeValid function.
import duckdb con = duckdb.connect() con.install_extension("spatial") con.load_extension("spatial") con.execute(""" DROP TABLE IF EXISTS geo_data; CREATE TABLE geo_data AS SELECT da_dguid, ST_Area_Spheroid(geom) as st_area_spheroid, ST_Area(geom) as st_area, geom FROM 'https://data-01.dataforcanada.org/processed/statistics_canada/boundaries/2021/digital_boundary_files/da_2021.parquet' WHERE isnan(ST_Area_Spheroid(geom)) """) issues = con.sql(""" SELECT * EXCLUDE geom FROM geo_data; """).df() issues
ST_Area_Spheroidassumes lat/long axis order. I have see it return NaN if the coordinates are passed in as long/lat. Tryalways_xy := trueand see if that changes anything.