Skip to content

Instantly share code, notes, and snippets.

@marcellobenigno
Last active December 26, 2015 02:59

Revisions

  1. marcellobenigno revised this gist Jan 14, 2014. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions testes_postgis_raster.sql
    Original file line number Diff line number Diff line change
    @@ -32,3 +32,26 @@ pixel_value = classe de capacidade na tabela raster
    */




    -- outros testes
    CREATE TABLE vector_srtm AS
    SELECT row_number() OVER (ORDER BY (gv).val) AS gid, ST_Union((gv).geom) AS geom, (gv).val
    FROM (
    SELECT rid, ST_Intersection(rast, geom) AS gv
    FROM srtm, fazendas
    WHERE ST_Intersects(rast, geom) AND fazendas.gid =1
    ) AS tmp
    GROUP BY (gv).val
    ORDER BY (gv).val;

    ----------------------

    CREATE TABLE vector_srtm_inter AS
    SELECT rid as gid, (gv).geom AS geom, (gv).val
    FROM (
    SELECT rid, ST_Intersection(rast, geom) AS gv
    FROM srtm, fazendas
    WHERE ST_Intersects(rast, geom) AND fazendas.gid =1
    ) inter;
  2. marcellobenigno revised this gist Oct 21, 2013. 1 changed file with 12 additions and 9 deletions.
    21 changes: 12 additions & 9 deletions testes_postgis_raster.sql
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,3 @@
    /*
    value = classe de capacidade na tabela vetorial
    pixel_value = classe de capacidade na tabela raster
    */

    -- Abordagem tradicional (vetor/vetor):
    SELECT foo.value, ST_area(foo.geom::geography)/10000 AS area_ha
    FROM ( SELECT c.value,
    @@ -28,4 +20,15 @@ FROM fazendas f,(
    ) AS tmp
    WHERE ST_Intersects(f.geom, tmp.geom)
    GROUP BY tmp.pixel_value
    ORDER BY tmp.pixel_value;
    ORDER BY tmp.pixel_value;


    /*
    conversão: raster2pgsql -s 4326 -I -C -M capacidade_agricola.tif -F -t 90x90 capacidade_rast > capacidade_rast.sql
    campos:
    value = classe de capacidade na tabela vetorial
    pixel_value = classe de capacidade na tabela raster
    */

  3. marcellobenigno revised this gist Oct 21, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion testes_postgis_raster.sql
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ SELECT foo.value, ST_area(foo.geom::geography)/10000 AS area_ha
    ) as foo
    ORDER BY foo.value;

    -- PostGIS Raster (vetor/raster):
    -- PostGIS Raster (raster/vetor):
    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,
  4. marcellobenigno revised this gist Oct 21, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion testes_postgis_raster.sql
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    value = classe de capacidade na tabela vetorial
    pixel_value = classe de capacidade ma tabela raster
    pixel_value = classe de capacidade na tabela raster
    */

  5. marcellobenigno revised this gist Oct 21, 2013. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions testes_postgis_raster.sql
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@
    /*
    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,
  6. marcellobenigno created this gist Oct 21, 2013.
    23 changes: 23 additions & 0 deletions testes_postgis_raster.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    -- 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;