The closest thing you can do without doing any coding is to use the gdal_contour utility[1] to create a vector file and then use gdal_rasterize [2] to burn them back to a raster. If you use appropriate options, all your pixels will be clamped to the discrete levels used in gdal_contour. It's straight forward to apply a color table to that.<br>
<br>If you want to do this using a script, refer to the gdal API tutorial[3]. You'll have to do the classification while you read and write the pixels using GDALRasterIO(). You can set the color table too.<br><br>Note that there may be some differences along the edges of classified pixels between these two methods. The lines generated by gdal_contour may go through the area of a pixel and could change the burn value.<br>
<br>[1]: <a href="http://www.gdal.org/gdal_contour.html">http://www.gdal.org/gdal_contour.html</a><br>[2]: <a href="http://www.gdal.org/gdal_rasterize.html">http://www.gdal.org/gdal_rasterize.html</a><br>[3]: <a href="http://www.gdal.org/gdal_tutorial.html">http://www.gdal.org/gdal_tutorial.html</a><br>
<br><div class="gmail_quote">On Fri, Jul 29, 2011 at 12:05 AM, Stephen Crawford <span dir="ltr"><<a href="mailto:src176@psu.edu">src176@psu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<u></u>
<div bgcolor="#ffffff" text="#000000">
Thanks for the reply. I had looked at these before, and then looked
again after your note, but I just don't understand how I map the
climate variable values to different colors in the palette, along
the lines of:<br>
<br>
tmax < 30 | color1<br>
30 < tmax < 50 | color2<br>
tmax > 50 | color3<br>
<br>
Thanks,<br>
Steve<div><div></div><div class="h5"><br>
<br>
On 7/27/2011 1:01 AM, Chaitanya kumar CH wrote:
<blockquote type="cite">Sorry, here are the links.<br>
<br>
[1]: <a href="http://www.gdal.org/rgb2pct.html" target="_blank">http://www.gdal.org/rgb2pct.html</a><br>
<br>
[2]: <a href="http://www.gdal.org/gdal_vrttut.html" target="_blank">http://www.gdal.org/gdal_vrttut.html</a><br>
[3]: <a href="http://www.gdal.org/formats_list.html" target="_blank">http://www.gdal.org/formats_list.html</a><br>
<br>
<div class="gmail_quote">On Wed, Jul 27, 2011 at 10:30 AM,
Chaitanya kumar CH <span dir="ltr"><<a href="http://chaitanya.ch" target="_blank">chaitanya.ch</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Stephen,<br>
<br>
The docs for rgb2pct.py script [1] has an example that shows
how to convert to a paletted image using hand made VRT file.<br>
You can use the "-of PNG" option to set the destination format
as png and the -pct option with your VRT file.
<div>
<div><br>
<br>
<div class="gmail_quote">On Wed, Jul 27, 2011 at 2:42 AM,
Stephen Crawford <span dir="ltr"><<a href="mailto:src176@psu.edu" target="_blank">src176@psu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi All,<br>
<br>
I have 60 or so asciiGrids of climate data that I
would like to tun into PNGs, with the climate values
classified by color. I would like to script this
process using Python. Is there a way to do this with
GDAL? Or if not, is there any other open source way
to do this?<br>
<br>
Thanks,<br>
Steve<br>
<br>
<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote>
</div>
<br>
<br clear="all">
<br>
</div>
</div>
<font color="#888888">-- <br>
Best regards,<br>
Chaitanya kumar CH.<br>
<br>
+91-9494447584<br>
17.2416N 80.1426E<br>
</font></blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
Best regards,<br>
Chaitanya kumar CH.<br>
<br>
+91-9494447584<br>
17.2416N 80.1426E<br>
</blockquote>
<br>
</div></div><font color="#888888"><pre cols="72">--
Stephen Crawford
Center for Environmental Informatics
The Pennsylvania State University
<a href="mailto:src176@psu.edu" target="_blank">src176@psu.edu</a>
814.865.9905</pre>
</font></div>
</blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br><br>+91-9494447584<br>17.2416N 80.1426E<br>