Skip to content

Instantly share code, notes, and snippets.

@marcellobenigno
Last active December 26, 2015 02:59
Show Gist options
  • Save marcellobenigno/7082163 to your computer and use it in GitHub Desktop.
Save marcellobenigno/7082163 to your computer and use it in GitHub Desktop.
Testes_PostGIS_Raster
/*
value = classe de capacidade na tabela vetorial
pixel_value = classe de capacidade ma tabela raster
*/
-- Abordagem tradicional (vetor/vetor):
SELECT foo.value, ST_area(foo.geom::geography)/10000 AS area_ha
FROM ( SELECT c.value,
ST_Union(ST_Intersection(f.geom, c.geom)) as geom
FROM fazendas f, capacidade_vect c
WHERE ST_Intersects(f.geom, c.geom)
AND f.gid = 6
GROUP BY c.value
) as foo
ORDER BY foo.value;
-- PostGIS Raster (vetor/raster):
SELECT tmp.pixel_value, ST_area(Geography(ST_Union(ST_Intersection(f.geom, tmp.geom))))/10000 AS area_ha
FROM fazendas f,(
SELECT (ST_DumpAsPolygons(ST_Clip(c.rast, ST_Buffer(f.geom, 0.01), TRUE))).val AS pixel_value,
(ST_DumpAsPolygons(ST_Clip(c.rast, ST_Buffer(f.geom, 0.01), TRUE))).geom AS geom
FROM fazendas f, capacidade_rast c
WHERE ST_Intersects(ST_Buffer(f.geom, 0.01), c.rast)
AND f.gid = 6
) AS tmp
WHERE ST_Intersects(f.geom, tmp.geom)
GROUP BY tmp.pixel_value
ORDER BY tmp.pixel_value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment