When I use:
gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 255 -burn 255 polygon.shp tiff.tiff
I get a new tiff with a white hole in it with the shape of the polygon shp. However, when I use the reverse
process:
gdal_rasterize -i -b 1 -b 2 -b 3 -burn 255 -burn 255 -burn 255 polygon.shp tiff.tiff
I get a blank tiff. I expect the old tiff shaped by the polygon (ie. raster values inside the polygon), instead.
Any ideas why this happens? is it possible to clip a raster with a shapefile in this way?
Answer
I took one png file from the data_dir of GeoServer. Install GeoServer and you will have the same image to play with in directory:
\geoserver-2.7.1\data_dir\coverages\mosaic_sample\
Convert png into tiff and assign projection.
gdal_translate -a_srs epsg:4326 global_mosaic_6.png tiff.tiff
Input file size is 50, 50
0...10...20...30...40...50...60...70...80...90...100 - done.
Then burn:
gdal_rasterize -i -b 1 -b 2 -b 3 -burn 255 -burn 255 -burn 255 burn.shp tiff.tiff
Warning : the output raster dataset has a SRS, but the input vector layer SRS is unknown. Ensure input vector has the same SRS, otherwise results might be incorrect.
0...10...20...30...40...50...60...70...80...90...100 - done.
Burn.shp contains one polygon:
POLYGON (( 10.375610236185853 39.384332051098106, 10.344426149120759 39.730475417520644, 10.87455562922735 39.92069834861771, 11.152094004106685 39.546489303836594, 10.92133175982499 39.16292503293594, 10.375610236185853 39.384332051098106 ))
And the result is this:
As a comparison the result without using the -i option
No comments:
Post a Comment