ThinkGeo.com    |     Documentation    |     Premium Support

Union of Polygon

We are not able to highlight the (area/region) union/ Intersection of  polygons.


These are from 2 different shape files.


We fetch one polygon fron shape file and check the adjacent polygons in other shape file.


Now we want to find out the overlapping area to be highlighted of these two polygons.




We want to calculate overlapping area also.


 


Please guide me.


Thanks


Dhananjay


 



Dhananjay,


I don't have your two shapes in shapefiles, so I simulated it with two overlapping squares in one memory layer styled with just a pen and the intersecting shape in a second memory layer so I could style it with a fill.  If each feature is in a shapefile layer it should be easy to use GetAllFeatures or something related to get the shapes out and then generate the intersection.  You could add the intersected shape back into one of the shapefile layers but if you set the fill to see the intersection you won't be able to see the new shape from the original shapes, so I added it into a second layer I could style with a fill.  If you really needed to do that I think the only way would be to apply a ValueStyle based on some column which would apply a style without fill to certain features and another to others with the fill.  If you're just trying to do this basic operation that's probably going too far.


There is also a message box using RectangleShape.GetArea to get the area of the intersecting shape. 


 I know this isn't the exact answer but maybe it'll give you an idea or two.


Allen


 


 




winformsMap1.MapUnit =



GeographyUnit.DecimalDegree;LayerOverlay overlay = new LayerOverlay();InMemoryFeatureLayer original = new InMemoryFeatureLayer();new AreaStyle(new GeoPen(GeoColor.SimpleColors.Red));ApplyUntilZoomLevel.Level20;InMemoryFeatureLayer intersect = new InMemoryFeatureLayer();new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Green));ApplyUntilZoomLevel.Level20;RectangleShape rectangle1 = new RectangleShape(new PointShape(-80, 40), new PointShape(-79, 39));RectangleShape rectangle2 = new RectangleShape(new PointShape(-79.2, 40.5), new PointShape(-78.2, 39.5));RectangleShape rectangle3 = rectangle1.GetIntersection(rectangle2);new Feature(rectangle1));new Feature(rectangle2));new Feature(rectangle3));MessageBox.Show(rectangle3.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareMeters).ToString());RectangleShape extent = original.GetBoundingBox();


 


 


original.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle =


original.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel =


 


intersect.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle =


intersect.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel =


 


 


 


original.Open();


original.InternalFeatures.Add(


original.InternalFeatures.Add(


intersect.Open();


intersect.InternalFeatures.Add(


 


overlay.Layers.Add(original);


overlay.Layers.Add(intersect);


 


winformsMap1.Overlays.Add(overlay);


winformsMap1.CurrentExtent = extent;


winformsMap1.Refresh();



Ugh, that didn’t work.  Let me try again… 
  
                 winformsMap1.MapUnit = GeographyUnit.DecimalDegree; 
  
                 LayerOverlay overlay = new LayerOverlay(); 
  
                 InMemoryFeatureLayer original = new InMemoryFeatureLayer(); 
                 original.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Red)); 
                 original.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
                 InMemoryFeatureLayer intersect = new InMemoryFeatureLayer(); 
                 intersect.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Green)); 
                 intersect.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
                 RectangleShape rectangle1 = new RectangleShape(new PointShape(-80, 40), new PointShape(-79, 39)); 
                 RectangleShape rectangle2 = new RectangleShape(new PointShape(-79.2, 40.5), new PointShape(-78.2, 39.5)); 
                 RectangleShape rectangle3 = rectangle1.GetIntersection(rectangle2); 
  
                 original.Open(); 
                 original.InternalFeatures.Add(new Feature(rectangle1)); 
                 original.InternalFeatures.Add(new Feature(rectangle2)); 
  
                 intersect.Open(); 
                 intersect.InternalFeatures.Add(new Feature(rectangle3)); 
                 MessageBox.Show(rectangle3.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareMeters).ToString()); 
  
                 overlay.Layers.Add(original); 
                 overlay.Layers.Add(intersect); 
  
                 RectangleShape extent = original.GetBoundingBox(); 
                 winformsMap1.Overlays.Add(overlay); 
  
                 winformsMap1.CurrentExtent = extent; 
                 winformsMap1.Refresh(); 


Hi Allen, 
  
 Thank you very much for the reply.  You were really giving the correct anwser.  Dhananjay, can you have a try. 
  
 Regards. 
 Johnny