[gdal-dev] (no subject)
Discourse Maps
discoursemap at live.com
Mon Mar 1 09:21:37 EST 2010
I am simply trying to open a raster image, manipulate in NumPy and then spit
it back out in GDAL.
I am having trouble setting null data...
I tried: ds.GetRasterBand(1).SetNoDataValue( -9999 )
but nothing seems to work.
Any help is appreciated!
Below is my code:
#! /usr/bin/env python
import os, sys
use_numeric = True
try:
from osgeo import ogr, gdal
from osgeo.gdalconst import *
import numpy
os.chdir(r'L:\users\gv\numPyGDAL\ospy_data4\ospy_data4')
use_numeric = False
except ImportError:
import ogr, gdal
from gdalconst import *
import Numeric
os.chdir(r'L:\users\gv\numPyGDAL\ospy_data4\ospy_data4')
# register all of the drivers
gdal.AllRegister()
# open the image
ds = gdal.Open('sequest', GA_ReadOnly)
if ds is None:
print 'Could not open image'
sys.exit(1)
band = ds.GetRasterBand(1))# 1-based index
# read data and add the value to the string
data = band.ReadAsArray()
print data
dims = data.shape
nx=dims[1]
ny=dims[0]
nxarray=numpy.zeros(nx)
dst_format = 'HFA'
dst_datatype = gdal.GDT_Int16
dst_options = ['COMPRESS=LZW']
dst_file='sequest_final.img'
dst_xsize = nx
dst_ysize = ny
dst_nbands = 1
geoTransform = ds.GetGeoTransform()
proj = ds.GetProjection()
driver = gdal.GetDriverByName( dst_format )
dst_ds = driver.Create(dst_file, dst_xsize, dst_ysize, dst_nbands,
dst_datatype, dst_options)
for j in range(ny):
nxarray = data[j,:]
nxarray.shape = (1,nx)
print nxarray
dst_ds.GetRasterBand(1).WriteArray(nxarray,0,j)
dst_ds.SetGeoTransform(geoTransform)
dst_ds.SetProjection(proj)
dst_ds = None
_________________________________________________________________
Hotmail: Free, trusted and rich email service.
http://clk.atdmt.com/GBL/go/201469228/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20100301/0331db87/attachment.html
More information about the gdal-dev
mailing list