ThinkGeo.com    |     Documentation    |     Premium Support

Problem with Polygon (Innerrings)

Hello,

in my Application I create doughnut polygons (one outer ring, one inner ring). But my polygons are completely filled, i can not see a hole for the inner ring. Hints are very wellcome...


Torsten

 


 



        public Form1()
        {
            InitializeComponent();
            this.winformsMap1.MapUnit = GeographyUnit.Meter;
        }

        static string fn_polyError = "polygon.txt";

        private void button1_Click(object sender, EventArgs e)
        {
            string ff = fn_polyError;
            string fn = Path.Combine(@"d:\", ff);
            if (!File.Exists(fn)) return;
            StreamReader sr = new StreamReader(fn, Encoding.UTF8);
            var koordString = sr.ReadToEnd();
            PolygonShape poly = new PolygonShape();
            poly.LoadFromWellKnownData(koordString);

            PolygonShape outer = null;
            PolygonShape inner = null;
            if (string.Compare(ff, fn_polyError, true) == 0)
            {
                outer = new PolygonShape(poly.OuterRing.CloneDeep() as RingShape);
                outer.TranslateByOffset(1400, 1400, GeographyUnit.Meter, DistanceUnit.Meter);
                inner = new PolygonShape(poly.InnerRings[0].CloneDeep() as RingShape);
                inner.TranslateByOffset(-1400, 1400, GeographyUnit.Meter, DistanceUnit.Meter);
            }

            InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, GeoColor.StandardColors.DarkBlue));
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            LayerOverlay ovl = new LayerOverlay();
            ovl.Layers.Add(inMemoryFeatureLayer);
            ovl.IsVisible = true;
            inMemoryFeatureLayer.IsVisible = true;
            this.winformsMap1.Overlays.Add(ovl);

            inMemoryFeatureLayer.Open();
            inMemoryFeatureLayer.EditTools.BeginTransaction();
            inMemoryFeatureLayer.EditTools.Add(new Feature(poly));

            if (null != outer) inMemoryFeatureLayer.EditTools.Add(new Feature(outer));
            if (null != inner) inMemoryFeatureLayer.EditTools.Add(new Feature(inner));

            inMemoryFeatureLayer.EditTools.CommitTransaction();
            var ext = inMemoryFeatureLayer.GetBoundingBox();
            inMemoryFeatureLayer.Close();

            this.winformsMap1.CurrentExtent = ext;
            this.winformsMap1.Refresh(ovl);

        }



Hi Torsten,


I think the reason is that your polygon's outerring and innerring's directions are the same, I tried to reverse the outerring's points, it works properly, please replace your code



inMemoryFeatureLayer.EditTools.Add(new Feature(poly));

with 



PolygonShape newPoly = new PolygonShape();
for (int i = poly.OuterRing.Vertices.Count - 1; i >= 0; i--)
{
    newPoly.OuterRing.Vertices.Add(poly.OuterRing.Vertices<i>);
}
foreach (var item in poly.InnerRings)
{
    newPoly.InnerRings.Add(item);
}

inMemoryFeatureLayer.EditTools.Add(new Feature(newPoly));


and you can get the imange:



Hope it helps,


Edgar



Hallo Edgar,

thank you for your quick answer. The Problem is fixed. BTW - is that a generally requirement: OuterRings MUST have a different direction as the InnerRings?


Torsten



Torsten, 
  
 Yes, it’s a generally requirement, only this could tell the graphics to draw a hole in a AreaBaseShape or not, and strictly, the outerring direction must be clockwise and the innerrings must be counterclockwise. 
  
 Regards, 
  
 Edgar