SharpMap 1.1 missing references

Topics: Algorithms, SharpMap v0.9 / v1.x, Web Controls
Jun 12, 2015 at 6:42 AM
Hi,
I have used SharpMap 0.9 to develop an application in ASP.NET framework 2 which is working fine. Now I'm trying to convert it to framework 4 and trying to use SharpMap 1.1, I'm facing errors . Mostly are reference error below are the same for reference,
  1. 'GeoAPI.Geometries.Envelope' does not contain a definition for 'Left'.
  2. The type or namespace name 'Geometries' does not exist in the namespace 'SharpMap'.
apart from this it looks like SharpMap 1.1 has changed or moved SharpMap.Geometries.GeometryCollection is there any reference for how can I implement this GeometryCollection ?

Cheers!
Coordinator
Jun 12, 2015 at 9:14 AM
SharpMap geometries have been removed in favor of GeoAPI/NetTopologySuite geometries as they did provide full topology support.
This means you have to reference GeoAPI and NetTopolgySuite.

1.) SharpMap.Geometries.Envelope.Left equals to GeoAPI.Geometries.Envelope.MinX or GeoAPI.Geometries.Envelope.Left() (extension method)
2.) SharpMap.Geometries -> GeoAPI.Geometries.

GeoAPI/NetTopologySuite have GeometryCollections as well.
Jun 12, 2015 at 12:26 PM
Edited Jun 12, 2015 at 12:28 PM
Thank you FObermaier, That was amazingly fast response and it really helped a lot. I'll be needing a little bit more time of yours to sort this out. Can you please take a look at the below code that's where I'm stuck at. If you could show me how to use the new methods in the below piece of code it will help a lot.
SharpMap.Geometries.GeometryCollection pointArraySubject = new SharpMap.Geometries.GeometryCollection();   
SharpMap.Layers.VectorLayer mySubjectLayer = new SharpMap.Layers.VectorLayer("SubjectIcon");
mySubjectLayer.Style.Line = new Pen(Outlinecolor, 3);
mySubjectLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(pointArraySubject);
mySubjectLayer.Style.Fill = new System.Drawing.SolidBrush(Color.Yellow);
mySubjectLayer.SRID = _SRID;
  Cheers!      
Coordinator
Jun 15, 2015 at 6:34 AM
var factory = GeoAPI.GeometryServices.Instance.CreateGeometryFactory(_SRID);
var pointArraySubject = factory.CreateGeometryCollection(null);
var mySubjectLayer = new SharpMap.Layers.VectorLayer("SubjectIcon");
mySubjectLayer.Style.Line = new System.Drawing.Pen(Outlinecolor, 3);
mySubjectLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(pointArraySubject);
mySubjectLayer.Style.Fill = new System.Drawing.SolidBrush(Color.Yellow);
Jun 16, 2015 at 6:27 AM
Thank you FObermaier, I tried your above code snippet,
var factory = GeoAPI.GeometryServices.Instance.CreateGeometryFactory(_SRID);
I'm getting,
The type or namespace name 'GeometryServices' does not exist in the namespace 'GeoAPI' (are you missing an assembly reference?)
it seems I'm missing a reference for that one which one should I use? shall I use the below, Please advise :
GeoAPI.IGeometryServices.CreateGeometryFactory(System.Int32)
(or)
NetTopologySuite.NtsGeometryServices.CreateGeometryFactory()
Cheers!
Coordinator
Jun 16, 2015 at 6:54 AM
var factory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(_SRID);
If you get an exception stating that the instance was not set, you need to add
GeoAPI.GeometryServiceProvider.Instance = NetTopologySuite.NtsGeometryServices.Instance;
somewhere in the startup of your application.
Jun 17, 2015 at 4:47 AM
Thanks a lot FObermaier, I have used the above solution you provided it works like a charm.
Have a few more other errors after using that now.
1.var factory = GeoAPI.GeometryServices.Instance.CreateGeometryFactory(_SRID);
var pointArraySubject = factory.CreateGeometryCollection(null);
var mySubjectLayer = new SharpMap.Layers.VectorLayer("SubjectIcon");
mySubjectLayer.Style.Line = new System.Drawing.Pen(Outlinecolor, 3);
mySubjectLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(pointArraySubject); <-- Hitting a error here!
mySubjectLayer.Style.Fill = new System.Drawing.SolidBrush(Color.Yellow);

The error is like below, No idea what this is. I tried googling but no luck!
The call is ambiguous between the following methods or properties: 'SharpMap.Data.Providers.GeometryFeatureProvider.GeometryFeatureProvider(GeoAPI.Geometries.IGeometry)' and 'SharpMap.Data.Providers.GeometryFeatureProvider.GeometryFeatureProvider(System.Collections.Generic.IEnumerable<GeoAPI.Geometries.IGeometry>)'

2.pointArraySubject.Coordinates.Add();
 How to add new coordinates into array? It seems this has been moved to another reference, is that so?.
  1. pointArray.Collection.Add(SharpMap.Geometries.LinearRing.GeomFromWKB((byte[])Row["the_geom"]));
    Error in above line is like:
    'GeoAPI.Geometries.IGeometryCollection' does not contain a definition for 'Collection' and no extension method 'Collection' accepting a first argument of type 'GeoAPI.Geometries.IGeometryCollection' could be found (are you missing a using directive or an assembly reference?)
Cheers!
Coordinator
Jun 17, 2015 at 1:48 PM
  1. mySubjectLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider((GeoAPI.Geometries.IGeometry)pointArraySubject);
  2. Geometries are treated as value items in GeoAPI/NTS, thus you can't add coordinates to an existing geometry. If you want to add a new point to the GeometryProvider, you need to add it to the provider:
var p = (GeometryProvider)mySubjectLayer.DataSource;
p.Geometries.Add(...);