ThinkGeo.com    |     Documentation    |     Premium Support

Adding a PolygonShape

I must be missing something simple. I have created a series of vertices to build a polygon. If i create a LineShape from them and add them to my layer, everything works perfectly: 



 



linePoints.Add(new Vertex(minXminY));
linePoints.Add(new Vertex(maxXminY));
linePoints.Add(new Vertex(maxXmaxY));
linePoints.Add(new Vertex(minXmaxY));
linePoints.Add(new Vertex(minXminY));

line = new LineShape(linePoints);

newPolyLayer.FeatureSource.AddFeature(line);


Now, if i load that line into a PolygonShape and do the same process to add it to the layer, nothing shows up on my map. Do i need to do something differently when working with a PolygonShape vs a LineShape??




PolygonShape pathPart = new PolygonShape(line.GetWellKnownText().Replace("LINESTRING", "POLYGON(") + ")");

newPolyLayer.FeatureSource.AddFeature(pathPart);



Here's an example of the WKT:

POLYGON((-96.5510170619308 45.192079,-96.5510949380692 45.192079,-96.5510949380692 45.1921065365298,-96.5510170619308 45.1921065365298,-96.5510170619308 45.192079))




In both instances, the FeatureSource has the transaction open, and the layer is open.
Also in both cases I set the defaultLineStyle and add the layer to the overlay, then refresh the map




newPolyLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.Black, 1, true);

labelOverlay.Layers.Add("myLayer", newPolyLayer);

map.Refresh();


levi,


Thanks for your post and your sample code is very helpful to find the problem.


The PolygonShape is inherited from AreaBaseShape, so you need to set the DefaultAreaStyle to the layer which contains polygon. The code likes below:


            newPolyLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Black));
            newPolyLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Width = 1;
            newPolyLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.LineJoin = DrawingLineJoin.Round;
            newPolyLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

Please let me know if you have more questions.


Thanks


James



Perfect. With this info I’m able to ditch the LineShape and WKT altogether and just new up a RingShape with my vertices. 
  
 The API Documentation and Code Community didn’t help much when I was looking for samples for doing this, or for some other simple things. Is there any other documentation that I can access that goes over some of these 101 type processes?

Unfortunately, we currently don’t have the documentation to explain high level, 101 type of topics such as explaining what style to use for what type of shape and why.You are right to express concern that we lack such a documentation. 
   We have had in plan to have such a documentation for a long time. Soon, we will start working on that and the documentation will be in a Wikipedia format.  
  Thank you for reminding us of how important this is that we finally bring to our users the most complete documentation.


Good to hear.


Maybe this is another 101 thing...



I have this object: 



MultipolygonShape outline = MultipolygonShape.Union(path);


And I need to apply a negative buffer to it. I went the route of 



outline.Buffer(-2, GeographyUnit.DecimalDegree, DistanceUnit.Meter);


But get an inxedOutOfRange exception on distance. So, I took a look at the NegativeBuffer code sample. What it's doing makes sense, however, in the GetPerimeter method, OuterRing is called to get a collection of vertices on the PolygonShape. My issue is that I'm using a MultiPolygonShape and not a PolygonShape. Is there an easy conversion here? Or better yet, is there an easy way to get a list of vertices for my MultiPolygonShape?




The answer to get the NegativeBuffer code to work was to use the Polygons property on MultiPolygonShape



foreach (PolygonShape polygon in outline.Polygons)
{
// call it here
}


Levi, 
  
   One other thing to add is that with the developer build we have fixed the Buffer method to support negative buffering.  In the past we did not allow it but it is part of the next release to have the API accept negative values.  If you get the latest developer build this should work for you if interested. 
  
 David

 I would like to also comment that in the older versions of Map Suite, it is still possible to apply negative buffering. You can see that in the project of the Code Community, Negative Buffering.


code.thinkgeo.com/projects/s...ebuffering