Subject: Marine Geospatial Ecology Tools (MGET) help
Text archives
From: | "Jason Roberts" <> |
---|---|
To: | <> |
Subject: | [mget-help] RE: Raster processing in Python |
Date: | Wed, 29 Apr 2009 10:29:18 -0400 |
Hi Lennert, It is possible to work with Arc rasters as numpy arrays. MGET
does this frequently. I recommend the GDAL package; see http://www.gdal.org. The code will ultimately
look similar to this: import gdal, gdalconst dataset = gdal.Open(pathToRaster, gdalconst.GA_ReadOnly) band = dataset.GetRasterBand(1) data =
"band.ReadAsArray() " # data is a
numpy array noDataValue = band.GetNoDataValue() # always
returns a float, even for integer rasters Alternatively, you could use MGET to do it: from GeoEco.DataManagement.ArcGISRasters import ArcGISRaster data, noDataValue = ArcGISRaster.ToNumpyArray(pathToRaster) The MGET function wraps GDAL code similar to what I show above
and performs some additional services: ·
It can read rasters from geodatabases (GDAL only reads from
rasters on disk) ·
It returns a numpy array that uses the most compact data type to
represent the data (ArcGIS and GDAL occasionally select sub-optimal data types) ·
It returns an int NoData value for integer rasters (GDAL always
returns a float, even for integer rasters) For more on MGET's Python functions, view the GeoEco Python
Reference under the Marine Geospatial Ecology Tools folder in your Start menu.
In that Reference, click GeoEco Module Index and then click
GeoEco.DataManagment.ArcGISRasters, and drill in until you find the appropriate
function. The choice of whether to use GDAL or MGET is up to you. If you
are writing a tool that you plan to redistribute to others, you may prefer to
use GDAL because it is lighter weight than MGET and has an MIT license (less
restrictive than MGET's GPL). If you prefer to keep your code compact and like
the additional services provided by MGET, you might prefer it instead. GDAL does not allow you to write rasters, at least not in the
traditional ArcInfo Binary Grid format or to geodatabases. It can write rasters
in many other formats, such as ArcInfo ASCII Grid, GeoTIF, Erdas IMAGINE
(.img). To write ArcInfo Binary Grids or to geodatabases, you can use the MGET
ArcGISRaster.FromNumpyArray function. See the documentation I referenced above
for more info. Others will probably be interested in this answer. Do you mind
if I forward this to the mget-help list? (Note: This will cause the message to
be archived on our server for others to view. It will include your email
address. I can redact that if you like.) Jason From: Lennert Tyberghein Sent: Wednesday, April
29, 2009 5:20 AM Hi Jason, |