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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

SELECT ST_AsJPEG(rast) As rastjpg<br />

FROM dummy_rast<br />

WHERE rid=1;<br />

5.6.3 <strong>Raster</strong> to PNG File<br />

<strong>The</strong> ST_AsPNG(raster, band/numberbands, compression) function returns the selected raster bands<br />

as a single PNG image (byte array). Where:<br />

– band: a number that specifies a band <strong>for</strong> single band export.<br />

– numberbands: an array <strong>of</strong> bands used to export. Bands are mapped to RGB or RGBA space.<br />

For example, ARRAY[3,2,1] means map band 3 to Red, band 2 to green and band 1 to blue.<br />

If both band and numberbands are not specified, then all bands are used if the raster has 1, 3, or<br />

4 bands and. If it has 2 or more than 4 bands, then only band 1 is used.<br />

– compression is a number from 1 to 9.<br />

SELECT ST_AsPNG(rast) As rastpng<br />

FROM dummy_rast WHERE rid=2;<br />

5.7 Intersect <strong>Raster</strong>s with Vectors<br />

One approach to make this operation is to convert all raster tiles to a set <strong>of</strong> geometries and do a<br />

traditional intersection query between geometries only. <strong>The</strong> problem is that vectorizing all the tiles<br />

will be too long and it is impossible to load a huge number <strong>of</strong> geometry in GIS s<strong>of</strong>tware. Since it is<br />

mostly impossible to convert those tiles to vectors, the <strong>PostGIS</strong> <strong>Raster</strong> approach will vectorize only<br />

what is needed to do the requested operation.<br />

In the intersection, if a geometry completely overlaps a nodata value area <strong>of</strong> one tile, st_intersects(rast,<br />

geom) will return false <strong>for</strong> this tile/geometry couple and st_intersection(rast, geom)<br />

will return an EMPTY GEOMETRY without vectoring this tile. If the geometry partially overlaps a nodata<br />

value area and intersects other parts <strong>of</strong> the tile, st_intersects(rast, geom) will return true <strong>for</strong> this<br />

tile/geometry couple and st_intersection(rast, geom) will return only values <strong>of</strong> parts <strong>of</strong> the tile<br />

that intersects the geometry.<br />

5.7.1 Intersect <strong>Raster</strong>s with Points<br />

Practically, user can use intersection operation to extract ground elevation values <strong>for</strong> lidar (Light<br />

Detection And Ranging) 1 points.<br />

SELECT pointID, ST_Value(rast, geom) elevation<br />

FROM lidar, srtm WHERE ST_Intersects(geom, rast)<br />

Figure 5.4: Intersection <strong>of</strong> raster and geometric points [23].<br />

In the above request, the intersection(raster,vector) operation is not necessarily needed. This is<br />

due to the fact that each geometric point is represented by a pixel or a cell <strong>of</strong> a grid. So to extract<br />

1 http://en.wikipedia.org/wiki/LIDAR.<br />

68

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

Saved successfully!

Ooh no, something went wrong!