Ejemplo n.º 1
0
        public Dictionary <TysonGeoPoint, List <TysonGeoPoint> > Build(
            List <TysonGeoPoint> points,
            double[] envelope)
        {
            Envelope = envelope;

            var ge = VoronoiBuilder.BuildLine(points, envelope);

            //x→,y↑
            _lbPt = new TysonGeoPoint(Envelope[0], Envelope[1]);
            _ltPt = new TysonGeoPoint(Envelope[0], Envelope[3]);

            _rbPt = new TysonGeoPoint(Envelope[2], Envelope[1]);
            _rtPt = new TysonGeoPoint(Envelope[2], Envelope[3]);


            var pointWithLines
                = new Dictionary <int, List <GraphEdge> >();
            var edgeLines = new List <GraphEdge>();

            void SafeAddToDict(int pointIndex, GraphEdge edgeLine)
            {
                if (pointWithLines.ContainsKey(pointIndex))
                {
                    pointWithLines[pointIndex].Add(edgeLine);
                }
                else
                {
                    pointWithLines.Add(pointIndex,
                                       new List <GraphEdge>()
                    {
                        edgeLine
                    }
                                       );
                }
            }

            foreach (var graphEdge in ge)
            {
                SafeAddToDict(graphEdge.Point1Index, graphEdge);
                SafeAddToDict(graphEdge.Point2Index, graphEdge);

                edgeLines.Add(graphEdge);
            }

            //处理边界点
            EdgePointHandle(points, edgeLines, pointWithLines);


            //遍历所有的EdgeLine,生成Polygon

            var pointPolygonDict = new Dictionary <TysonGeoPoint, List <TysonGeoPoint> >();

            foreach (var kv in pointWithLines)
            {
                var edges      = kv.Value;
                var linearRing = BuildLinearRingWithEdgeLine(edges); //BuildLinearRing(edges);
                if (linearRing != null)
                {
                    pointPolygonDict.Add(
                        points[kv.Key],
                        linearRing
                        );
                }
            }

            return(pointPolygonDict);
        }
Ejemplo n.º 2
0
        public FeatureSet Analysis(IFeatureSet featureSet, double[] envelope = null)
        {
            if (featureSet.FeatureType != FeatureType.Point)
            {
                return(null);
            }

            var geoPoints =
                featureSet
                .Features
                .Select(e => (GeoPoint)(e
                                        .Geometry
                                        .BasicGeometry)
                        )
                .ToList();

            if (geoPoints.Count == 0)
            {
                return(null);
            }

            var firstPoint = geoPoints[0];

            envelope ??= new double[4]
            {
                firstPoint.X, firstPoint.Y, firstPoint.X, firstPoint.Y
            };

            if (envelope.Length != 4)
            {
                throw new Exception(nameof(envelope) + "的长度必须为4");
            }

            foreach (var geoPoint in geoPoints)
            {
                if (geoPoint.X < envelope[0])
                {
                    envelope[0] = geoPoint.X;
                }
                else if (geoPoint.X > envelope[2])
                {
                    envelope[2] = geoPoint.X;
                }

                if (geoPoint.Y < envelope[1])
                {
                    envelope[1] = geoPoint.Y;
                }
                else if (geoPoint.Y > envelope[3])
                {
                    envelope[3] = geoPoint.Y;
                }
            }

            envelope[0] -= EnvelopeEpsilon;
            envelope[1] -= EnvelopeEpsilon;
            envelope[2] += EnvelopeEpsilon;
            envelope[3] += EnvelopeEpsilon;

            var tysons = VoronoiBuilder
                         .BuildCellWithIndex(geoPoints, envelope);

            var originTables = featureSet.AttrTable;
            var originRows   = originTables.Rows;

            var polygonFeatureSet = new FeatureSet(FeatureType.Polygon);
            var attrTable         = originTables.Clone();
            var attrTableRows     = attrTable.Rows;
            var cols = attrTable.Columns.Count;

            foreach (var polygon in tysons)
            {
                IGeometry geometry = new Geometry(polygon.Value);
                polygonFeatureSet.Features.Add(new CoreSpatial.Feature(geometry));
                var newRow = attrTable.NewRow();
                var oldRow = originRows[polygon.Key];
                for (int i = 0; i < cols; i++)
                {
                    newRow[i] = oldRow[i];
                }
                attrTableRows.Add(newRow);
            }

            polygonFeatureSet.AttrTable = attrTable;

            return(polygonFeatureSet);
        }