2

I have 70 raster landsat images with srid: 32647,32648,32649 and want to clip raster to polygon (shapefile, srid: 4326) in postgis.

I imported all raster into 1 table with parameter -s : 32648, transform srid of shapefile to 32648 but the result is not as I expected ( only overlap 40% the polygon)

So How can I fix that problem ?

2

Assuming you used raster2pgsql to import the data, -sis NOT the right option to reproject the data into one single CRS.

You have assigned a new srid, but not recalculated the coordinates: http://postgis.net/docs/manual-2.2/using_raster_dataman.html

Instead, use gdalwarp -s_srs old_srs -t_srs new_srs srcfile destfile to reproject two of your rasters to the CRS of the third. Then you can import all of them into one table.

  • is there anyway to do it fast ? becasue it's long to do it file by file – kzempty Nov 2 '15 at 11:14
  • 1
    Surely. On Wndows: for %%N in (*.tif) DO gdalwarp -of vrt -s_srs ... -t_srs ... %%N D:\Karten\gdal\%%~nN.vrt. Linux and Mac might have a different syntax for the loop. – AndreJ Nov 2 '15 at 12:05
  • I tried and got this error : ERROR: rt_raster_from_two_rasters: The two rasters provided do not have the same alignment SQL state: XX000 – kzempty Nov 2 '15 at 16:46
  • Did you get the error executing gdalwarp or when importing into Postgis? – AndreJ Nov 3 '15 at 4:48
  • Hi Andre, both command are fine. I get error when run st_clip() and st_union() query – kzempty Nov 3 '15 at 7:50
0

Try importing your rasters without the -s option. raster2pgsql should automatically assign them the right SRID. You can check after the load is complete with ST_SRID(rast). Once they are imported with their own right SRID, you just have to ST_Transform(geom, ST_SRID(rast)) the polygon before cliping.

If in any case the importer do not assign each raster it's proper SRID you can reassign them with ST_SetSRID().

  • I think it's not solution because I tried it and get another error: invalid memory alloc request size – kzempty Nov 3 '15 at 7:57
  • 1
    How big are your rasters in term of memory? – Pierre Racine Nov 3 '15 at 14:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.