private LineString getLinearizedArc(
            Circle c, double startAngle, double midAngle, double endAngle)
        {
            Arc arc        = c.GetArc(startAngle, midAngle, endAngle);
            var Linearized = arc.Linearize(double.MaxValue, GeometryFactory).ToArray();

            Coordinate[] coords = new Coordinate[Linearized.Length];
            for (int i = 0; i < coords.Length; i++)
            {
                var vec = Linearized[i];
                coords[i] = new Coordinate(vec.X, vec.Y);
            }
            CoordinateArraySequence cs = new CoordinateArraySequence(coords);

            return(new LineString(cs, new GeometryFactory()));
        }
예제 #2
0
        } // End Function TransformIntoPointGeometryCollection

        // Transform into GeometryCollection.
        // @param geom input geometry
        // @return a geometry collection
        private static GeometryCollection TransformIntoPointGeometryCollection(GeometryCollection gc)
        {
            Utilities.UniqueCoordinateArrayFilter filter = new Utilities.UniqueCoordinateArrayFilter();
            gc.Apply(filter);
            Coordinate[] coord = filter.Coordinates;

            Geometry[] geometries = new Geometry[coord.Length];
            for (int i = 0; i < coord.Length; i++)
            {
                Coordinate[]            c  = new Coordinate[] { coord[i] };
                CoordinateArraySequence cs = new CoordinateArraySequence(c);
                geometries[i] = new Point(cs, gc.Factory);
            } // Next i

            return(new GeometryCollection(geometries, gc.Factory));
        } // End Function TransformIntoPointGeometryCollection
예제 #3
0
        /// <summary>
        ///     Converts a Microsoft.Spatial GeographyPolygon to a Polygon.
        /// </summary>
        /// <param name="geographyPolygon">The Microsoft.Spatial GeographyPolygon.</param>
        /// <returns></returns>
        public static Polygon ToNtsPolygon(this GeographyPolygon geographyPolygon)
        {
            if (geographyPolygon == null)
            {
                return(null);
            }

            var coords = new List <Coordinate>();

            foreach (var ring in geographyPolygon.Rings)
            {
                foreach (var coord in ring.Points)
                {
                    coords.Add(new Coordinate(coord.Longitude, coord.Latitude));
                }
            }

            var geomFactory = new GeometryFactory(new PrecisionModel(), 4326);

            coords.RemoveAt(coords.Count - 1);
            //coords.Sort(new CoordinateComparer(CalculateCentre(coords)));
            var first = coords.First();

            coords.Add(new Coordinate(first.X, first.Y));
            var sequence = new CoordinateArraySequence(coords.ToArray());
            var poly     = new Polygon(
                new LinearRing(sequence, geomFactory),
                geomFactory);

            // Reverse if this is counter clock-wise
            if (poly.Shell.IsCCW)
            {
                poly.Shell.Reverse();
            }
            return(poly);
        }