Add padding to the Extents of a Graphic Collection

662
1
09-25-2012 01:23 PM
MuralidharMoka
New Contributor II
We wanted to add some padding to the Extents to the Collection of Graphics
We send the Collection and % to pad.
Was interested in knowing if this is the correct way of doing it. Does this always work in any coordinate system.

       public static Envelope GetExtentsForGraphicCollection(GraphicCollection gc, double percentToPadEnvelope)
        {
            double? minX = null;
            double? minY = null;
            double? maxX = null;
            double? maxY = null;

            foreach (Graphic g in gc)
            {
                double tempMinX = Convert.ToDouble(g.Attributes["MIN_X"]);
                double tempMinY = Convert.ToDouble(g.Attributes["MIN_Y"]);
                double tempMaxX = Convert.ToDouble(g.Attributes["MAX_X"]);
                double tempMaxY = Convert.ToDouble(g.Attributes["MAX_Y"]);

                if (minX == null || tempMinX < minX)
                    minX = tempMinX;
                if (minY == null || tempMinY < minY)
                    minY = tempMinY;
                if (maxX == null || tempMaxX > maxX)
                    maxX = tempMaxX;
                if (maxY == null || tempMaxY > maxY)
                    maxY = tempMaxY;
            }
            double xPadding = (double)(maxX - minX) * percentToPadEnvelope;
            double yPadding = (double)(maxY - minY) * percentToPadEnvelope;

            minX = minX - xPadding;
            maxX = maxX + xPadding;
            minY = minY - yPadding;
            maxY = maxY + yPadding;


            return new Envelope((double)minX, (double)minY, (double)maxX, (double)maxY);
        }
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
We wanted to add some padding to the Extents to the Collection of Graphics


Once you get the extent of your graphics, you can also use the Envelope Expand method.
Nothing wrong in  your code though.
0 Kudos