コード例 #1
0
ファイル: Map.cs プロジェクト: SDRC-India/sdrcdevinfo
        public Layer CreateBufferLayer(Layer SrcLayer, float BufferRadius)
        {
            int i;
            Layer BufferLayer = new Layer();
            Shape SrcShape;
            IDictionaryEnumerator dicEnumerator = SrcLayer.GetRecords(SrcLayer.LayerPath + "\\" + SrcLayer.ID).GetEnumerator();
            switch (SrcLayer.LayerType)
            {
                case ShapeType.Point:
                case ShapeType.PointCustom:
                case ShapeType.PointFeature:
                    GraphicsPath TempGp = new GraphicsPath();
                    PointF Pt;
                    while (dicEnumerator.MoveNext())
                    {
                        Shape TempShp = new Shape();
                        SrcShape = (Shape)dicEnumerator.Value;
                        Pt = (PointF)SrcShape.Parts[0];
                        TempShp.AreaId = SrcShape.AreaId;
                        TempShp.AreaName = SrcShape.AreaName;
                        TempShp.Centroid = Pt;
                        PointF[] Pts = GetPointBuffer(Pt, BufferRadius);

                        TempGp.Reset();
                        TempGp.AddPolygon(Pts);
                        TempShp.Extent = TempGp.GetBounds();

                        TempShp.Parts.Add(Pts);
                        BufferLayer.Records.Add(TempShp.AreaId, TempShp);

                        if (BufferLayer.Extent.IsEmpty)
                        {
                            BufferLayer.Extent = TempShp.Extent;
                        }
                        else
                        {
                            BufferLayer.Extent = RectangleF.Union(BufferLayer.Extent, TempShp.Extent);
                        }

                        TempShp = null;
                    }

                    TempGp.Dispose();
                    break;

                case ShapeType.PolyLine:
                case ShapeType.PolyLineCustom:
                case ShapeType.PolyLineFeature:
                    TempGp = new GraphicsPath();
                    while (dicEnumerator.MoveNext())
                    {
                        Shape TempShp = new Shape();
                        SrcShape = (Shape)dicEnumerator.Value;
                        TempShp.AreaId = SrcShape.AreaId;
                        TempShp.AreaName = SrcShape.AreaName;
                        //TempShp.Centroid = SrcShape.Parts(j)
                        for (i = 0; i <= SrcShape.Parts.Count - 1; i++)
                        {
                            PointF[] Pts = (PointF[])SrcShape.Parts[i];
                            PointF[] PolyPts = GetLineBuffer(Pts, BufferRadius);
                            TempShp.Centroid = Pts[(int)Pts.Length / 2];
                            TempShp.Parts.Add(PolyPts);

                            TempGp.Reset();
                            TempGp.AddPolygon(PolyPts);

                            if (TempShp.Extent.IsEmpty)
                            {
                                TempShp.Extent = TempGp.GetBounds();
                            }
                            else
                            {
                                TempShp.Extent = RectangleF.Union(TempShp.Extent, TempGp.GetBounds());
                            }

                            Pts = null;
                        }

                        BufferLayer.Records.Add(TempShp.AreaId, TempShp);

                        if (BufferLayer.Extent.IsEmpty)
                        {
                            BufferLayer.Extent = TempShp.Extent;
                        }
                        else
                        {
                            BufferLayer.Extent = RectangleF.Union(BufferLayer.Extent, TempShp.Extent);
                        }

                        TempShp = null;
                    }

                    TempGp.Dispose();
                    break;
            }
            BufferLayer.LayerType = ShapeType.PolygonBuffer;
            BufferLayer.FillColor = Color.FromArgb(40, 255, 0, 0);
            BufferLayer.BorderColor = Color.Transparent;
            return BufferLayer;
        }