1

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?

  • gdalwarp has a "-cutline" feature to clip a raster with any ogr supported polygon. You should also add the -te option to set the output extents to match the polygon. However I don't think that gdalwarp will output to AAIGrid format directly. – Micha May 31 '13 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.