Trying to use Sharpmap 2.0

Topics: SharpMap v2.0
Sep 14, 2007 at 11:18 AM
Hi!

Im trying to use the sharpmap 2.0 located at google projects but i'm not able to figure out how to get it o work

My Current code:

...

ShapeFileProvider provider = new ShapeFileProvider(@"<Path>\Country Boundaries 2.shp");
provider.Open();

List<Geometry> geometries = new List<Geometry>();
geometries.AddRange(provider.GetGeometriesInView(provider.GetExtents()));

provider.Close();

GeometryProvider geoProvider = new GeometryProvider(geometries);

List<ILayer> layers = new List<ILayer>();

GeometryLayer layer = new GeometryLayer("MyLayer", geoProvider); #ArgumentNullException on this row
layers.Add(layer);

_map.AddLayers(layers);
sharpMapControl.ZoomToExtents();
sharpMapControl.Refresh();
...



The exception is from the SharpMap.Features.FeatureDataView


...

private object createRowPredicateFilter(Predicate<DataRow> filter)
{
Type rowPredicateFilterType = Type.GetType("System.Data.DataView+RowPredicateFilter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

object[] args = new object[] { filter };
object rowPredicateFilter = Activator.CreateInstance(rowPredicateFilterType,
BindingFlags.Instance | BindingFlags.NonPublic, null, args, null); #rowPredicateFilter is null

return rowPredicateFilter;
}
...

The type ("System.Data.DataView+RowPredicateFilter") seems a bit wierd?

...or am I doing something wrong?

Thanx
Coordinator
Sep 14, 2007 at 5:30 PM
You need to have .Net 3.5 Beta 2 installed at this time to run v2.0 of SharpMap.

It is an unfortunate problem with the System.Data namespace that it doesn't allow you to make your own filters for views, especially with the System.Predicate`1 type around. I don't know why we didn't get this functionality in v2.0 RTM: making the views filterable only by a rather crude expression system (System.Data.DataExpression - a non-public type where instances are created by parsing the DataView.RowFilter text) is very limiting.

The reason you are getting null is that the type System.Data.DataView+RowPredicateFilter, a DataView filter allowing you to use a System.Predicate`1, only exists in the v2.0 of the runtime which ships with v3.5 Beta 2 (revision 1378 or greater, whereas the most current released revision of v2.0 is 832). It's obviously there to support LINQ, and makes a great way to extend DataView (except for the part about not being a public type). I'm not sure if MS will ship this type as a hotfix to v2.0, or if v3.5 will be needed to take advantage of it. If we'll need v3.5, then it's not clear whether to make v3.5 a requirement of SharpMap v2.0 or to create a separate System.ComponentModel.IBindingListView implementation for feature data. I've tried hijacking other mechanisms of the DataView to do the needed spatial filtering, but to no avail whatever. So these (require v3.5 or implement IBindingListView) are the only two choices, it appears. You're input on this would be helpful...
Oct 18, 2007 at 2:12 AM
I also have the same problem which might be a difficult problem. I hope it will be resolved soon.
Coordinator
Oct 18, 2007 at 3:06 AM
I just found out today that the code which relies on .Net 3.5 Beta 2 really only relies on .Net 2.0 SP1, which is not released yet, but at least won't require 3.5.

However, the only way you can currently get 2.0 SP1 is to install 3.5 Beta 2. Do you have this?
Oct 18, 2007 at 5:35 AM
I downloaded 3.5 Beta2 and the project can be compiled normally. Maybe the best way is to achieve self-definition.