support for getting coordinates for polygon without parsing string in sharpmap???

Topics: Algorithms, Data Access, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0
Nov 29, 2010 at 10:38 AM

Currently, FeatureDataRow.Geometry provides GeometryType and text representation of its shape. but I have to parse the Geometry string (e.g. POLYGON (((east north, )))) to get earch pair of coordinates (e.g. east and north ).

 

Is this feature available in SharpMap?

 

Thanks in advance.

Coordinator
Nov 29, 2010 at 10:57 AM

Hello kingofwebguru,

you don't need to parse the wkt:

SharpMap.Data.FeatureDataRow fdr;
SharpMap.Geometries.Polygon p = fdr.Geometry as SharpMap.Geometries.Polygon;
if (p == null) return;
for (int i = 0; i < p.ExteriorRing.NumPoints; i++) { SharpMap.Geometries.Point pt = p.ExteriorRing.Vertices[i]; // ... } foreach (SharpMap.Geometries.LinearRing interiorRing in p.InteriorRings) { for (int i = 0; i < interiorRing.NumPoints; i++) { SharpMap.Geometries.Point pt = interiorRing.Vertices[i]; //... } }

Hth FObermaier

Nov 29, 2010 at 9:39 PM

Hi Hth FObermaier,

Is there built-in methods that allows me to do the reverse, ie, methods that can be used to build polyogn/multi-polygon based on coordinates? Because I need to read those cooridnates from shapefile, then transform them, and finally store them in database using geography type.

K.

Coordinator
Nov 29, 2010 at 9:54 PM
Edited Nov 29, 2010 at 9:55 PM

Hello kingofwebguru,

have a look at SharpMap.SqlServerSpatialObjects project. It should handle SharpMap.Geometries.Geometry -> SqlServer2008.Geometry datatype. Either you enhance it to Convert to Geography or, I think there should be Geometry <-> Geography conversion routines in the respective library

Hth FObermaier

Nov 30, 2010 at 10:13 AM

Hi Hth FObermaier,

What I want is the ability to assembly the shape back. For example, once I used those routines to read every coordinates (e.g. East/North, Lat/Lon) from polygon or multipolygon, I want to be able to create polygon/mulitipolygon from those coordinates. For example:

Given:

Polygon (())

and the code below:

 

SharpMap.Data.FeatureDataRow fdr;
SharpMap.Geometries.Polygon p = fdr.Geometry as SharpMap.Geometries.Polygon;
if (p == null) return;
for (int i = 0; i < p.ExteriorRing.NumPoints; i++)
{
SharpMap.Geometries.Point pt = p.ExteriorRing.Vertices[i];
// ...
}
foreach (SharpMap.Geometries.LinearRing interiorRing in p.InteriorRings)
{
for (int i = 0; i < interiorRing.NumPoints; i++)
{
SharpMap.Geometries.Point pt = interiorRing.Vertices[i];
//...
}
}


--> produce coordinates




What I need is code to do the reverse to create polygon/multipolygon based on coordinates, e.g.

Polygon (())
Multipolygon ((()))








Coordinator
Nov 30, 2010 at 10:39 AM

Kingofwebguru,

+olygons are made up of an exterior ring and -possibly- a set of non-intersecting interior rings.

To create a Polygon, you first need to create -at least- the exterior ring:

SharpMap.Geometries.Point[] points;
System.Collections.Generic.List<SharpMap.Geometries.Point> pointList = new System.Collections.Generic.List<SharpMap.Geometries.Point>(pts);
SharpMap.Geometries.LinearRing linearRing = new SharpMap.Geometries.LinearRing(pointList);

Then you can create the polygon:

SharpMap.Geometries.Polygon polygon = new SharpMap.Geometries.Polygon(linearRing);

If you do have interior rings you need to create them just like the exterior ring and pass the list of interior rings to the constructor as well

var interiorRings = new System.Collections.Generic.List<SharpMap.Geometries.LinearRing>();
//Add the rings
...
SharpMap.Geometries.Polygon polygon = new SharpMap.Geometries.Polygon(linearRing, interiorRings);
Hth FObermaier

Nov 30, 2010 at 10:57 AM

Hth FObermaier,

Thank you!

 

Regarding multipolygon, I would very much appreciate it if code for multipolygon could be provided. It would aslo be good for someone else who might need it using SharpMap.

Coordinator
Nov 30, 2010 at 11:36 AM

sorry, forgot about that one:

you need to setup the polygons first, create a new MultiPolygon instance and add the polygons to its Polygons property.

cheers

FObermaier

Dec 3, 2010 at 11:17 AM

Hi,

 

Can SharpMap convert SharpMap geography to SqlGraphy data  type ?

Coordinator
Dec 3, 2010 at 11:30 AM

Hello kingofwebguru,

have a look at SharpMap.SqlServerSpatialObjects project. It should handle SharpMap.Geometries.Geometry -> SqlServer2008.Geometry datatype. Either you enhance it to Convert to Geography or, I think there should be SqlServer2008.Geometry <-> SqlServer2008.Geography conversion routines in the respective library

Hth FObermaier