Some questions about finding shapes in shapefiles

Nov 8, 2010 at 7:48 PM

Hello,

I have turned to SharpMap because I am trying to locate specific shapes in a shapefile using a point.  I need to know whether a given point is within a shape.

I started of with SharpMap 0.9 a managed to locate the shapes with the following code:

BoundingBox ext = new SharpMap.Geometries.Point(point.X, point.Y).GetBoundingBox();

FeatureDataSet ds = new FeatureDataSet();
sf.ExecuteIntersectionQuery(ext, ds);

DataTable table = ds.Tables[0];
foreach (DataRow row in table.Rows)
{

}

      

This is very fast and as far as I can tell also accurate.

My first question is: how can I get the original feature id of the shapes found?

Because I could not find out how to get these, I tried the same with SharpMap 2.0:

IGeometryServices gs = new GeometryServices();
IExtents2D rect = gs.DefaultGeometryFactory.CreateExtents2D(point.X, point.Y, point.X, point.Y);
GeoAPI.Geometries.IPoint ipoint = gs.DefaultGeometryFactory.CreatePoint2D(point.X, point.Y);

FeatureQueryExpression query = FeatureQueryExpression.Intersects(ipoint.Extents);
using (IFeatureDataReader dr = sf.ExecuteFeatureQuery(query))
{
    while (dr.Read())
    {

       int fid = dr.GetOid();
    }
}

This also works, and now I can get the orginal feature id. But... it is many times slower than the SharpMap 0.9 version.

So my second question is: am I missing something, or is the 2.0 version just very slow? (I also saw an other user asking about this in 2008:  http://sharpmap.codeplex.com/Thread/View.aspx?ThreadId=31281).

I am specifically interested in using SharpMap 2.0 because later on I also want to write shapefiles.

If you can help me out that would be great.

Thanks!

 

Coordinator
Nov 9, 2010 at 7:05 AM

Hello asimov6

For SharpMap v0.9 you could use ShapeFile Providers

GetObjectIdsInView(BoundingBox env)

function.

For SharpMap v2.0 you might get better performance if you set for ShapeFileProvider IsSpatiallyIndexed = false. If you are just looking for the Ids, you could also use ShapeFileProvider's

ExecuteOidQuery(SpatialBinaryExpression query)

function.

Hth FObermaier

Nov 9, 2010 at 8:26 AM

Hello FObermaier,

Thanks for your reply. I also noticed the GetObjectIdsInView function. Is it as (in)accurate as the ExecuteIntersectionQuery?

I was allready using ShapeFileProvider IsSpatiallyIndexed = false, and that gives me a quick opening of the shapefile but the ExecuteFeatureQuery is still slow. On the other hand if I set IsSpatiallyIndexed = true, the opening is very slow (about 2 minutes for a 72 mb shapefile), but the ExecuteFeatureQuery is much faster (still not as fast as 0.9).

 

Thanks for your time.

Coordinator
Nov 9, 2010 at 8:52 AM

asimov6,

ExecuteIntersectionQuery internally calls GetObjectIdsInView, so you should get the same result.

Hth FObermaier

 

Oct 18, 2011 at 10:05 AM

For the shapefiles (.DBF) if you want to execute a custom query use this connection string: (using the visual fox-pro oledb)
Provider=vfpoledb;Data Source=<Path>;Collating Sequence=general; 

and then: select RecNo()-1 as RowID, <parameters> from <table> where <Conditions>

that RecNo()-1 return the pysical record number in the .DBF file. It's compatible only with visual fox-pro oledb