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

How to convert this SharpMap.Geometries.Point in SharpMap 1.1?

Topics: SharpMap v0.9 / v1.x
Feb 20, 2014 at 10:58 AM
Hello everyone, I got this line of code from the demo example:
myMap.Center = DirectCast(ViewState("mapCenter"), SharpMap.Geometries.Point)
However, because I use SharpMap 1.1, this threw an error. How can correct this? I would appreciate it if there is document somewhere comparing SharpMap 0.9 and SharpMap 1.1 side by side. It seems a lot of changes between the demo example and the current release of SharpMap. This makes it impossible to use the current release with the demo website.

Feb 20, 2014 at 12:11 PM
myMap.Center = DirectCast(ViewState("mapCenter"), GeoAPI.Geometries.Coordinate)
Feb 20, 2014 at 7:07 PM
Thanks. I should have mentioned that I tried this also. It worked but once I clicked on the map it threw error saying it can't from points to coordinate. Have you experienced this? Thanks.
Feb 20, 2014 at 8:08 PM
If you look at the code in the DemoWebSite you'll notice the using directive that states the Point is to be used as a synonyme for GeoAPI.Geometries.Coordinate.
SharpMap.Geometries have been removed in favor of GeoAPI/NetTopologysuite some time ago.

It seems you are mixing old code with new compiled assemblies.
Feb 20, 2014 at 8:34 PM
Yes that's very true. I did mix it up, FObermaier. I am very new to this and I am trying to learn how this work. I used the demo as my guideline and downloaded the latest SharpMap assemblies. But both of them don't work together.

Could you point me to the documentation of how I can solve the problem using latest SharpMap assemblies?

Regarding my above question, how could I make it work with the latest assemblies? What's the equivalent code for SharpMap 1.1?

I am very sorry. I have been searching for days now and SharpMap is the closest I can get.

Thank you very very much.
Feb 20, 2014 at 9:06 PM
Actually it is fairly easy
  • SharpMap.Geometries.BoundingBox => GeoAPI.Geometries.Envelope
    Be careful, the constructor argument order has changed: xmin, ymin, xmax, ymax => xmin, xmax, ymin,ymax
  • SharpMap.Geometries.Point => either GeoAPI.Geometries.Coordinate if only the location is of interest or GeoAPI.Geometries.IPoint if topological context is relevant
  • All other SharpMap.Geometries.Geometry classes => GeoAPI.Geometries.IGeometry (or the specific types)
As you cannot create GeoAPI.Geometry.IGeometry interfaces with new, you need to use a geometry factory. You can use
var gf = GeoAPI.GeometryServiceProider.Instance.CreateGeometryFactory(...);
to get one. Or you use
var gf = new NetTopologySuite.Geometries.GeometryFactory();
Marked as answer by asplearning on 2/20/2014 at 2:01 PM