[Numpy-discussion] how to tell if a point is inside a polygon
Pierre GM
pgmdevlist@gmail....
Mon Oct 13 18:46:01 CDT 2008
> 2008/10/13 Mathew Yeates <myeates@jpl.nasa.gov>
>
> > Is there a routine in scipy for telling whether a point is inside a
> > convex 4 sided polygon?
Mathew,
You could use OGR (www.gdal.org)
Example
-------------
import osgeo.ogr as ogr
vert = [(0,0),(0,1),(1,1),(1,0)]
listvert = [" %s %s" % (x,y) for (x,y) in vert]
listvert.append(listvert[0])
geo = ogr.CreateGeometryFromWkt("POLYGON ((%s))" % ','.join(listvert))
querypoint = (0.5, 0.5)
qpt = ogr.CreateGeometryFromWkt("POINT(%s %s)" % querypoint)
assert geo.Contains(qpt)
querypoint = (0.5, 1.5)
qpt = ogr.CreateGeometryFromWkt("POINT(%s %s)" % querypoint)
assert not geo.Contains(qpt)
More information about the Numpy-discussion
mailing list