Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to set to novalue all the pixels of my raster inside a polygon. enter image description here

I'm trying the gdalwarp command line with -cutline option. But this command extract the values of my raster inside the polygone (shapefile).

Raster and vector dataset's are both in the same projection. What coud be the next steps ? If this is the right track, is it possible to script the "raster calculator" plugins ? Thank you in advance

share|improve this question

2 Answers 2

Thank your for your help.

This is an important feature for me. I am not sure it was clear on my example, but I am trying to remove data "on land" from my offshore raster ! Given your comments, I have been looking for a shapefile delimiting oceans. NaturalEarth provides me with a very good dataset which fulfilled my needs.(10mphysical/10m_ocean.shp) Here is the image of the 3 layers : the ocean, my initial dataset and the 3 layers However the extracted dataset do not keep track of the metadata !! H0:bathymetry became 'Band1'.

Do you know a way to bypass those modification? gdalinfo on first dataset :

Band 1 Block=345x1 Type=Float32, ColorInterp=Undefined
  NoData Value=-32768
  Metadata:
    _FillValue=-32768
    coordinates=lon lat
    grid_mapping=crs
    long_name=bathymetry relative to the mean level
    NETCDF_VARNAME=H0
    standard_name=model_sea_floor_depth_below_geoid
    units=m
    valid_max=10000
    valid_min=-10000

gdalinfo on second dataset :

Band 1 Block=345x1 Type=Float32, ColorInterp=Undefined
  NoData Value=-32768
  Metadata:
    _FillValue=-32768
    coordinates=lon lat
    grid_mapping=crs
    long_name=GDAL Band Number 1
    NETCDF_VARNAME=Band1
share|improve this answer

Cutline does the exact opposite of what you are trying to do. If you use cutline with gdalwarp, it should crop your raster to the area INSIDE the polygon and set everything outside to no data (see below):

before after

I don't know why nothing happened in your case (perhaps you forgot to specify the cutline layer option -cl - who knows).

To do what you want there are several ways of going about it. One would be to create a polygon with the same extent as your raster and then calculate the difference of that polygon with your desired polygons. This will effectively give you a new polygon which is the area you want to keep. You can then use that as your cutline.

An alternative is to rasterize your polygons with the same resolution as your existing raster using gdal_rasterize, but set the -burn value to be the same as your NoData value (which you can also specify) and your -init value to be 1. You can then simply multiply your new raster with the existing one.

share|improve this answer
    
thank your very much for your answer. After I spend more time with my output raster, I realised exactly what your just say : gdalwrap does exactly the opposite of what I am looking for. Your first option seems easier to me. Could you tell me which command can I use to <b> calculate the difference of that polygon</b> –  Renaud Nov 19 '12 at 19:14
    
Unfortunately there isn't a commandline OGR Utility for this. The easiest way to get the difference is to do it in QGIS because there is a function already built in to the Vector tools to do this. Otherwise if your data are in a spatial database like PostGIs you can use the ST_Difference function in an SQL command. Failing that you will need to write a Python script to call the OGR API. –  MappaGnosis Nov 19 '12 at 19:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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