duckdb_spatial icon indicating copy to clipboard operation
duckdb_spatial copied to clipboard

Find spatial reference of a geometry column

Open markruddy opened this issue 1 year ago • 4 comments

Hi, is there an equivalent of the PostGIS statement:

SELECT ST_SRID(geom) FROM my_table;

In duckdb spatial extension? I'd like to be able to query the SRS of tables to troubleshoot spatial queries but can't find ST_SRID implemented(?) Is there an alternative approach to get this information through table properties?

Many thanks

markruddy avatar Mar 08 '24 18:03 markruddy

Hi! duckdb spatial does not store the SRID inside the geometry type, its recommended to keep it in a separate column for now and in the future ST_Read might be able to output it as well. But for now you can use st_read_meta in combination with UNNEST to extract the projection information from a st_read compatible dataset.

Maxxen avatar Mar 13 '24 08:03 Maxxen

Hi Maxxen, Can you please give an example of the sql query that uses the combination of st_read_meta and UNNEST to parse out the projection information for a geoparquet file? I am stuck here at this point unable to figure out how to parse the result. I am using this query: Image

The result I get is this and I am not sure how to parse the result in Javascript to extract the projection info. Image

Thanks

kbatchu avatar Feb 15 '25 13:02 kbatchu

You can't use st_read_meta for parquet files, parquet files are handled by duckdbs parquet extension and so in this case to read geoparquet metadata you should use the parquet_kv_metadata function. Example:

SELECT decode(value) as col FROM parquet_kv_metadata('http://github.dev/opengeospatial/geoparquet/blob/main/examples/example.parquet');

That's going to give you the geoparquet metadata as a JSON.

Maxxen avatar Feb 15 '25 13:02 Maxxen

Thank you. I got it now.

kbatchu avatar Feb 15 '25 16:02 kbatchu