<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
Strangely enough, ExecuteSQL works (it returns an osgeo.ogr.layer object with one feature) with<br>
<br>
'select FID from judeteEPSG3844 where DENJUD = "CLUJ"'<br>
<br>
but later a GetField('FID') request returns "Illegal field requested in GetField()"<br>
<br>
-marius<br>
<br><br><div><hr id="stopSpelling">Date: Tue, 12 Jul 2011 11:36:42 -0400<br>Subject: Re: [gdal-dev] OGR Geometry methods<br>From: luke.peterson@gmail.com<br>To: mariusjigmond@hotmail.com<br><br>does executing<div><br></div><div>sql = 'select FID from judeteEPSG3844 where DENJUD = "CLUJ"'</div><div><br></div><div>return anything?<br clear="all">-----<br>Luke Peterson<br>312-533-1051(m)<br>
<br><br><div class="ecxgmail_quote">On Tue, Jul 12, 2011 at 11:30 AM, Marius Jigmond <span dir="ltr">&lt;<a href="mailto:mariusjigmond@hotmail.com">mariusjigmond@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex">




<div><div dir="ltr">
Luke,<br>
<br>
GetFIDColumn returns an empty string (not supported according to the docs). I tried the following SQL statement:<br>
sql = 'select DENJUD from judeteEPSG3844 where DENJUD = "CLUJ"'<br>
but it's still returning that same wrong feature.<br><font color="#888888">
<br>
-marius<br>
</font><div class="ecxhm"><br><br></div><div><div class="ecxhm"><hr>Date: Tue, 12 Jul 2011 09:13:00 -0400<br>Subject: Re: [gdal-dev] OGR Geometry methods<br>From: <a href="mailto:luke.peterson@gmail.com">luke.peterson@gmail.com</a><br>
To: <a href="mailto:mariusjigmond@hotmail.com">mariusjigmond@hotmail.com</a></div><div><div></div><div class="h5"><br><br><br>
-----<br>
Luke Peterson<br>
- sent via mobile device -<br>
On Jul 11, 2011 11:00 PM, "Marius Jigmond" &lt;<a href="mailto:mariusjigmond@hotmail.com">mariusjigmond@hotmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; After some more investigation that is likely NOT the issue. I have an ExecuteSQL statement which selects a certain polygon based on an attribute value. Unfortunately it seems to return the wrong feature. The feature I query for is unique so a duplicate is out of the question. Here's the code:<br>


&gt;<br>
&gt; #!/usr/bin/python<br>
&gt;<br>
&gt; from osgeo import ogr<br>
&gt; import sys, math, time, os<br>
&gt;<br>
&gt; aquifer = '/data/romania/judeteEPSG3844.shp'<br>
&gt; aqDS = ogr.Open(aquifer)<br>
&gt; sql = 'select * from judeteEPSG3844 where DENJUD = "CLUJ"'<br>
&gt; aqLayer = aqDS.ExecuteSQL(sql)<br>
&gt; feat = aqLayer.GetFeature(0)<br>
&gt; print aqLayer.GetFeatureCount()<br>
&gt; print feat.GetField('DENJUD')<br>
&gt; aqDS.ReleaseResultSet(aqLayer)<br>
&gt;<br>
&gt; The result:<br>
&gt; marius@mobi:~/temp$ run_sql.py <br>
&gt; 1<br>
&gt; TELEORMAN<br>
&gt; marius@mobi:~/temp$ <br>
&gt;<br>
&gt; This explains why none of my centroids were remotely close to the polygon.<br>
&gt;<br>
&gt; Is there something wrong with my query or should I file a bug?<br>
&gt;<br>
Can you select the feature by its FID instead? (apologies, I'm banging this out on my phone ... probably won't run but you should get the idea):<br>
aqLayer = aqDS.GetLayerByIndex(0) #gets the whole shapefile<br>
aqFID = aqLayer.GetFIDColumn() # I forget the method name here... hope this is right but may have to pull in the layer def<br>
sql = 'select %s from judeteEPSG3844 where DENJUD = "CLUJ"' % aqFID # specifically asking for just the FID field in the resultset<br>
sqlResults = aqDS.ExecuteSQL(sql) # sql results same as before<br>
featFID = sqlResults.GetFeature(0).GetFieldAsInt(aqFID) #this should be the actual FID of the results (problems would occur if your sql returned more than one hit)<br>
feat = aqLayer.GetFeature(featFID) # using the fid to grab the feature from the 0th layer in the shapefile<br>
This may be a long way around ... <br><br>
&gt; -marius<br>
&gt;<br>
&gt;<br>
&gt; On Mon, 2011-07-11 at 20:46 -0500, Marius Jigmond wrote:<br>
&gt;&gt;<br>
&gt;&gt; I suppose a piece of code speaks louder :):<br>
&gt;&gt;<br>
&gt;&gt; xsect = False<br>
&gt;&gt; for i in range(gridLayer.GetFeatureCount()):<br>
&gt;&gt; &nbsp; feat = gridLayer.GetFeature(i)<br>
&gt;&gt; &nbsp; geom = feat.GetGeometryRef()<br>
&gt;&gt; &nbsp; point = geom.Centroid()<br>
&gt;&gt; &nbsp; for j in range(aqLayer.GetFeatureCount()):<br>
&gt;&gt; &nbsp;&nbsp;&nbsp; aqfeat = aqLayer.GetFeature(j)<br>
&gt;&gt; &nbsp;&nbsp;&nbsp; aqgeom = aqfeat.GetGeometryRef()<br>
&gt;&gt; &nbsp;&nbsp;&nbsp; if point.Intersect(aqgeom):<br>
&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xsect = True<br>
&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'ibound = 1'<br>
&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break<br>
&gt;&gt; &nbsp; if xsect:<br>
&gt;&gt; &nbsp;&nbsp;&nbsp; feat.SetField('IBOUND', 1)<br>
&gt;&gt; &nbsp;&nbsp;&nbsp; gridLayer.SetFeature(feat)<br>
&gt;&gt; &nbsp;&nbsp;&nbsp; xsect = False<br>
&gt;&gt;<br>
&gt;&gt; -marius<br>
&gt;&gt;<br>
&gt;&gt; On Mon, 2011-07-11 at 20:34 -0500, Marius Jigmond wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Hi everyone,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I am trying to test whether centroids of polygons lie/intersect within another polygon. I have tried Intersect, Within, and Contains but they always return false. Should these methods work for my intended purpose or do I need to implement a point in polygon function? Thanks.<br>


&gt;&gt;&gt;<br>
&gt;&gt;&gt; -marius<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; gdal-dev mailing list<br>
&gt;&gt;&gt; <a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
&gt;&gt;&gt; <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; gdal-dev mailing list<br>
&gt;&gt; <a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
&gt;&gt; <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; gdal-dev mailing list<br>
&gt; <a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
&gt; <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
<br></div></div></div>                                               </div></div>
</blockquote></div><br></div></div>                                               </div></body>
</html>