Discussion:
[gdal-dev] gdal_translate clip PostGIS raster
Andreas Oxenstierna
2021-05-10 17:23:33 UTC
Permalink
Hi list

Is it possible to clip a PostGIS raster with a PostGIS vector poly using gdal_translate?

I cannot find a working syntax to define the clipping table in the WHERE clause.
Eg. this returns "Error browsing database for PostGIS Raster properties : ERROR: syntax error at or near "FROM"

gdal_translate -of GTiff "PG:<connectinfo> schema=a table=rastertable WHERE='ST_Intersects(rast,c.geom) AND c.id<http://c.id> = 2 FROM a.vectortable c'" a.tif

Best regards

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>
Even Rouault
2021-05-10 17:31:34 UTC
Permalink
Try with gdalwarp and the -cutline family of arguments
Post by Andreas Oxenstierna
Hi list
Is it possible to clip a PostGIS raster with a PostGIS vector poly using gdal_translate?
I cannot find a working syntax to define the clipping table in the WHERE clause.
Eg. this returns "Error browsing database for PostGIS Raster
properties : ERROR:  syntax error at or near "FROM"
gdal_translate -of GTiff "PG:<connectinfo> schema=a table=rastertable
WHERE='ST_Intersects(rast,c.geom) AND c.id <http://c.id> = 2 FROM
a.vectortable c'" a.tif
Best regards
Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
www.t-kartor.com <http://www.t-kartor.com>
_______________________________________________
gdal-dev mailing list
https://lists.osgeo.org/mailman/listinfo/gdal-dev
--
http://www.spatialys.com
My software is free, but my time generally not.
Andreas Oxenstierna
2021-05-11 06:48:35 UTC
Permalink
Thanks

but still stumbling (using 2.3.2)
gdalwarp -cutline "PG:dbname=gisdb" -csql 'select * from polytest where id=1' -crop_to_cutline -of GTiff -srcnodata -9999 -dstnodata -9999 "PG:<connectinfo> schema=a table=rastertable" dest.tif

returns:
ERROR 1: Input file <rastertable> has no raster bands.

gdalinfo reports that the table is tiled in 360 pieces which potentially is the source for the issue:
Subdatasets:
SUBDATASET_1_NAME=PG:host=

SUBDATASET_360_DESC=PostGIS Raster at

HÀlsningar

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>
On 10 May 2021, 19:31 +0200, Even Rouault <***@spatialys.com>, wrote:

Try with gdalwarp and the -cutline family of arguments

Le 10/05/2021 à 19:23, Andreas Oxenstierna a écrit :
Hi list

Is it possible to clip a PostGIS raster with a PostGIS vector poly using gdal_translate?

I cannot find a working syntax to define the clipping table in the WHERE clause.
Eg. this returns "Error browsing database for PostGIS Raster properties : ERROR: syntax error at or near "FROM"

gdal_translate -of GTiff "PG:<connectinfo> schema=a table=rastertable WHERE='ST_Intersects(rast,c.geom) AND c.id<http://c.id> = 2 FROM a.vectortable c'" a.tif

Best regards

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>



_______________________________________________
gdal-dev mailing list
gdal-***@lists.osgeo.org<mailto:gdal-***@lists.osgeo.org>
https://lists.osgeo.org/mailman/listinfo/gdal-dev
--
http://www.spatialys.com
My software is free, but my time generally not.
Andreas Oxenstierna
2021-05-12 06:11:54 UTC
Permalink
Tested with:
1 
 table=rastertable WHERE=rid>0" dest.tif
Returns:
WHERE=rid>0 has no raster bands

2 
 table=rastertable WHERE=rid=1" dest.tif
Returns:
a valid but empty tif file

3 
 table=<view based on the rastertable" dest.tif
Returns:
... has no raster bands

gdalwarp seems to treat PostGIS raster tables as one subdataset for each tile. Basically make them useless in my mind - or have I missed something essential/simple ?


HÀlsningar

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>
On 11 May 2021, 08:48 +0200, Andreas Oxenstierna <***@t-kartor.com>, wrote:
Thanks

but still stumbling (using 2.3.2)
gdalwarp -cutline "PG:dbname=gisdb" -csql 'select * from polytest where id=1' -crop_to_cutline -of GTiff -srcnodata -9999 -dstnodata -9999 "PG:<connectinfo> schema=a table=rastertable" dest.tif

