Пример #1
0
        /// <summary>
        /// Converts a collection of geometric shapes on the surface of the ellipsoid
        /// to the collection of geometric figures in the plane according to the given gnomonic projection.
        /// </summary>
        /// <param name="collection">Collection of geometric shapes on the surface of the ellipsoid</param>
        /// <param name="projection">Projection</param>
        /// <returns>Collection of geometric figures in the plane</returns>
        public static GeometryCollection GetGeometries(GeographyCollection collection, GnomonicProjection projection)
        {
            GeometryCollection result   = new GeometryCollection();
            IGeometry          geometry = null;

            foreach (IGeography geography in collection)
            {
                if (geography is GeoPoint)
                {
                    geometry = projectPoint((GeoPoint)geography, projection);
                }
                else if (geography is GeoPolyline)
                {
                    geometry = projectPolyline((GeoPolyline)geography, projection);
                }
                else if (geography is GeoPolygon)
                {
                    geometry = projectPolygon((GeoPolygon)geography, projection);
                }
                else if (geography is GeoMultiPoint)
                {
                    geometry = projectMultiPoint((GeoMultiPoint)geography, projection);
                }
                else
                {
                    throw new NotImplementedException("Geometry \"" + geography.GetType().FullName + "\" is not supported.");
                }

                result.Add(geometry);
            }

            return(result);
        }
Пример #2
0
        public void BuildCollection()
        {
            GeographyCollection c = GeographyFactory.Collection(NonDefaultGeographicCoords)
                                    .MultiPoint().Point(5, 5).Point(10, 10)
                                    .LineString(0, 0).LineTo(0, 5)
                                    .MultiPolygon()
                                    .Polygon().Ring(-5, -5).LineTo(0, -5).LineTo(0, -2)
                                    .Polygon().Ring(-10, -10).LineTo(-5, -10).LineTo(-5, -7)
                                    .Collection()
                                    .Point(5, 5);

            Assert.AreEqual(NonDefaultGeographicCoords, c.CoordinateSystem);
            c.VerifyAsCollection(
                (mp) => mp.VerifyAsMultiPoint(new PositionData(5, 5), new PositionData(10, 10)),
                (ls) => ls.VerifyAsLineString(new PositionData(0, 0), new PositionData(0, 5)),
                (mp) => mp.VerifyAsMultiPolygon(
                    new PositionData[][] {
                new PositionData[] { new PositionData(-5, -5), new PositionData(0, -5), new PositionData(0, -2), new PositionData(-5, -5) }
            },
                    new PositionData[][]                {
                new PositionData[] { new PositionData(-10, -10), new PositionData(-5, -10), new PositionData(-5, -7), new PositionData(-10, -10) }
            }),
                (col) => col.VerifyAsCollection(
                    (p) => p.VerifyAsPoint(new PositionData(5, 5))));

            c = GeographyFactory.Collection();
            c.VerifyAsCollection(null);
        }
Пример #3
0
        /// <summary>
        /// Converts a collection of geometric shapes on the surface of the ellipsoid
        /// to the collection of geometric figures in the plane in line with the given projection.
        /// </summary>
        /// <param name="geometries">Enumerator geometric shapes on the surface of the ellipsoid</param>
        /// <param name="projection">Projection</param>
        /// <returns>Collection of geometric figures in the plane</returns>
        public static GeographyCollection GetGeographies(IEnumerable <IGeometry> geometries, GnomonicProjection projection)
        {
            GeographyCollection result   = new GeographyCollection();
            IGeography          geometry = null;

            foreach (IGeometry g in geometries)
            {
                if (g is PointD)
                {
                    geometry = unprojectPoint((PointD)g, projection);
                }
                else if (g is Polyline)
                {
                    geometry = unprojectPolyline((Polyline)g, projection);
                }
                else if (g is Polygon)
                {
                    geometry = unprojectPolygon((Polygon)g, projection);
                }
                else if (g is MultiPoint)
                {
                    geometry = unprojectMultiPoint((MultiPoint)g, projection);
                }
                else
                {
                    throw new NotImplementedException("Geometry \"" + g.GetType().FullName + "\" is not supported.");
                }

                result.Add(geometry);
            }

            return(result);
        }
        private static void WriteGeographyCollection(JsonWriter writer, GeographyCollection geographyCollection)
        {
            writer.WriteStartArray();

            foreach (var geography in geographyCollection.Geographies)
            {
                WriteGeography(writer, geography);
            }

            writer.WriteEndArray();
        }
