Пример #1
0
        public static IEnumerable<OCM.API.Common.LatLon> SearchPolygonFromPolyLine(List<OCM.API.Common.LatLon> points, double distanceKM)
        {
            //http://dotspatial.codeplex.com/wikipage?title=CycleThroughVerticesCS&referringTitle=Desktop_SampleCode

            //create feature set from points
            Feature f = new Feature();
            FeatureSet fs = new FeatureSet(f.FeatureType);

            Coordinate[] coord = new Coordinate[points.Count];
            for (int i = 0; i < points.Count; i++)
            {
                coord[i] = new Coordinate((double)points[i].Latitude, (double)points[i].Longitude);
            }
            LineString ls = new LineString(coord);
            f = new Feature(ls);
            fs.Features.Add(f);
            fs.Buffer(distanceKM, false); //TODO: approx km to lat/long coord value
            IFeatureSet iF = fs.Buffer(10, true);

            //export polygon points
            List<OCM.API.Common.LatLon> polyPoints = new List<OCM.API.Common.LatLon>();
            Extent extent = new Extent(-180, -90, 180, 90);
            foreach (ShapeRange shape in fs.ShapeIndices)
            {
                if (shape.Intersects(extent))
                    foreach (PartRange part in shape.Parts)
                    {
                        foreach (Vertex vertex in part)
                        {
                            if (vertex.X > 0 && vertex.Y > 0)
                            {
                                // prepare export of polygon points
                                Console.WriteLine(vertex.X);
                                polyPoints.Add(new OCM.API.Common.LatLon { Latitude = vertex.X, Longitude = vertex.Y });
                            }
                        }
                    }
            }

            return polyPoints;
        }