duckdb / duckdb_spatial

MIT License
492 stars 41 forks source link

ST_Read fails on GeoJSON data with 3D coordinates #244

Closed jheer closed 7 months ago

jheer commented 10 months ago

Some GeoJSON files may include 3D points -- geometries whose coordinates can contain 3 dimensions. This is a valid part of the GeoJSON specification. Here's one example of this in the wild, from the USGS: https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson

At first glance, it looks like this is supported by GDAL (though to be fair I did not look very deep):

However, trying to read such a file with the spatial extension fails. If you run the following in DuckDB v0.9.2:

INSTALL spatial;
LOAD spatial;
CREATE TABLE quakes AS SELECT *
FROM ST_READ('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson')

The result is:

Error: Not implemented Error: Geometry type '1001' not supported

Even if DuckDB spatial does not support points other than Point2D, it would be useful to be able to parse the first two coordinates (e.g., lat/lon) rather than fail with an error. Thanks!

Maxxen commented 10 months ago

Hi! Thanks for reporting this issue. Thankfully this is already fixed in #226

Sorry, just saw that this was in ST_READ. Yes, the problem is that even though GDAL supports it DuckDB will reject any geometries containig z-values when it reada from GDAL. We could probably relax this though so that we just drop the z axis. Will look into it!

jheer commented 10 months ago

Thanks!! I would love to see this addition and we'd make good use of it in the Mosaic project.

Maxxen commented 7 months ago

DuckDB Spatial now supports coordinates with Z and M values properly, so this is now possible without information loss!