[gdal-dev] Problems doing spatial query with OGR

Clay, Bruce bclay at ball.com
Wed May 28 08:49:14 EDT 2008


Environment: Windows XP Visual Studio 2005, GDAL 1.5.0 with the C#  SWIG
bindings.

 

I am trying to determine the number of features within a geographic
bounding box for a specific time period.  The code I am using is shown
below

 

    OSGeo.OGR.Feature feature;

    int numFeatures;

 

    string sqlString = "select count(*) from " + tableName + " where " +
queryDefString;

 

    try

    {

        spatialFilter = Geometry.CreateFromWkt(wktGeometry);

    }

    catch (Exception except)

    {

        mLastErrorMsg = "Could not create patial filter from WKT
string";

    }

    if (spatialFilter != null)

    {

        try

        {

            dataLayer = dataSource.ExecuteSQL(sqlString, spatialFilter,
dialect);

 

            feature = dataLayer.GetNextFeature();

            if(feature != null)

            {
                numFeatures = feature. GetFieldAsInteger (0);

            }

                }

    }

 

The code executes without any error but appears to not use the spatial
filter at all because I get much lower results from an ArcObjects call
with the same bounding box and I get the same results from this code if
I pass a null value in as the spatial filter instead of the spatial
filter created from a WKT string.

 

The full sqlString is:

     "select count(*) from MODIS where

               DATE_TIME BETWEEN TO_DATE('2008-05-01 01:01:00',
'YYYY-MM-DD HH24:MI:SS') AND

                                 TO_DATE('2008-05-22 23:59:00',
'YYYY-MM-DD HH24:MI:SS')"

 

The wktGeometry string used to create the spatial filter is:

    "POLYGON((-83.7610299999997 35.1668499999996,

              -83.7610299999997 41.5608200000006,

              -76.9408000000003 41.5608200000006,

              -76.9408000000003 35.1668499999996,

              -83.7610299999997 35.1668499999996))"

 

As I mentioned above, I don't get any run time errors doing this just
the wrong results.

 

It appears to be filtering only on the date range provided.

 

Is there a specific order required in the WKT string?

 

Any other thoughts would be greatly appreciated.

 

Bruce

 




This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20080528/847049eb/attachment.html


More information about the gdal-dev mailing list