Пример #5
0
        protected override async Task _init(GeographyCollection layer)
        {
            SimpleMeshBuilder meshes = await loadObj(layer.Source);

            features  = meshes.Meshes;
            symbology = layer.Properties.Units;

            Color col = symbology.ContainsKey("point") ? (Color)symbology["point"].Color : Color.white;
            Color sel = symbology.ContainsKey("point") ? new Color(1 - col.r, 1 - col.g, 1 - col.b, col.a) : Color.red;

            mainMat = Instantiate(HandleMaterial);
            mainMat.SetColor("_BaseColor", col);
            selectedMat = Instantiate(HandleMaterial);
            selectedMat.SetColor("_BaseColor", sel);
        }
        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);
        }
Пример #7
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));
        }
Пример #8
0
        /// <summary>
        /// Calculates gnomonic projection for geometric shapes on the surface of the ellipsoid.
        /// </summary>
        /// <param name="collection">Collection of geometric shapes on the surface of the ellipsoid</param>
        /// <returns>Gnomonic projection</returns>
        public static GnomonicProjection GetProjection(GeographyCollection collection)
        {
            List <GeoPoint> points = new List <GeoPoint>();

            foreach (IGeography g in collection)
            {
                GeoPoint[] pts = g.ExtractPoints();
                foreach (GeoPoint p in pts)
                {
                    points.Add(p);
                }
            }
            double centerLat = 0;
            double centerLon = 0;

            GnomonicProjection.GetCenter(points, out centerLat, out centerLon);
            return(new GnomonicProjection(centerLon, centerLat));
        }
Пример #9
0
        private static void WriteGeography(
            Utf8JsonWriter writer,
            GeographyCollection geography)
        {
            writer.WriteStartObject();

            writer.WriteString(s_TypePropertyNameBytes, GeoJsonConstants.GeometryCollectionTypeName);

            writer.WriteStartArray(s_GeometriesPropertyNameBytes);

            foreach (Geography child in geography.Geographies)
            {
                WriteGeography(writer, child);
            }

            writer.WriteEndArray();

            writer.WriteEndObject();
        }
Пример #10
0
        static ODataSpatialTypeUtil()
        {
            // Geometry type values.
            GeometryValue                = GeometryFactory.Point(32.0, -10.0).Build();
            GeometryPointValue           = GeometryFactory.Point(33.1, -11.0).Build();
            GeometryLineStringValue      = GeometryFactory.LineString(33.1, -11.5).LineTo(35.97, -11).Build();
            GeometryPolygonValue         = GeometryFactory.Polygon().Ring(33.1, -13.6).LineTo(35.97, -11.15).LineTo(11.45, 87.75).Ring(35.97, -11).LineTo(36.97, -11.15).LineTo(45.23, 23.18).Build();
            GeometryCollectionValue      = GeometryFactory.Collection().Point(-19.99, -12.0).Build();
            GeometryMultiPointValue      = GeometryFactory.MultiPoint().Point(10.2, 11.2).Point(11.9, 11.6).Build();
            GeometryMultiLineStringValue = GeometryFactory.MultiLineString().LineString(10.2, 11.2).LineTo(11.9, 11.6).LineString(16.2, 17.2).LineTo(18.9, 19.6).Build();
            GeometryMultiPolygonValue    = GeometryFactory.MultiPolygon().Polygon().Ring(10.2, 11.2).LineTo(11.9, 11.6).LineTo(11.45, 87.75).Ring(16.2, 17.2).LineTo(18.9, 19.6).LineTo(11.45, 87.75).Build();

            // Geography type values.
            GeographyValue                = GeographyFactory.Point(32.0, -100.0).Build();
            GeographyPointValue           = GeographyFactory.Point(33.1, -110.0).Build();
            GeographyLineStringValue      = GeographyFactory.LineString(33.1, -110.0).LineTo(35.97, -110).Build();
            GeographyPolygonValue         = GeographyFactory.Polygon().Ring(33.1, -110.0).LineTo(35.97, -110.15).LineTo(11.45, 87.75).Ring(35.97, -110).LineTo(36.97, -110.15).LineTo(45.23, 23.18).Build();
            GeographyCollectionValue      = GeographyFactory.Collection().Point(-19.99, -12.0).Build();
            GeographyMultiPointValue      = GeographyFactory.MultiPoint().Point(10.2, 11.2).Point(11.9, 11.6).Build();
            GeographyMultiLineStringValue = GeographyFactory.MultiLineString().LineString(10.2, 11.2).LineTo(11.9, 11.6).LineString(16.2, 17.2).LineTo(18.9, 19.6).Build();
            GeographyMultiPolygonValue    = GeographyFactory.MultiPolygon().Polygon().Ring(10.2, 11.2).LineTo(11.9, 11.6).LineTo(11.45, 87.75).Ring(16.2, 17.2).LineTo(18.9, 19.6).LineTo(11.45, 87.75).Build();
        }
