This project has moved and is read-only. For the latest updates, please go here.

Zoom to FilterDelegate results

Topics: Algorithms, CompactFramework, Data Access, General Topics, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, WinForms Controls
Jan 26, 2011 at 4:28 PM


I'm new user SharpMap and i'm trying to do a zoom in results of Filterdelegate.

my code:

SharpMap.Map sharp = new SharpMap.Map(new Size(727, 489));

ShapeFile sf = new ShapeFile(Shapefile, true);

sf.FilterDelegate = delegate(FeatureDataRow row)
   return row["cCodQuadra"].Equals("0293");


SharpMap.Layers.VectorLayer testlayer = new SharpMap.Layers.VectorLayer("TestLayer");

testlayer.DataSource = sf;



But Extents of "sf" is all shapefile not only results filterdelegate.

Somebody help me?

Jan 27, 2011 at 8:05 AM

hello heliolima,

you are right, the ShapeFile provider's GetExtents() function always returns the whole extent.

Now if you just want to zoom to that polygon, you can perform:

var fds = new FeatureDataSet();
sf.ExecuteIntersectionQuery(sf.GetExtents(), fds);
var bb = new BoundingBox();
foreach(var fdr in fds.Tables[0].Rows)
   bb = bb.Join(fdr.Geometry.BoundingBox);

You also have the choice to add a new GeometryLayer with a GeometryFeatureProvider as datasource with fds.Tables[0] as construction argument. Then you can remove the FilterDelegate from the ShapeFile provider.

Hth FObermaier

Jan 27, 2011 at 10:40 PM

hello FObermaier

thank you for the help.

i got this way:


SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet();

sf.ExecuteIntersectionQuery(sf.GetExtents(), fds);

List<SharpMap.Geometries.BoundingBox> listabb = new List<SharpMap.Geometries.BoundingBox>();

SharpMap.Geometries.BoundingBox bb = null;

var teste = (from lista in fds.Tables[0].AsEnumerable()
  select lista).ToList();

foreach (var fdr in teste)
     SharpMap.Data.FeatureDataRow dr = fdr as SharpMap.Data.FeatureDataRow;

bb = new SharpMap.Geometries.BoundingBox(listabb);