<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.32.2">
</HEAD>
<BODY>
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>
<BR>
#!/usr/bin/python<BR>
<BR>
from osgeo import ogr<BR>
import sys, math, time, os<BR>
<BR>
aquifer = '/data/romania/judeteEPSG3844.shp'<BR>
aqDS = ogr.Open(aquifer)<BR>
sql = 'select * from judeteEPSG3844 where DENJUD = "CLUJ"'<BR>
aqLayer = aqDS.ExecuteSQL(sql)<BR>
feat = aqLayer.GetFeature(0)<BR>
print aqLayer.GetFeatureCount()<BR>
print feat.GetField('DENJUD')<BR>
aqDS.ReleaseResultSet(aqLayer)<BR>
<BR>
The result:<BR>
<A HREF="mailto:marius@mobi">marius@mobi</A>:~/temp$ run_sql.py <BR>
1<BR>
TELEORMAN<BR>
<A HREF="mailto:marius@mobi">marius@mobi</A>:~/temp$ <BR>
<BR>
This explains why none of my centroids were remotely close to the polygon.<BR>
<BR>
Is there something wrong with my query or should I file a bug?<BR>
<BR>
-marius<BR>
<BR>
On Mon, 2011-07-11 at 20:46 -0500, Marius Jigmond wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
I suppose a piece of code speaks louder :):<BR>
<BR>
xsect = False<BR>
for i in range(gridLayer.GetFeatureCount()):<BR>
feat = gridLayer.GetFeature(i)<BR>
geom = feat.GetGeometryRef()<BR>
point = geom.Centroid()<BR>
for j in range(aqLayer.GetFeatureCount()):<BR>
aqfeat = aqLayer.GetFeature(j)<BR>
aqgeom = aqfeat.GetGeometryRef()<BR>
if point.Intersect(aqgeom):<BR>
xsect = True<BR>
print 'ibound = 1'<BR>
break<BR>
if xsect:<BR>
feat.SetField('IBOUND', 1)<BR>
gridLayer.SetFeature(feat)<BR>
xsect = False<BR>
<BR>
-marius<BR>
<BR>
On Mon, 2011-07-11 at 20:34 -0500, Marius Jigmond wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
Hi everyone,<BR>
<BR>
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>
<BR>
-marius
<PRE>
_______________________________________________
gdal-dev mailing list
<A HREF="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</A>
<A HREF="http://lists.osgeo.org/mailman/listinfo/gdal-dev">http://lists.osgeo.org/mailman/listinfo/gdal-dev</A>
</PRE>
</BLOCKQUOTE>
<PRE>
_______________________________________________
gdal-dev mailing list
<A HREF="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</A>
<A HREF="http://lists.osgeo.org/mailman/listinfo/gdal-dev">http://lists.osgeo.org/mailman/listinfo/gdal-dev</A>
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>