13.07.2013 Views

PostGIS Raster : Extending PostgreSQL for The Support of ... - CoDE

PostGIS Raster : Extending PostgreSQL for The Support of ... - CoDE

PostGIS Raster : Extending PostgreSQL for The Support of ... - CoDE

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 4.44: In-database raster.<br />

directly seen from Quantum GIS (an open source desktop geographic in<strong>for</strong>mation systems). For<br />

instance, the first pixel value <strong>for</strong> the first, the second and the third band are respectively FD, 4E, 46<br />

in hexadecimal. <strong>The</strong>se values correspond to 253, 78 and 70 in decimal.<br />

4.16 Indexing<br />

<strong>PostGIS</strong> <strong>Raster</strong> creates indexes over raster data itself. In this way, user can do really complex<br />

operations on raster data, like getting a set <strong>of</strong> geometry and geometry value from a given raster<br />

band (ST_DumpAsPolygons() function). Unlike Oracle GeoRASTER that creates indexes over spatial<br />

extent, it has more sense when <strong>PostGIS</strong> <strong>Raster</strong> creates indexes over raster data.<br />

In <strong>PostGIS</strong>, loading a new raster table and creating indexes over the raster column can be done<br />

by executing these two lines:<br />

python raster2pgsql.py -r path/*.tif -t raster_table -s 4326 -k 50x50 -I<br />

-o raster_sql.sql<br />

psql -d database -f raster_sql.sql<br />

<strong>The</strong> -s option georeferences the resulting rasters using SRID 4326.<br />

<strong>The</strong> -k option splits image files into tiles <strong>of</strong> 50x50 pixels (one per row). All these tiles do not<br />

overlap and their upper left corners follow a regular block grid. <strong>The</strong> global extent <strong>of</strong> the layer is<br />

rectangular and not rotated.<br />

<strong>The</strong> -I option in<strong>for</strong>ms the loader to create the spatial index on the raster table. This index<br />

is very important as it restricts <strong>PostGIS</strong> <strong>Raster</strong>’s computing ef<strong>for</strong>ts only to the tiles involved in<br />

spatial operations. For example, when finding the intersection <strong>of</strong> the raster_table and a set <strong>of</strong><br />

geometry points, this operation will be per<strong>for</strong>med only on the tiles that actually intersect with the<br />

geometry points. So it is much faster to search <strong>for</strong> those tiles if they are spatially rather than try<br />

them one after the other sequentially from the raster table. If the -I option was not specified when<br />

using raster2pgsql.py, the index can always be created afterward by executing the following SQL<br />

command:<br />

CREATE INDEX rast_gist_idx<br />

ON raster_table<br />

USING GIST (ST_ConvexHull(rast));<br />

<strong>The</strong> ST_ConvexHull() function returns the convex hull geometry <strong>of</strong> the raster including pixel<br />

values equal to BandNoDataValue(). Further, a spatial index can also be made on the geom_points<br />

table to make sure that the intersection operation will be done as quickly as possible:<br />

CREATE INDEX point_geom_idx<br />

ON geom_points<br />

USING GIST (the_geom);<br />

53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!