returns:
ERROR 1: Input file <rastertable> has no raster bands.

gdalinfo reports that the table is tiled in 360 pieces which potentially is the source for the issue:
Subdatasets:
SUBDATASET_1_NAME=PG:host=

SUBDATASET_360_DESC=PostGIS Raster at

HÀlsningar

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>
On 10 May 2021, 19:31 +0200, Even Rouault <***@spatialys.com>, wrote:

Try with gdalwarp and the -cutline family of arguments

Le 10/05/2021 à 19:23, Andreas Oxenstierna a écrit :
Hi list

Is it possible to clip a PostGIS raster with a PostGIS vector poly using gdal_translate?

I cannot find a working syntax to define the clipping table in the WHERE clause.
Eg. this returns "Error browsing database for PostGIS Raster properties : ERROR: syntax error at or near "FROM"

gdal_translate -of GTiff "PG:<connectinfo> schema=a table=rastertable WHERE='ST_Intersects(rast,c.geom) AND c.id<http://c.id> = 2 FROM a.vectortable c'" a.tif

Best regards

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>



_______________________________________________
gdal-dev mailing list
gdal-***@lists.osgeo.org<mailto:gdal-***@lists.osgeo.org>
https://lists.osgeo.org/mailman/listinfo/gdal-dev
--
http://www.spatialys.com
My software is free, but my time generally not.
Andreas Oxenstierna
2021-05-14 06:42:57 UTC
Permalink
I had missed something essential and simple ...
mode=2 must be added to the end of the PG connection string to tell GDAL to treat a PostGIS raster table as one unit.
The default mode=1 treats each tile as a subdataset

Sorry for the noise

Best regards

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>
On 12 May 2021, 08:12 +0200, Andreas Oxenstierna <***@t-kartor.com>, wrote:
Tested with:
1 
 table=rastertable WHERE=rid>0" dest.tif
Returns:
WHERE=rid>0 has no raster bands

2 
 table=rastertable WHERE=rid=1" dest.tif
Returns:
a valid but empty tif file

3 
 table=<view based on the rastertable" dest.tif
Returns:
... has no raster bands

gdalwarp seems to treat PostGIS raster tables as one subdataset for each tile. Basically make them useless in my mind - or have I missed something essential/simple ?


HÀlsningar

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>
On 11 May 2021, 08:48 +0200, Andreas Oxenstierna <***@t-kartor.com>, wrote:
Thanks

but still stumbling (using 2.3.2)
gdalwarp -cutline "PG:dbname=gisdb" -csql 'select * from polytest where id=1' -crop_to_cutline -of GTiff -srcnodata -9999 -dstnodata -9999 "PG:<connectinfo> schema=a table=rastertable" dest.tif

returns:
ERROR 1: Input file <rastertable> has no raster bands.

gdalinfo reports that the table is tiled in 360 pieces which potentially is the source for the issue:
Subdatasets:
SUBDATASET_1_NAME=PG:host=

SUBDATASET_360_DESC=PostGIS Raster at

HÀlsningar

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>
On 10 May 2021, 19:31 +0200, Even Rouault <***@spatialys.com>, wrote:

Try with gdalwarp and the -cutline family of arguments

Le 10/05/2021 à 19:23, Andreas Oxenstierna a écrit :
Hi list

Is it possible to clip a PostGIS raster with a PostGIS vector poly using gdal_translate?

I cannot find a working syntax to define the clipping table in the WHERE clause.
Eg. this returns "Error browsing database for PostGIS Raster properties : ERROR: syntax error at or near "FROM"

gdal_translate -of GTiff "PG:<connectinfo> schema=a table=rastertable WHERE='ST_Intersects(rast,c.geom) AND c.id<http://c.id> = 2 FROM a.vectortable c'" a.tif

Best regards

Andreas Oxenstierna
T-Kartor Geospatial AB
Olof Mohlins vÀg 12 Kristianstad
mobile: +46 733 206831
mailto: ***@t-kartor.com<mailto:***@t-kartor.com>
www.t-kartor.com<http://www.t-kartor.com>



_______________________________________________
gdal-dev mailing list
gdal-***@lists.osgeo.org<mailto:gdal-***@lists.osgeo.org>
https://lists.osgeo.org/mailman/listinfo/gdal-dev
--
http://www.spatialys.com
My software is free, but my time generally not.
Loading...