This project has moved. For the latest updates, please go here.

get polygons

Dec 11, 2008 at 12:55 AM
Hi all my question is very simple how i can retrieve a polygons from SharpMap.Data.Providers.MsSql objec, i know tha i can retrieve geometries !
Dec 11, 2008 at 7:17 AM
do something like this:

SharpMap.Data.Providers.MsSql prov = new SharpMap.Data.Providers.MsSql( ... );
uint uid = <id of feature>;
SharpMap.Geometries.Geometry geom = prov.GetGeometryById(oid);

Dec 11, 2008 at 7:43 AM
Edited Dec 11, 2008 at 7:45 AM
how i can transform a Geometry object to polygon object, this is my code :

Polygon pl = new Polygon();







Dec 11, 2008 at 9:26 AM
And that is not working?

The function parsing the wkb data (look at SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse(BinaryReader reader) ) invokes - if the wkb data is encoding a Polygon - CreateWKBPolygon which is returning a Polygon instance. You should then be able to cast it as a Polygon.

Maybe check Geometry.AsText() to see what it is.

Dec 11, 2008 at 9:58 AM
try something like:

SharpMap.Data.Providers.MsSql sqls =  new ....
Polygon pl = null;
Geometry geom = sqls.GetGeometryById(0);

pl = geom as Polygon;
if(pl == null)
    throw new InvalidOperationException("Geometry is not a polygon. It is a " + geom.GetType());

// if we are here then pl contains a valid polygon so we can work with it