2

I have four band .tif that I am trying to clip to the shapefile extent with:

gdal.Warp(OutDS, inRaster, cutlineDSName = InShapefile1, cropToCutline = True, dstNodata = inNoData)

using Python and GDAL I first open the raster and then try to clip it band by band. The result has only zeros. Clipping shapefile has only one polygon geometry but it is possible that it extends out of raster's bounds in some cases. I've tried to perform clip with color composite but result is the same. Also the output single band rasters are read by, for example, ArcMap as multiband composites.

The link to the sample data is here: https://dl.dropboxusercontent.com/u/83030488/Tiff/Sent10.rar

UPDATE

By implementing the subprocess, call method I managed to identify the error. The problem was that I did not have the system veriable GDAL_DATA set correctly.

Now another error came out:

ERROR 4: `EPSG:3912' does not exist in the file system, and is not recognized as a supported dataset name.

I am calling gdalwarp with:

path= str(outClipedRasterPath)
os.chdir(path)
cmd = 'gdalwarp -dstnodata -9999 -cutline -s_srs EPSG:3912 -t_srs EPSG:3912 ' + InShapefile1 + ' -crop_to_cutline -of GTiff ' + inRaster + OutDS
call(cmd)
  • You need to make sure that both raster (.tif) image and the shapefile have the same projection. – ahmadhanb Mar 6 '17 at 12:48
  • They do have the same projection. – Alešinar Mar 6 '17 at 12:54
  • Give us some simplified test data to play with. – user30184 Mar 6 '17 at 13:23
0

The problem was solved by dropping the EPSG codes as they were not needed since no reprojection actually took place, also the code above lacked one 'space' added between inRaster + OutDS as whole command is a string. The code is now updated.

In any case the ERROR 4: `EPSG:3912' does not exist in the file system, and is not recognized as a supported dataset name. is wierd as pcs.csv contains it.

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.