[gdal-dev] OSR Python: nearest polygon distance from each point feature?

David Verbyla dlverbyla at alaska.edu
Sat Dec 22 08:17:38 PST 2012


> I am a newbie to OGR/OSR using Python 2.7.2, please excuse my ignorance:
> I am trying to find the distance to the closest polygon for each point.
> Is there a more efficient way than simply computing the distance to all
> polygons for each point?  For example:
>

nPts = pointsLayer.GetFeatureCount()
nPolys = polysLayer.GetFeatureCount()

for pt in range(0,nPts):
      minDist = 1000000
      pointFeature = pointsLayer.GetFeature(pt)
      for poly in range(0,nPolys):
            polyFeature = polysLayer.GetFeature(poly)
            Dist = pointFeature.GetGeometryRef().Distance(
polyFeature.GetGeometryRef() )
            if (Dist < minDist):
                  minDist = Dist
      print (pt,minDist)

Thank you.

Dave Verbyla
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20121222/2af2a619/attachment.html>


More information about the gdal-dev mailing list