0

I have 2 tables in BQ; one of them includes a geography column PointWKT (gps POINT) and second table includes a geography column BoundaryWKT (POLYGONS & MULTIPOLYGONS). Both tables also include DateTime column.

I want to do a spatial join so each PointWKT will be assigned to corresponding BoundaryWKT. Until today, i was using GeoPandas but now i have to switch to SQL.

Is there any way in SQL BigQuery that would substitute geopandas .sjoin like:

join_df = gpd.sjoin(table1, table2, how="inner", op='within')

ANSWER to this question:

SELECT * FROM table1, table2 WHERE ST_Contains (table1.geom, table2.geom)

Another question is, if it is possible to include another condition for joining?

Besides the spatial join from geography columns i also need to include join on DateTime column from both tables.

Is this even possible?

2
  • 2
    One Question only please, you can ask two separate questions.
    – Mapperz
    Commented Jun 17, 2020 at 12:56
  • Please do not include answers in the area reserved for your single question.
    – PolyGeo
    Commented Jun 25, 2022 at 20:19

1 Answer 1

1

This is definitely possible, but the performance might vary depending on cardinality of various intersections.

You can include various conditions in WHERE clause, including condition on DateTime.

Say you can do something like

SELECT * FROM table1, table2 WHERE ST_Contains (table1.geom, table2.geom) 
  AND (table1.datetime BETWEEN DATETIME_SUB(table2.datetime, INTERVAL 10 MINUTE)
                           AND DATETIME_ADD(table2.datetime, INTERVAL 10 MINUTE))
1
  • Thanks for sharing this! it doesn't exactly solve my problem but you definitely showed a way to go!
    – KayEss
    Commented Jun 18, 2020 at 8:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.