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

Convert Single Geometry Type to Another?

Topics: SharpMap v2.0
Jun 25, 2010 at 5:53 PM
Is it possible to convert a geometry type to another? For instance, I'd like to convert a MultiLineString to a Polygon. Is this possible? If so, what's the best approach to doing so? The object I'm trying to convert visualizes as a polygon, but when brought into SharpMap, it's "IsClosed" property is false. Thanks! Jason
Jun 27, 2010 at 10:22 PM

Hello Freedomspeaks,

Sharpmap v2.0 relies on NetTopologySuite v2.11 for creation and validation of Geometries.

If your LineStrings are not closed, you could do the following:

var mls = geom as IMultiLineString;
var gf = geom.Factory;
var linearRings = new List<ILinearRing>;
foreach (var lineString in mls.Components)
    var seq = lineString.Coordinates.Clone() as ICoordinateSequnece;
    if (!seq.IsClosed) seq.CloseRing();
return gf.CreatePolygon(linearRings);

This code has not seen a compiler, so there might be some errors, but -I think- it gives the broad picture.

Hth FObermaier



Jun 29, 2010 at 12:39 AM
Thanks for the reply. What .DLLs do I need to reference in my project to get this to build? I've tried the GeoAPI.dll and the NetTopologySuite.dll, but they don't seem to be working. Thanks again!
Jun 29, 2010 at 8:04 AM

You need to compile the sharpmap v2 solution yourself as there is no released version yet.

You can checkout the code via (tortoise)svn from

Hth FObermaier