Пример #11
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());
        }
Пример #12
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;
            }
        }
Пример #13
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());
        }
Пример #14
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);
        }
Пример #15
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();
        }
Пример #16
0
        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;
        }
Пример #17
0
        /// <summary>
        /// Converts a collection of geometric shapes on the surface of the ellipsoid 
        /// to the collection of geometric figures in the plane according to the given gnomonic projection.
        /// </summary>
        /// <param name="collection">Collection of geometric shapes on the surface of the ellipsoid</param>
        /// <param name="projection">Projection</param>
        /// <returns>Collection of geometric figures in the plane</returns>
        public static GeometryCollection GetGeometries(GeographyCollection collection, GnomonicProjection projection)
        { 
            GeometryCollection result = new GeometryCollection();
            IGeometry geometry = null;
            foreach (IGeography geography in collection)
            {
                if (geography is GeoPoint)
                {
                    geometry = projectPoint((GeoPoint)geography, projection);
                }
                else if (geography is GeoPolyline)
                {
                    geometry = projectPolyline((GeoPolyline)geography, projection);
                }
                else if (geography is GeoPolygon)
                {
                    geometry = projectPolygon((GeoPolygon)geography, projection);
                }
                else if (geography is GeoMultiPoint)
                {
                    geometry = projectMultiPoint((GeoMultiPoint)geography, projection);
                }
                else
                    throw new NotImplementedException("Geometry \"" + geography.GetType().FullName + "\" is not supported.");

                result.Add(geometry);
            }

            return result;
        }
Пример #18
0
        /// <summary>
        /// Converts a collection of geometric shapes on the surface of the ellipsoid 
        /// to the collection of geometric figures in the plane in line with the given projection.
        /// </summary>
        /// <param name="geometries">Enumerator geometric shapes on the surface of the ellipsoid</param>
        /// <param name="projection">Projection</param>
        /// <returns>Collection of geometric figures in the plane</returns>
        public static GeographyCollection GetGeographies(IEnumerable<IGeometry> geometries, GnomonicProjection projection)
        {
            GeographyCollection result = new GeographyCollection();
            IGeography geometry = null;
            foreach (IGeometry g in geometries)
            {
                if (g is PointD)
                {
                    geometry = unprojectPoint((PointD)g, projection);
                }
                else if (g is Polyline)
                {
                    geometry = unprojectPolyline((Polyline)g, projection);
                }
                else if (g is Polygon)
                {
                    geometry = unprojectPolygon((Polygon)g, projection);
                }
                else if (g is MultiPoint)
                {
                    geometry = unprojectMultiPoint((MultiPoint)g, projection);
                }
                else
                    throw new NotImplementedException("Geometry \"" + g.GetType().FullName + "\" is not supported.");

                result.Add(geometry);
            }

            return result;
        }
Пример #19
0
 /// <summary>
 /// Calculates gnomonic projection for geometric shapes on the surface of the ellipsoid.
 /// </summary>
 /// <param name="collection">Collection of geometric shapes on the surface of the ellipsoid</param>
 /// <returns>Gnomonic projection</returns>
 public static GnomonicProjection GetProjection(GeographyCollection collection)
 {
     List<GeoPoint> points = new List<GeoPoint>();
     foreach (IGeography g in collection)
     {
         GeoPoint[] pts = g.ExtractPoints();
         foreach (GeoPoint p in pts)
             points.Add(p);
     }
     double centerLat = 0;
     double centerLon = 0;
     GnomonicProjection.GetCenter(points, out centerLat, out centerLon);
     return new GnomonicProjection(centerLon, centerLat);
 }
Пример #20
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;
        }
Пример #21
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;
        }
Пример #22
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());
        }
Пример #23
0
        private static GeographyFactory <GeographyCollection> Add(this GeographyFactory <GeographyCollection> factory, GeographyCollection geographyCollection)
        {
            factory = factory.Collection();

            foreach (Geography geography in geographyCollection.Geographies)
            {
                factory = factory.Add(geography);
            }

            return(factory);
        }
Пример #24
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);
        }