[Gdal-dev] OGRDataSource::ExecuteSQL() method returning inaccurate results

Chapman, Martin MChapman at sanz.com
Wed May 12 12:43:35 EDT 2004


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?
 
Martin

	-----Original Message-----
	From: Chapman, Martin 
	Sent: Wednesday, May 12, 2004 10:15 AM
	To: gdal-dev at remotesensing.org
	Subject: [Gdal-dev] OGRDataSource::ExecuteSQL() method returning
inaccurate results
	
	
	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:
	 
	COgrShapeLayer* COgrDataSource::ExecuteSQL(string sStatement,
CSXBasicGeometry* pSpatialFilter, string sDialect)
	{
	try
	{
	    if (!m_pDatasource)
	        throw exception("Invalid data source null.");
	 
	    OGRSpatialReference* pSpatialRef =
m_pDatasource->GetLayer(0)->GetSpatialRef();
	    OGRLinearRing* pRing = NULL;
	 
	    if (dynamic_cast< CSXPolygon*>(pSpatialFilter))
	    {
	        CSXPolygon* pPolygon = (CSXPolygon*) pSpatialFilter;
	        pRing = new OGRLinearRing();
	        vector< double>::iterator it;
	        vector< double>* pPoints = pPolygon->GetPoints();
	        double nX = 0.0, nY = 0.0;
	 
	        for (it = pPoints->begin(); it != pPoints->end(); it++)
	        {
	            nX = *it;
	            it++;
	            nY = *it;
	            pRing->addPoint(nX, nY);
	        }
	 
	        pRing->addPoint(pPoints->at(1), pPoints->at(0));
	    }
	    else
	        throw exception("Invalid spatial filter data type.");
	    
	    OGRPolygon* pPolygon = new OGRPolygon();
	    if (pSpatialRef)
pPolygon->assignSpatialReference(pSpatialRef);  
	    pPolygon->addRingDirectly(pRing);
	    OGRLayer* pLayer = m_pDatasource->ExecuteSQL((const char*)
sStatement.c_str(), pPolygon, (const char*) sDialect.c_str());
	 
	    if (pLayer == NULL) throw exception(CPLGetLastErrorMsg());
	 
	    COgrShapeLayer* pShapeLayer = CreateShapeLayer(pLayer);
	    m_pDatasource->ReleaseResultSet(pLayer);
	    if (CPLGetLastErrorNo() != OGRERR_NONE) throw
exception(CPLGetLastErrorMsg());
	 
	    return pShapeLayer;
	}
	catch(exception e) 
	    {throw e;}
	catch(...) 
	    {throw exception("An unexpected error occurred.");}
	}
	 
	Thanks,
	 
	
	Martin Chapman
	Cell 303-885-1936
	Office 303-660-3933 x226
	mchapman at sanz.com
	http://www.sanz.com <http://www.sanz.com/> 
	 
	 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20040512/871d428e/attachment.html


More information about the Gdal-dev mailing list