<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=744473916-12052004><FONT face=Arial color=#0000ff size=2>My
apologies, I'm an idiot, I was passing in my x and y points for the spatial
filter in the wrong order. I did notice that the spatial intersection uses
the envelope of the feature rather than the actually feature geometry
though. I this by design? Is there a way to filter based on the
geometry points or do I need to do that after the query has
returned?</FONT></SPAN></DIV>
<DIV><SPAN class=744473916-12052004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=744473916-12052004><FONT face=Arial color=#0000ff
size=2>Martin</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT
face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> Chapman, Martin
<BR><B>Sent:</B> Wednesday, May 12, 2004 10:15 AM<BR><B>To:</B>
gdal-dev@remotesensing.org<BR><B>Subject:</B> [Gdal-dev]
OGRDataSource::ExecuteSQL() method returning inaccurate
results<BR><BR></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004>I am using the
OGRDataSource::ExecuteSQL() method to spatially filter a esri shape
file. The results are inaccurate in that they return features that do
not intersect the filter. Is this a known issue or does it look
like an error in my code? I am using GDAL 119. The attached screen
shot shows the spatial filter results and my code is listed
below:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2></FONT></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2>COgrShapeLayer* COgrDataSource::ExecuteSQL(string sStatement,
</FONT></SPAN></FONT><FONT face=Arial size=2><SPAN
class=542114815-12052004><FONT size=2>CSXBasicGeometry* pSpatialFilter,
</FONT></SPAN></FONT><FONT face=Arial size=2><SPAN
class=542114815-12052004><FONT size=2>string
sDialect)</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2>{</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2>try</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2>{</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2> if</FONT><FONT size=2>
(!m_pDatasource)</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2>
throw</FONT><FONT size=2> exception("Invalid data source
null.");</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2></FONT></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> OGRSpatialReference* pSpatialRef =
m_pDatasource->GetLayer(0)->GetSpatialRef();</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> OGRLinearRing* pRing =
NULL;</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=542114815-12052004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2> if</FONT><FONT size=2> (</FONT><FONT
color=#0000ff size=2>dynamic_cast</FONT><FONT size=2><
CSXPolygon*>(pSpatialFilter))</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> {</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> CSXPolygon* pPolygon =
(CSXPolygon*) pSpatialFilter;</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> pRing = </FONT><FONT
color=#0000ff size=2>new</FONT><FONT size=2>
OGRLinearRing();</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> vector< </FONT><FONT
color=#0000ff size=2>double</FONT><FONT size=2>>::iterator
it;</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> vector< </FONT><FONT
color=#0000ff size=2>double</FONT><FONT size=2>>* pPoints =
pPolygon->GetPoints();</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2>
double</FONT><FONT size=2> nX = 0.0, nY = 0.0;</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=542114815-12052004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2>
for</FONT><FONT size=2> (it = pPoints->begin(); it != pPoints->end();
it++)</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> {</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> nX =
*it;</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=542114815-12052004>
it++;</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> nY =
*it;</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2>
pRing->addPoint(nX, nY);</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> }</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=542114815-12052004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2>
pRing->addPoint(pPoints->at(1),
pPoints->at(0));</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=542114815-12052004></SPAN></FONT><FONT face=Arial size=2><SPAN
class=542114815-12052004><FONT size=2>
}</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2> else</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2>
throw</FONT><FONT size=2> exception("Invalid spatial filter data
type.");</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> </FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> OGRPolygon* pPolygon = </FONT><FONT color=#0000ff
size=2>new</FONT><FONT size=2> OGRPolygon();</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2> if</FONT><FONT size=2> (pSpatialRef)
pPolygon->assignSpatialReference(pSpatialRef);
</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004>
</SPAN></FONT><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2>pPolygon->addRingDirectly(pRing);</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> OGRLayer* pLayer =
m_pDatasource->ExecuteSQL((</FONT><FONT color=#0000ff
size=2>const</FONT><FONT size=2> </FONT><FONT color=#0000ff
size=2>char</FONT><FONT size=2>*) sStatement.c_str(),
</FONT></SPAN></FONT><FONT face=Arial size=2><SPAN
class=542114815-12052004><FONT size=2>pPolygon, </FONT></SPAN></FONT><FONT
face=Arial size=2><SPAN class=542114815-12052004><FONT size=2>(</FONT><FONT
color=#0000ff size=2>const</FONT><FONT size=2> </FONT><FONT color=#0000ff
size=2>char</FONT><FONT size=2>*)
sDialect.c_str());</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2></FONT></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2> if</FONT><FONT size=2> (pLayer ==
NULL) </FONT><FONT color=#0000ff size=2>throw</FONT><FONT size=2>
exception(CPLGetLastErrorMsg());</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=542114815-12052004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> COgrShapeLayer* pShapeLayer =
CreateShapeLayer(pLayer);</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2>
m_pDatasource->ReleaseResultSet(pLayer);</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2> if</FONT><FONT size=2>
(CPLGetLastErrorNo() != OGRERR_NONE) </FONT><FONT color=#0000ff
size=2>throw</FONT><FONT size=2>
exception(CPLGetLastErrorMsg());</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=542114815-12052004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2> return</FONT><FONT size=2>
pShapeLayer;</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2>}</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2>catch</FONT><FONT size=2>(exception e)
</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> {</FONT><FONT color=#0000ff size=2>throw</FONT><FONT
size=2> e;}</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
color=#0000ff size=2>catch</FONT><FONT size=2>(...)
</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2> {</FONT><FONT color=#0000ff size=2>throw</FONT><FONT
size=2> exception("An unexpected error
occurred.");}</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=542114815-12052004><FONT
size=2>}</DIV></FONT></SPAN></FONT>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=542114815-12052004><FONT face=Arial
size=2>Thanks,</FONT></SPAN></DIV>
<DIV><SPAN class=542114815-12052004><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV align=left><FONT face=Arial size=2>
<DIV align=left><FONT face=Arial size=2>Martin Chapman</FONT></DIV>
<DIV align=left><FONT face=Arial><FONT size=2><SPAN
class=812572720-02042003>Cell</SPAN> 303-885-1936</FONT></FONT></DIV>
<DIV align=left><FONT face=Arial size=2><SPAN class=812572720-02042003>Office
303-660-3933 x226</SPAN></FONT></DIV>
<DIV align=left><FONT face=Arial size=2><SPAN class=812572720-02042003><A
href="mailto:mchapman@sanz.com">mchapman@sanz.com</A></SPAN></FONT></DIV>
<DIV align=left><FONT face=Arial size=2><SPAN class=812572720-02042003><A
href="http://www.sanz.com/">http://www.sanz.com</A></SPAN></FONT></DIV></FONT></DIV>
<DIV align=left><FONT face=Arial size=2></FONT> </DIV>
<DIV> </DIV></BLOCKQUOTE></BODY></HTML>