[SciPy-User] ROI, the sequel
Pinner, Luke
Luke.Pinner at environment.gov.au
Tue Aug 3 23:07:11 EDT 2010
GDAL/OGR perhaps? www.gdal.org
Some semi-pseudo code below.
from osgeo import gdal,gdal_array,ogr
import numpy
# Open a polygon layer to rasterize from.
poly_ds = ogr.Open( some file dataset ) #Can also create an in-memory poly layer from scratch
poly_lyr=poly_ds.GetLayer(0)
# Create an in-memory raster to rasterize into
target_ds = gdal.GetDriverByName('MEM').Create( approriate args...)
#Rasterize...
gdal.RasterizeLayer( appropriate args... )
numpy_array = gdal_aray.DatasetReadAsArray(target_ds)
Then use the numpy_array as you lie.
Luke
-----Original Message-----
From: scipy-user-bounces at scipy.org [mailto:scipy-user-bounces at scipy.org] On Behalf Of Thøger Emil Juul Thorsen
Sent: Wednesday, 4 August 2010 10:05 AM
To: scipy-user at scipy.org
Subject: [SciPy-User] ROI, the sequel
Hello list;
I need a tool for polygon clipping of 2d NumPy arrays, but I cannot seem
to find anything. Shapely will only export the vertices of the polygon.
NXutils and patches in matplotlib seem to be purely visual, in any case
I cannot see how they would be saved as arrays in data coordinates.
There is a very neat IDL routine, POYFILLV which returns a 1d array of
the (1d) indices of the pixels that are inside the polygon, sort of like
a "where" function. Is there anything like it out there for numpy
arrays?
Best;
Emil
_______________________________________________
SciPy-User mailing list
SciPy-User at scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
------
If you have received this transmission in error please notify us immediately by return e-mail and delete all copies. If this e-mail or any attachments have been sent to you in error, that error does not constitute waiver of any confidentiality, privilege or copyright in respect of information in the e-mail or attachments.
Please consider the environment before printing this email.
------
More information about the SciPy-User
mailing list