[gdal-dev] Cropping a raster by a polygon - only nodata outside polygon wanted

Even Rouault even.rouault at spatialys.com
Wed Jan 14 02:39:21 PST 2015


Mathieu,

If 0 is a valid value at some locations of your raster, then you cannot use it
as the nodata value. Use an alpha band instead for example by using -dstalpha
instead of -dstnodata 0

Even

> Hello,
>
> I crop a 3 band raster by a polygon with the following formula :
> /gdalwarp -of GTiff -cutline polygon.shp -cl polygon input.tif output.tif
> /
> But pixels outside my polygon are assigned the 0 value. I'd like them to
> have nodata
>
> If I put the -dstnodata 0 option :
> /gdalwarp -of GTiff -cutline polygon.shp -cl polygon input.tif output.tif
> -dstnodata 0/, all the pixels in each of the 3 bands that contain the 0
> value will be turned to nodata, even if they are contained in my polygon.
>
> Hence, 127 0 222 will become 127 nodata 222
> or 0 127 222 will become nodata 127 222
>
> How to put the nodata value only outside my polygon ?
>
> Thanks a lot in advance !
>
> Mathieu
>
>
>
> --
> View this message in context:
>
http://osgeo-org.1560.x6.nabble.com/Cropping-a-raster-by-a-polygon-only-nodata-outside-polygon-wanted-tp5181426.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>


-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list