[postgis-devel] [PostGIS] #595: [raster] Add a series of ST_SetValues functions

PostGIS trac at osgeo.org
Fri Aug 31 14:31:47 PDT 2012


#595: [raster] Add a series of ST_SetValues functions
---------------------+------------------------------------------------------
 Reporter:  pracine  |       Owner:  pracine      
     Type:  task     |      Status:  new          
 Priority:  medium   |   Milestone:  PostGIS 2.1.0
Component:  raster   |     Version:  trunk        
 Keywords:  history  |  
---------------------+------------------------------------------------------

Comment(by dustymugs):

 Are you sure about Variant 1 (from scripts/plpgsql) working in world
 coordinates?  For example, with a skewed raster...

 {{{
 WITH foo AS (
         SELECT ST_SetValues(
                 ST_AddBand(ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 1, 1, 0),
 1, '8BUI', 1, 0),
                 1,
                 1, 1,
                 ARRAY[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
         ) AS rast
 ),
 bar AS (
         SELECT ST_AddBand(ST_MakeEmptyRaster(3, 3, 1, -1, 1, -1, 0, 0, 0),
 1, '8BUI', 0, 0) AS rast
 )
 SELECT
         (pap).x,
         (pap).y,
         (pap).val
 FROM (
         SELECT
                 ST_PixelAsPolygons(ST_SetValues(
                         bar.rast, 1,
                         NULL, NULL,
                         NULL, NULL,
                         foo.rast, 1,
                         FALSE, FALSE
                 )) AS pap
         FROM bar
         CROSS JOIN foo
 ) t
 }}}

 results

 {{{
 psql:test.sql:27: NOTICE:  aaa oldy=1, newheight=<NULL>
 psql:test.sql:27: NOTICE:  bbb newx=1, newy=1
 psql:test.sql:27: NOTICE:  ccc newwidth=3, newheight=3
 psql:test.sql:27: NOTICE:  111 x2=0, y2=0
 psql:test.sql:27: NOTICE:  222 newx=1, newy=1
 psql:test.sql:27: NOTICE:  333 newwidth=2, newheight=2
 psql:test.sql:27: NOTICE:  555 newx + newwidth - 1=2, newy + newheight -
 1=2
 psql:test.sql:27: NOTICE:  666 x=1, y=1
 psql:test.sql:27: NOTICE:  666 x=1, y=2
 psql:test.sql:27: NOTICE:  666 x=2, y=1
 psql:test.sql:27: NOTICE:  666 x=2, y=2
  x | y | val
 ---+---+-----
  1 | 1 |   5
  2 | 1 |   6
  3 | 1 |
  1 | 2 |   8
  2 | 2 |   9
  3 | 2 |
  1 | 3 |
  2 | 3 |
  3 | 3 |
 }}}

 That is completely incorrect especially when visualized in the attached
 image (flawed.png).

 Another simpler example, different scales...

 {{{
 WITH foo AS (
         SELECT ST_SetValues(
                 ST_AddBand(ST_MakeEmptyRaster(3, 3, 0, 0, 0.1, -0.1, 0, 0,
 0), 1, '8BUI', 1, 0),
                 1,
                 1, 1,
                 ARRAY[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
         ) AS rast
 ),
 bar AS (
         SELECT ST_AddBand(ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
 1, '8BUI', 0, 0) AS rast
 )
 SELECT
         (pap).x,
         (pap).y,
         (pap).val
 FROM (
         SELECT
                 ST_PixelAsPolygons(ST_SetValues(
                         bar.rast, 1,
                         NULL, NULL,
                         NULL, NULL,
                         foo.rast, 1,
                         FALSE, FALSE
                 )) AS pap
         FROM bar
         CROSS JOIN foo
 ) t
 }}}

 results

 {{{
 psql:test.sql:27: NOTICE:  aaa oldy=1, newheight=<NULL>
 psql:test.sql:27: NOTICE:  bbb newx=1, newy=1
 psql:test.sql:27: NOTICE:  ccc newwidth=3, newheight=3
 psql:test.sql:27: NOTICE:  111 x2=1, y2=1
 psql:test.sql:27: NOTICE:  222 newx=1, newy=1
 psql:test.sql:27: NOTICE:  333 newwidth=3, newheight=3
 psql:test.sql:27: NOTICE:  555 newx + newwidth - 1=3, newy + newheight -
 1=3
 psql:test.sql:27: NOTICE:  666 x=1, y=1
 psql:test.sql:27: NOTICE:  666 x=1, y=2
 psql:test.sql:27: NOTICE:  666 x=1, y=3
 psql:test.sql:27: NOTICE:  666 x=2, y=1
 psql:test.sql:27: NOTICE:  666 x=2, y=2
 psql:test.sql:27: NOTICE:  666 x=2, y=3
 psql:test.sql:27: NOTICE:  666 x=3, y=1
 psql:test.sql:27: NOTICE:  666 x=3, y=2
 psql:test.sql:27: NOTICE:  666 x=3, y=3
  x | y | val
 ---+---+-----
  1 | 1 |   1
  2 | 1 |   2
  3 | 1 |   3
  1 | 2 |   4
  2 | 2 |   5
  3 | 2 |   6
  1 | 3 |   7
  2 | 3 |   8
  3 | 3 |   9
 }}}

 By the looks of it, the function is working in raster coordinates instead.

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/595#comment:13>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-devel mailing list