polygon

Topics: SharpMap v0.9 / v1.x
Jun 29, 2011 at 2:59 PM

Hi!

I am inexperienced in SharpMap. I would like to draw a polygon with these dimensions
XMIN = 447509.148  XMAX=  447536.264, YMIN =544796.866, YMAX=544825.796

thanks mo_960

Jun 30, 2011 at 12:07 AM
  1. You should create a SharpMap.Geometries.BoundingBox. It has a constructor with parameters you need
  2. You should add a VectorLayer to your map (you can set VectorLayer's symbol to set colors and style)
  3. Create a GeometryProvider or a GeometryFeatureProvider for your VectoryLayer
  4. Set it as your VectorLayer's datasource
  5. Add a new row to your provider and set its geometry to your BoundingBox
  6. Refresh your map
Jun 30, 2011 at 9:02 AM

Hi tmatrai!

Thanks for the quick reply.

Maybe you have an example for me? Below I copied my attempt
...

            //Create sharpmap BoundingBox
            BoundingBox _BoundingBox = new BoundingBox(447509.148, 447536.264, 544796.866, 544825.796);

            //???????
            SharpMap.Data.Providers.GeometryProvider _GeometryProvider = new SharpMap.Data.Providers.GeometryProvider("????");

            //Set GeometryProvider to VectorLayer's datasource
            SharpMap.Layers.VectorLayer _VectorLayer = new VectorLayer("myLayer", _GeometryProvider);
           
            //Set colors and style
            _VectorLayer.Style.Fill = new SolidBrush(Color.FromArgb(50, 247, 125));
            _VectorLayer.Style.EnableOutline = true;
            _VectorLayer.Style.Outline = new Pen(Color.Black);
           
            //Add VectorLayer to map
            mapImage1.Map.Layers.Add(_VectorLayer);
            //Refresh map
            mapImage1.Refresh();
          


 


Jun 30, 2011 at 10:37 AM

You missed step 5:

You use geometryprovider, it must be initialized by your boundingbox in your constructor.

SharpMap.Data.Providers.GeometryProvider _GeometryProvider = new SharpMap.Data.Providers.GeometryProvider(_BoundingBox);

Coordinator
Jun 30, 2011 at 4:47 PM

as far as i know, you cannot add BoundingBox to GeometryProvider. You need to create some sort of valid Geometry class, in this case a polygon

var left = 447509.148;
var right = 447536.264;
var top = 544825.796;
var bottom = 544796.866;
SharpMap.Data.Providers.GeometryProvider _GeometryProvider = 
new SharpMap.Data.Providers.GeometryProvider(new SharpMap.Geometry.Polygon(
new [] { new SharpMap.Geometry.Point( left, bottom ), new SharpMap.Geometry.Point( left, top), new SharpMap.Geometry.Point( right, top ), new SharpMap.Geometry.Point( right, bottom ), new SharpMap.Geometry.Point( left, bottom ),
} ));
Hth FObermaier

Jul 1, 2011 at 8:30 AM

Yes, this was missing. Many thanks to FObermaier and tmatrai, keep on the good work!