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

Add a primitive geometry

This example shows how to add a simple geometry like a point
or line or both.

SharpMap.Map mymap = new SharpMap.Map(new Size(100,100));
SharpMap.Layers.VectorLayer vectorLayer = new VectorLayer("GeometryLayer");

Collection<GeoAPI.Geometries.IGeometry> geomColl = 
    new Collection<GeoAPI.Geometries.IGeometry>();

//Get the default geometry factory
GeoAPI.GeometryServices.Instance = new NetTopologySuite.NtsGeometryServices();
GeoAPI.Geometries.GeometryFactory gf = 

//Add a single Point
geomColl.Add(gf.CreatePoint(10, 10));

//Add a LineString with 2 Points
GeoAPI.Geometries.Coordinate[] points = new GeoAPI.Geometries.Coordinate 
        new GeoAPI.Geometries.Coordinate(10, 10), 
        new GeoAPI.Geometries.Coordinate(20, 20), 


vectorLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(GeomColl);


Last edited Aug 31, 2012 at 12:36 PM by FObermaier, version 3