Cast BLOB to GEOMETRY #309
Replies: 3 comments 3 replies
-
Hi @kylebarron, I believe the UScounties.fgb dataset available at https://github.com/flatgeobuf/flatgeobuf/blob/master/test/data/UScounties.fgb?raw=true is already cast to geometry. So, if you want to convert it to WKB_BLOB, you should do the following: DROP TABLE IF EXISTS UScounties;
CREATE TABLE UScounties AS
SELECT * FROM ST_Read('https://github.com/flatgeobuf/flatgeobuf/blob/master/test/data/UScounties.fgb?raw=true') SELECT ST_AsWKB(geom) as WKB_BLOB FROM UScounties; If you want to convert it back: SELECT ST_GeomFromWKB(ST_AsWKB(geom)) as geometry_from_WKB_BLOB FROM UScounties You can see the full example here: https://colab.research.google.com/drive/1uSsdRJwsQeFQ6xp_NcOH6HDfS46wCbgp?usp=sharing |
Beta Was this translation helpful? Give feedback.
-
Also, check out how I am trying to create a partitioned GeoParquet v1.1 with DuckDB and PyArrow from a 1 GB CSV file: DROP TABLE IF EXISTS dataset;
CREATE TABLE dataset AS
SELECT * EXCLUDE (YEAR, GEOPOINT, longitude, latitude),
STRUCT_PACK(
xmin := ST_XMin(ST_Envelope(ST_GeomFromWKB(geometry))),
ymin := ST_YMin(ST_Envelope(ST_GeomFromWKB(geometry))),
xmax := ST_XMax(ST_Envelope(ST_GeomFromWKB(geometry))),
ymax := ST_YMax(ST_Envelope(ST_GeomFromWKB(geometry)))
) AS bbox,
EXTRACT(YEAR FROM CAST(observation_date AS TIMESTAMP)) AS year,
EXTRACT(MONTH FROM CAST(observation_date AS TIMESTAMP)) AS month
FROM (
SELECT *,
ST_AsWKB(ST_Point(longitude, latitude)) AS geometry
FROM read_csv_auto('/content/drive/MyDrive/CNG/My_Tutorials/KSA/Saudi_Arabia_Hourly_Climate_Integrated_Surface_Data/Data/saudi-hourly-weather-data.csv')
) sub;
I hope this makes it clearer if I understand your question correctly. |
Beta Was this translation helpful? Give feedback.
-
With a bit more research, I discovered that my life is easier as long as I rely on a This is all just a workaround until #153 is implemented. |
Beta Was this translation helpful? Give feedback.
-
Hi 👋 . I'm trying to figure out how to cast
BLOB
toGEOMETRY
so that I can manually coerceGEOMETRY
toWKB
.The goal with this is to provide an API where the user just passes in
con
, and where I transparently convert the GEOMETRY to WKB if necessary, instead of the user always having to callST_AsWKB()
on the geometry column.This gives:
Is there a public API to coerce
BLOB
toGEOMETRY
? I'm poor at SQL so I might've missed it. Or is this non-public because the geometry binary format isn't stable?Beta Was this translation helpful? Give feedback.
All reactions