I have created a grid using fishnet which has cells that are equal to 10 m (with and height) and the grid size is 2.24 x 2.24 km. Using this grid I would like to extract all band values from the raster. How can I speed up the extraction?
Currently, I tried:
DROP TABLE IF EXISTS public.band_value_1_whole_km;
CREATE TABLE public.band_value_1_whole_km AS
SELECT
g.gid,
g.geom,
g.row,
g.col,
st_value(rd.rast, 1, st_centroid(g.geom)) as band_2,
st_value(rd.rast, 2, st_centroid(g.geom)) as band_3,
st_value(rd.rast, 3, st_centroid(g.geom)) as band_4,
st_value(rd.rast, 4, st_centroid(g.geom)) as band_8,
st_value(rd.rast, 5, st_centroid(g.geom)) as band_11,
st_value(rd.rast, 6, st_centroid(g.geom)) as ndvi,
st_value(rd.rast, 7, st_centroid(g.geom)) as ndbi
FROM
public.grid_for_test_1km_vector g
left jOIN
public.t32ulc_entire_tile rd
on
st_intersects(rd.rast, g.geom);
grid_for_test_1km_vector is grid table that contains polygons, while t32ulc_entire_tile has raster data that has the area which intersects with the grid polygons. This query executes very slowly...