My objective is to clip a polygon from PostGIS raster table, and then save this raster (draw polygon shape) as an ASC-II in a folder. What I did now are 2 steps.
1st Step: Insert the clipped raster into another raster table using Pgresql in PHP:
$preparedQuery = "INSERT INTO rastertable(rast) (SELECT ST_Clip(rast,1,geometry) FROM dtm, polygons WHERE polygons.polygonid = ?);"; $sth = $dbh2->prepare($preparedQuery); $sth->execute(array( $geoid ));
2nd Step: Retrieve the raster data from this table using PostGIS dumper:
gdal_translate -of AAIGrid "PG:host=localhost port= dbname='' user='' password='' schema='' table='rastertable' where='rid=1'" postgis.asc ;
How can I combine these two processes? I mean, can I get the raster file directly without inserting to and retrieving from the raster table?