I make a geospatial analysis, in Google BigQuery, which mostly includes making difference (I mean ST_Difference) between parcels geometry and some objects like woods, buildings etc. Some of objects I need to exclude are quite big, like 5 000 000 square meters. I used a grid (100mx100m) to cut them to smaller pieces, and that makes my analysis much quicker, about 50 times quicker. What is the best size of grid to use to gain best performance?
thats my query:
select
w.id,
st_difference(st_union_agg(w.geom_zakwalifikowana), st_union_agg(st_buffer(g.geom, bufor_wewn))) geom_bdot
from
model.obszar_analizy w,
bdot.polska_300m_siatka g
where st_dwithin(w.geom_zakwalifikowana, g.geom, bufor_wewn )
and g.kod in unnest(lista_bdot)
group by w.id_dzialki;
model.obszar_analizy is a table with parcels covering a given area (500-1000 square km area).
bdot.polska_300m_siatka is a table with topographic objects (e.g. houses, roads, forests, rivers, etc.), some of them were large or long, so I made an intersection with a grid of 100 by 100 meters squares.
I want to remove from the parcels table those parts of the geometry that are too close to the topographic object.