An object that performs the conversion between objects and elliptical plane geometry by gnomonic projection.
        private ICollection <IGeography> calculateOverlay(IGeography geometry1, IGeography geometry2, OverlayType operation, bool p)
        {
            GeographyCollection egc = new GeographyCollection();

            egc.Add(geometry1);
            egc.Add(geometry2);

            GnomonicProjection projection = GeometrySpreader.GetProjection(egc);
            GeometryCollection gc         = GeometrySpreader.GetGeometries(egc, projection);

            OverlayCalculator       oc           = new OverlayCalculator();
            ICollection <IGeometry> planarResult = oc.CalculateOverlay(gc[0], gc[1], operation);

            egc = GeometrySpreader.GetGeographies(planarResult, projection);
            return(egc);
        }
示例#2
0
        private static Polygon getBoundsBuffer(GeoPolygon polygon, GnomonicProjection projection, double distance, int pointsPerCircle, bool allowParallels)
        {
            Polygon temp = new Polygon();

            List <Polygon>          partialBuffers      = new List <Polygon>();
            GeographyCollection     geographyCollection = new GeographyCollection();
            ICollection <IGeometry> unionResult         = null;

            int c = 0;

            foreach (GeoContour contour in polygon.Contours)
            {
                for (int i = 0; i < contour.Vertices.Count; i++)
                {
                    GeoPoint p = contour.Vertices[i];

                    GeoPolygon tempPolygon = getPointBuffer(p, Math.Abs(distance), pointsPerCircle);
                    geographyCollection.Clear();
                    geographyCollection.Add(tempPolygon);

                    GeometryCollection gc = GeometrySpreader.GetGeometries(geographyCollection, projection);
                    if (gc[0] is Polygon)
                    {
                        unionResult = temp.Union((Polygon)gc[0]);
                    }
                    if (unionResult.Count > 0)
                    {
                        temp = (Polygon)((GeometryCollection)unionResult)[0];
                    }

                    c++;
                    if (c == 3)
                    {
                        partialBuffers.Add(temp);
                        temp = new Polygon();
                        c    = 0;
                    }
                }
            }

            if (temp.CoordinateCount > 0)
            {
                partialBuffers.Add(temp);
            }

            return(mergePartialBuffers(partialBuffers, allowParallels));
        }
示例#3
0
        private static GeoPolygon getPolygonBuffer(GeoPolygon geoPolygon, double angleDistance, int pointsPerCircle, bool allowParallels)
        {
            geoPolygon = (GeoPolygon)geoPolygon.Clone();
            double minAngle = Math.Sin(Math.Abs(angleDistance)) * Math.Sin(Math.PI / pointsPerCircle);

            geoPolygon.ReduceSegments(minAngle);
            geoPolygon.Densify(minAngle);

            GnomonicProjection projection;
            IGeometry          geometry;

            projectGeography(geoPolygon, out projection, out geometry);
            Polygon planePolygon = (Polygon)geometry;

            Polygon boundaryBuffer = getBoundsBuffer(geoPolygon, projection, angleDistance, pointsPerCircle, allowParallels);

            ICollection <IGeometry> result;

            if (angleDistance > 0)
            {
                result = planePolygon.Union(boundaryBuffer);
            }
            else
            {
                result = planePolygon.Difference(boundaryBuffer);
            }

            GeographyCollection geographyCollection = GeometrySpreader.GetGeographies(result, projection);

            foreach (IGeography g in geographyCollection)
            {
                if (g is GeoPolygon)
                {
                    return((GeoPolygon)g);
                }
            }

            return(new GeoPolygon());
        }
示例#4
0
        private static void projectGeography(IGeography geography, out GnomonicProjection projection, out IGeometry geometry)
        {
            GeographyCollection geographyCollection = new GeographyCollection();

            geographyCollection.Add(geography);

            double centerLatitude, centerLongitude;

            GnomonicProjection.GetCenter(geography.ExtractPoints(), out centerLatitude, out centerLongitude);
            projection = new GnomonicProjection(centerLongitude, centerLatitude);

            GeometryCollection geometryCollection = GeometrySpreader.GetGeometries(geographyCollection, projection);

            if (geometryCollection.Count > 0)
            {
                geometry = geometryCollection[0];
            }
            else
            {
                geometry = null;
            }
        }
