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.

sdo_geor.importFrom(geor, ’blocksize=(256,256)’, ’TIFF’, ’file’, ’srtm_new.tif’);<br />

UPDATE spain_images SET image = geor WHERE image_id = 1;<br />

END;<br />

<strong>The</strong> same operation is repeated <strong>for</strong> every image file. If these images <strong>for</strong>m a non-continuous coverage,<br />

two new tables are needed <strong>for</strong> each image file.<br />

Loading Using <strong>PostGIS</strong> <strong>Raster</strong><br />

When loading raster data by using GDAL driver, the loader creates all that are necessary to store<br />

the raster data into a SQL file. It consists <strong>of</strong> creating the needed tables, the indexes (if it is specified)<br />

and inserting raster data into the tables. A single or a set <strong>of</strong> raster images can be loaded all only once.<br />

Example:<br />

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

-o srtm.sql<br />

Next step is to execute the srtm.sql file using psql:<br />

psql -d postgis_db -f srtm.sql -U user -W<br />

3.2.6 Intersecting <strong>Raster</strong> and Vector Layers<br />

Intersecting in Oracle Geo<strong>Raster</strong><br />

It is impossible to intersect directly raster and vector data in Oracle Geo<strong>Raster</strong>. Instead, what user<br />

can do is to select a sampling window to clip an area <strong>of</strong> the raster and get raster data over this area.<br />

<strong>The</strong> sampling windows must be rectangular or the round windows cannot be used (As described in<br />

SDO_GEOR.generateStatistics documentation 2 ). So the MBR is used as solution.<br />

In the following example, the sampling windows are the geometry objects stored in sampling_win table.<br />

<strong>The</strong> request will calculate the intersection between the sampling windows and the spatial extent <strong>of</strong><br />

the Geo<strong>Raster</strong> objects [15]:<br />

DECLARE<br />

cellCoordinate mdsys.sdo_geometry;<br />

ret varchar2(256);<br />

gr sdo_georaster;<br />

BEGIN<br />

-- Intersect spatial extent <strong>of</strong> the rasters with the sampling windows<br />

(SELECT t.id, t.geom, r.image_id as rid<br />

FROM spain_images r, sampling_win t<br />

WHERE sdo_geom.sdo_intersection(r.image.spatialExtent, t.geom, 0.005) is not null)<br />

END;<br />

Intersecting in <strong>PostGIS</strong> <strong>Raster</strong><br />

<strong>PostGIS</strong> <strong>Raster</strong> uses st_intersection() and st_intersects() functions, that operate directly<br />

on raster and vector data, to calculate the intersection. Be<strong>for</strong>e doing the intersection, the<br />

st_intersects() will check which portion <strong>of</strong> raster is intesected by vector. So the st_intersection()<br />

intersects vector with raster by vectorizing only the necessary part <strong>of</strong> the raster [8]:<br />

CREATE TABLE vector_srtm_inter AS<br />

SELECT id, (gv).geom AS the_geom, (gv).val<br />

FROM ( SELECT id, ST_Intersection(rast, the_geom) AS gv<br />

FROM srtm_tiled, vector_data<br />

WHERE ST_Intersects(rast, the_geom)<br />

) inter;<br />

2 http://docs.oracle.com/cd/B28359_01/appdev.111/b28398/geor_ref.htm#CHEDCICI.<br />

25

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

Saved successfully!

Ooh no, something went wrong!