Have you looked at http://www.gdal.org/gdal_tutorial.html?

Attached is a Python code snippet that shows how to assign values to pixels
in an image. To do what you're asking, you need to create the output raster,
and then write out the values in your array into the correct pixel position.

I assume that you need to modify the values in the DEM, and not just simply
convert the image from one format to another?

Roger
--

2010/4/5 weixj2003ld <weixj200...@163.com>

> Now,I can read data from a DEM file into an array,but I do not know how to
> use it to create a png file?
> Thk u.
> BTW,Some one tell me that freeimage can do it,but  I do not know.
>
>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
#! /usr/bin/env python

"""Create an image with gdal using hard-coded georeferencing and extents.

 tile_span = 5_deg x 5_deg
    x_span = 300 pixels
    y_span = 300 pixels
pixel_size = .01666666
ul_x = -60
ul_y = -5
"""

import gdal
import Numeric

# .GetDriverByName(gdal_format)
# .create(filename, x_span, y_span, bands, data_type)
# .SetGeoTransform([ul_x, pixel_x, rotation_x, ul_y, rotation_y, pixel_y]) 

out_drv = gdal.GetDriverByName('GTiff')
out_ds = out_drv.Create('step1.tif', 300, 300 , 1, gdal.GDT_Byte)
out_ds.SetGeoTransform([-60, .01666666, 0, -5, 0, -.01666666])
out_band = Numeric.zeros([out_ds.RasterYSize, out_ds.RasterXSize])

# walk through the arrays and assign a value for each pixel
for iY in range(out_ds.RasterYSize):
  for iX in range(out_ds.RasterXSize):
    out_band[iY][iX] = 0
  
out_ds.GetRasterBand(1).WriteArray(out_band)

out_ds = None
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to