示例#5
0
        private static GeoPolygon getPointBuffer(GeoPoint point, double angleDistance, int pointsPerCircle)
        {
            if (angleDistance < 0)
            {
                return(new GeoPolygon());
            }

            GnomonicProjection projection   = new GnomonicProjection(point.L, point.Phi);
            PointD             planePoint   = new PointD(0, 0);
            Polygon            planePolygon = (Polygon)planePoint.Buffer(Math.Tan(angleDistance), pointsPerCircle, false);

            GeometryCollection geometryColllection = new GeometryCollection();

            geometryColllection.Add(planePolygon);
            GeographyCollection gc = GeometrySpreader.GetGeographies(geometryColllection, projection);

            if (gc[0] is GeoPolygon)
            {
                return((GeoPolygon)gc[0]);
            }

            return(new GeoPolygon());
        }
示例#6
0
        /// <summary>
        /// Computes a convex hull of the specified points.
        /// </summary>
        /// <param name="points">Enumerator of coordinates for which convex hull should be computed</param>
        /// <returns>A list containing a sequence of the convex hull points</returns>
        public static IList <GeoPoint> GetConvexHull(IEnumerable <GeoPoint> points)
        {
            GeographyCollection geographyCollection = new GeographyCollection();

            foreach (GeoPoint p in points)
            {
                geographyCollection.Add(p);
            }

            GnomonicProjection projection         = GeometrySpreader.GetProjection(geographyCollection);
            GeometryCollection geometryCollection = GeometrySpreader.GetGeometries(geographyCollection, projection);
            List <ICoordinate> list = new List <ICoordinate>();

            foreach (IGeometry g in geometryCollection)
            {
                list.Add(((PointD)g).Coordinate);
            }

            IList <ICoordinate> planarResult = PlanimetryAlgorithms.GetConvexHull(list);

            geometryCollection.Clear();
            foreach (ICoordinate p in planarResult)
            {
                geometryCollection.Add(new PointD(p));
            }

            geographyCollection = GeometrySpreader.GetGeographies(geometryCollection, projection);
            List <GeoPoint> result = new List <GeoPoint>();

            foreach (GeoPoint p in geographyCollection)
            {
                result.Add(p);
            }

            return(result);
        }
示例#7
0
        private static GeoPolygon getPolylineBuffer(GeoPolyline geoPolyline, double angleDistance, int pointsPerCircle, bool allowParallels)
        {
            geoPolyline = (GeoPolyline)geoPolyline.Clone();
            double minAngle = Math.Sin(Math.Abs(angleDistance)) * Math.Sin(Math.PI / pointsPerCircle);

            geoPolyline.ReduceSegments(minAngle);
            geoPolyline.Densify(minAngle);

            GnomonicProjection projection;
            IGeometry          geometry;

            projectGeography(geoPolyline, out projection, out geometry);
            Polyline            planePolyline       = (Polyline)geometry;
            GeographyCollection geographyCollection = new GeographyCollection();

            Polygon        temp           = new Polygon();
            List <Polygon> partialBuffers = new List <Polygon>();

            ICollection <IGeometry> unionResult = null;

            int c = 0;

            foreach (GeoPath path in geoPolyline.Paths)
            {
                for (int i = 0; i < path.Vertices.Count - 1; i++)
                {
                    GeoPoint p = path.Vertices[i];

                    GeoPolygon tempPolygon = getPointBuffer(p, angleDistance, pointsPerCircle);
                    geographyCollection.Clear();
                    geographyCollection.Add(tempPolygon);

                    GeometryCollection gc = GeometrySpreader.GetGeometries(geographyCollection, projection);
                    if (gc[0] is Polygon)
                    {
                        unionResult = temp.Union((Polygon)gc[0]);
                    }
                    if (unionResult.Count > 0)
                    {
                        temp = (Polygon)((GeometryCollection)unionResult)[0];
                    }

                    c++;
                    if (c == 3)
                    {
                        partialBuffers.Add(temp);
                        temp = new Polygon();
                        c    = 0;
                    }
                }
            }

            if (temp.CoordinateCount > 0)
            {
                partialBuffers.Add(temp);
            }

            Polygon            planeBuffer        = mergePartialBuffers(partialBuffers, allowParallels);
            GeometryCollection geometryCollection = new GeometryCollection();

            geometryCollection.Add(planeBuffer);
            geographyCollection = GeometrySpreader.GetGeographies(geometryCollection, projection);

            foreach (IGeography g in geographyCollection)
            {
                if (g is GeoPolygon)
                {
                    return((GeoPolygon)g);
                }
            }

            return(new GeoPolygon());
        }