ThinkGeo.com    |     Documentation    |     Premium Support

Desktop edition 3.0 version of GetExtentFromShapes?

In desktop edition 2.0 I could call the method Map.GetExtentFromShapes in order to calculate an extent for a map based on the extent of all the dynamic shapes.


What is the equivalent method for desktop edition 3.0? Let's say I want to use an InMemoryFeatureLayer and add some features to it (similar to the CSWpfHowDoISamples.EfficientlyMoveAPlaneImage.xaml.cs sample). Can I just open the layer, grab the bounding box, and use the bounding box to calculate an extent?



Gregory, 


You can implement this functionality very easily, try following code, and hope it helps.

        private RectangleShape ExpandRectangles(IEnumerable<BaseShape> sourceShapes)
        {
            RectangleShape resultShape = new RectangleShape();

            foreach (BaseShape sourceShape in sourceShapes)
            {
                resultShape.ExpandToInclude(sourceShape.GetBoundingBox());
            }

            return resultShape;
        }

        private RectangleShape ExpandRectangles(IEnumerable<Feature> sourceFeatures)
        {
            RectangleShape resultShape = new RectangleShape();

            foreach (Feature sourceFeature in sourceFeatures)
            {
                resultShape.ExpandToInclude(sourceFeature.GetBoundingBox());
            }

            return resultShape;
        }\

 

Any more questions please feel free to let me know.
 
Thanks.
 
Yale


Thanks for the answer, Yale. I had to make a slight change to your approach (which you'll see below). The reason for the changes is that if I simply construct a new instance of RectangleShape and try to extend it, the lower right point keeps the uninitialized values and as a result the rectangle is not valid. Let me know what you think!



 



private static RectangleShape ExpandRectangles(List<BaseShape> sourceShapes)RectangleShape resultShape = sourceShapes[0].GetBoundingBox();foreach (BaseShape sourceShape in sourceShapes)return resultShape;


{


 


 


{


resultShape.ExpandToInclude(sourceShape.GetBoundingBox());


}


 


}



Gregory, 
  
 I think the result should be the same. Which version is your using now? I think we have fixed this problem at least in the latest public release 3.0.362. 
  
 Any more questions please feel free to let me know. 
  
 Thanks. 
  
 Yale