[gdal-dev] Python ogr DataSource.ExecuteSQL syntax?

David Verbyla dlverbyla at alaska.edu
Mon Feb 4 19:32:11 PST 2013


I am trying to figure out the syntax for .ExecuteSQL using Python ogr.

For example:
fireLayer.SetAttributeFilter(None) #returns all 2623 polygons
fireLayer.SetAttributeFilter(" FIREID < 75 ") #returns 4 polygons

I am trying to get the same results using the ExecuteSQL:
testLayer = dataSource.ExecuteSQL("select * from fireLayer")
type(testLayer) #retuns NoneType
testLayer = dataSource.ExecuteSQL("select * from fireLayer where FIREID <
75")
type(testLayer) #retuns NoneType

Thanks in advance.

Dave Verbyla

On Sat, Dec 22, 2012 at 7:17 AM, David Verbyla <dlverbyla at alaska.edu> wrote:

>
> 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/20130204/52f1ac05/attachment.html>


More information about the gdal-dev mailing list