Search And Zoom To An Address (.SHP/.DBF)

Topics: CompactFramework, SharpMap v0.9 / v1.x, WinForms Controls
Mar 25, 2015 at 6:36 PM
Edited Mar 25, 2015 at 6:47 PM
I'm looking for examples regarding .dbf files associated with .shp, and the ability to zoom to addresses within them (have these displaying in a LabelLayer atm). I found something similar using PostGIS data provider here, but never got anywhere when modifying it:
   var dataSource = new SharpMap.Data.Providers.ShapeFile("Structures.shp", true, false);
   var bbox = dataSource.GetExtents();
   //Code for dataSource.DefinitionQuery (does not exist for this data provider)
   var ds = new SharpMap.Data.FeatureDataSet();
   dataSource.ExecuteIntersectionQuery(bbox, ds);
To my understanding your suppose to create a new search result layer which is built from a query executed against the .dbf (named the same as the .shp), and then zoom to the location of the result (bounding box) on that layer. Are there any examples of this? Any help is appreciated.
Coordinator
Apr 1, 2015 at 9:39 AM
The SharpMap.Data.ShapeFile provider derives from SharpMap.Data.FilterProvider that means you can do the following:
var dataSource = new SharpMap.Data.Providers.ShapeFile("Structures.shp", true, false);
dataSource.FilterDelegate = r => System.Convert.ToString(r["street"]).StartsWith("Main");
var bbox = dataSource.GetExtents();
var ds = new SharpMap.Data.FeatureDataSet();
dataSource.ExecuteIntersectionQuery(bbox, ds);
As an alternative you could set up a Dictionary<string, uint> that maps street names to feature ids. That way you can call dataSource.GetGeometryByID(fid) and use that to zoom to the item in question. To get the feature ids you need to set dataSource.IncludeOid = true;.