0

I have Eastcoast.shp file and my raster input file="myrasterfinal77.tif" output file= "myrasterfinal77_out.tif"

So with respect to Eastcoast.shp shapefile i want to extract same polygon image from my myrasterfinal77.tif input file and generate a output file "myrasterfinal77_out.tif"

Error Message i am getting 
    gdalwarp -cutline "Eastcoast.shp" -crop_to_cutline -dstnodata "-9999.0" "myrasterfinal77.tif" "myrasterfinal77_out.tif"
                                    ^
SyntaxError: invalid syntax

For that i am using gdalwarp but i am getting syntax Error.

gdalwarp -cutline "Eastcoast.shp" -crop_to_cutline -dstnodata "-9999.0" "myrasterfinal77.tif" "myrasterfinal77_out.tif"

Below is my myrasterfinal77.tif image enter image description here

Below is my shapefile plot image.
enter image description here

So i want same latitude longitude polygon raster tiff image to generate outside polygon nodata. I want only the polygon area.

Error Message i am getting is below :-

binzo
  • 1,527
  • 1
  • 3
  • 13
Sameer Rai
  • 21
  • 2
  • Any suggestion for above question? – Sameer Rai Oct 21 '20 at 08:45
  • If you can show an error message when executing the command, it will help to get an answer. – binzo Oct 22 '20 at 03:13
  • @binzo gdalwarp -cutline "Eastcoast.shp" -crop_to_cutline -dstnodata "-9999.0" "myrasterfinal77.tif" "myrasterfinal77_out.tif" ^ SyntaxError: invalid syntax – Sameer Rai Oct 22 '20 at 04:41
  • The error message "SyntaxError: ..." is from Python, not from gdalwarp. You may find the following link to be helpful on how to invoke the gdal command from Python. [https://gis.stackexchange.com/questions/178048/gdal-translate-error](https://gis.stackexchange.com/questions/178048/gdal-translate-error) – binzo Oct 22 '20 at 06:15
  • @binzo, Thanks for suggestion As per the provided link i modified my code, now i am getting 1 as an output , import os os.system("gdalwarp -cutline 'Eastcoast.shp' -crop_to_cutline -dstnodata '-9999.0' " + "myrasterfinal77.tif" + " " + "myrasterfinal77_out.tif") – Sameer Rai Oct 22 '20 at 07:07
  • The output of 1 is the return value of the python function os.system, indicating that the gdalwarp command is failing for some reason. If you can run the gdalwarp command on the command line, I suggest you run it and check the error messages from gdalwarp. – binzo Oct 22 '20 at 07:36

0 Answers0