[gdal-dev] Re: Convert vector to raster with colored polygons
spiderplant0
spiderplant0 at gmail.com
Fri May 27 18:15:00 EDT 2011
Thanks Chaitanya, that worked perfectly.
In case anyone else has this problem here are the full list of command I
used...
First need to get GDAL 1.8 + as gdal_rasterize in GDAL 1.7 wont work.
You can get it here...
http://vbkto.dyndns.org/sdk/
Convert your vector to a greyscale .tiff
(When I viewed this in IrfanViewer or ER Viewer all I see is a black image
so you cant tell if its working at this stage.)
gdal_rasterize -ot Byte -init 0 -ts <widthInPixels> <heightInPixels> -a
<attributeName> -l <layerName> <vectorFile>.shp <rasterFile>.tiff
Add a .vrt wrapper...
gdalbuildvrt -overwrite -srcnodata 0 <rasterFile>.vrt <rasterFile>.tiff
Now edit the .vrt replacing the line ...
<ColorInterp>Gray</ColorInterp>
with something like (edit the number of 'Entry' rows and color values as
required) ...
<ColorInterp>Palette</ColorInterp>
<ColorTable>
<Entry c1="0" c2="0" c3="0" c4="0" />
<Entry c1="255" c2="255" c3="0" c4="255" />
<Entry c1="0" c2="255" c3="0" c4="255" />
<Entry c1="0" c2="255" c3="255" c4="255" />
<Entry c1="0" c2="0" c3="255" c4="255" />
</ColorTable>
The first line corresponds to attribute value = 0, the second to attribute
value 1,
'c4' is the transparency. So line 0 is fully transparent.
Convert .VRT into a full-color .tiff
(You should now see the image correctly in IrFan Viewer.)
gdal_translate -expand rgba <rasterFile>.vrt <newRasterFile>.tiff
For some reason not all GDAL programs are available in all packages, so for
the next step you might need to switch over to the OSGeo4W GDAL package to
convert to google-maps tiles...
gdal2tiles -r near -z0-12 --s_srs <EpsgMapProjection> <newRasterFile>.tiff
./tiles
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Convert-vector-to-raster-with-colored-polygons-tp6396185p6412737.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
More information about the gdal-dev
mailing list