[gdal-dev] problem rasterizing categorical data from shapefile - 0 values at some intersections

Etienne etiennesky at yahoo.com
Fri Aug 5 11:37:54 EDT 2011


Chaitanya,


I forgot to mention that the entire shapefile (much bigger) has many more polygons with 32 possible values (land cover type), so -with isn't practical in this case.

What I meant by  'most representative value' was, to have the value which represents the dominant land cover type in the pixel, not the one which happens to be at the center of the pixel, or the last one processed in the case of an overlap.



-> I think I found a solution:  use the -at option (to eliminate the missing data problem), sampling at a higher resolution (to minimize the overlap effect), and then re-sample to the desired lower resolution.
It's not optimal but meets my needs and fixes the problem with the gaps/overlaps in the shapefile


gdal_rasterize  -tr 0.00005 0.00005  -a_nodata 255 -of GTiff  -a_srs EPSG:4618 -a "CLASSE_ID" -ot Byte -init 255 -at -l region1 region1.shp region1-2h.tif
gdalwarp  -tr 0.0005 0.0005   region1-2h.tif region1-2hl.tif


many thanks! Etienne


BTW original files are found at
http://mapas.mma.gov.br/geodados/brasil/vegetacao/vegetacao2002/cerrado/dados/shape_file/mosaicos/
link cerrado->dados->shapefiles



________________________________
From: Chaitanya kumar CH <chaitanya.ch at gmail.com>
To: Etienne <etiennesky at yahoo.com>
Cc: "gdal-dev at lists.osgeo.org" <gdal-dev at lists.osgeo.org>
Sent: Friday, August 5, 2011 9:46:03 AM
Subject: Re: [gdal-dev] problem rasterizing categorical data from shapefile - 0 values at some intersections


I suggested the -where option because your shapefile had only two features that are (almost)inverse of each other. You can select only one of them. You might want to use the -at option with this.

What do you mean by 'most representative value'?


On Fri, Aug 5, 2011 at 5:40 PM, Etienne <etiennesky at yahoo.com> wrote:

Hi and thanks!
>
>
>I set the init value to 255, and the overlapping pixels are set to that value (instead of the default of 0).  
>
>
>
>Unfortunately, using -where resulted in the same gaps not being filled, and a combination of -where and -at selects too many pixels (the borders all overlap).
>
>
>Looking more closely, it seems that the problem is almost exclusively where there are tiny gaps between the polygons.
>
>
>It seems that -at doesn't leave any gaps, although it favors the higher-index values (as they are processed later, presumably).
>I would prefer to have the most representative value, any hints?
>
>
>
>many thanks, Etienne
>
>
>
>________________________________
>From: Chaitanya kumar CH <chaitanya.ch at gmail.com>
>To: Etienne <etiennesky at yahoo.com>
>Cc: "gdal-dev at lists.osgeo.org" <gdal-dev at lists.osgeo.org>
>Sent: Friday, August 5, 2011 4:22:10 AM
>Subject: Re: [gdal-dev] problem rasterizing categorical data from shapefile - 0 values at some intersections
>
>
>
>Etienne,
>
>Rasters of type Byte cannot hold
values below 0. So, the nodata value of -1 is not practical. It's better to choose 0 or 255 depending on your data or choose a different data type.
>
>Your problem arises because the two geometries in the shapefile overlap in some places and leave some gaps between them in other places.
>Consider selecting only one feature using the -where option in gdal_rasterize. You can also use the -at option but it may not work at all resolutions.
>
>
>On Fri, Aug 5, 2011 at 7:40 AM, Etienne <etiennesky at yahoo.com> wrote:
>
>Hi all,
>>
>>I am trying to create a raster file with categorical data (land vegetation/cover positive indices) from a shapefile containing 1 layer of polygons.  
>>
>>I use the following command: 
>>gdal_rasterize  -tr 0.0005 0.0005  -a_nodata -1 -of GTiff  -a_srs EPSG:4618 -a "CLASSE_ID" -ot Byte -init -1 -l region1 region1.shp region1-3.tif
>>
>>This creates a  map which looks good, but there are some holes in the data, (individual pixels with a value of 0) at the intersection of 2 polygons. It looks like the
>>intersections pass through the exact center of these pixels. These pixels are not set to missing(-1). Depending on the output resolution, different pixels get set to a value of 0.
>>
>>Has anyone ran into this problem?  Any idea how to fix this?  
>>Those interested will find 2 small shapefiles here: http://db.tt/3X4hI45andhttp://db.tt/phqnGci
>>
>>
>>I tried using gdal_grid, but it doesn't seem to support a shapefile with POLYGONs.
>>
>>many thanks!
>>Etienne
>>
>>_______________________________________________
>>gdal-dev mailing list
>>gdal-dev at lists.osgeo.org
>>http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
>
>-- 
>Best regards,
>Chaitanya kumar CH.
>
>+91-9494447584
>17.2416N 80.1426E
>
>
>


-- 
Best regards,
Chaitanya kumar CH.

+91-9494447584
17.2416N 80.1426E



More information about the gdal-dev mailing list