Represents the polygon geometry.
Inheritance: Geometry
示例#1
0
        internal static void LoadWkt(this Polygon polygon, string wkt)
        {
            var json = wkt.ToJson("MULTIPOLYGON");

            polygon.rings = json == null ? new double[][][] { } : json.Deserialize <double[][][][]>().SelectMany(p => p).ToArray();
        }
示例#2
0
        /// <summary>
        /// Creates a new polygon from well-known text (WKT).
        /// </summary>
        /// <param name="wkt"></param>
        /// <returns></returns>
        public static Polygon FromWkt(string wkt)
        {
            if (wkt == null)
                return null;

            var polygon = new Polygon();
            polygon.LoadWkt(wkt);
            return polygon;
        }
示例#3
0
        /// <summary>
        /// Determines if the polygon is inside the other polygon.
        /// </summary>
        /// <param name="polygon1"></param>
        /// <param name="polygon2"></param>
        /// <returns></returns>
        public static bool Within(this Polygon polygon1, Polygon polygon2)
        {
            if (Null(polygon1, polygon2))
                return false;

            return polygon2.Contains(polygon1);
        }
示例#4
0
        /// <summary>
        /// Determines if the point is within the specified distance from the polygon.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="polygon"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static bool WithinDistance(this Point point, Polygon polygon, double distance)
        {
            if (Null(point, polygon))
                return false;

            return point.Extent().Buffer(distance).Intersects(polygon.Extent()) && point.Distance(polygon) < distance;
        }
示例#5
0
        /// <summary>
        /// Determines if the multipoint is inside the polygon.
        /// </summary>
        /// <param name="multipoint"></param>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static bool Within(this Multipoint multipoint, Polygon polygon)
        {
            if (Null(multipoint, polygon))
                return false;

            return polygon.Contains(multipoint);
        }
示例#6
0
        /// <summary>
        /// Determines if the polyline is inside the polygon.
        /// </summary>
        /// <param name="polyline"></param>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static bool Within(this Polyline polyline, Polygon polygon)
        {
            if (Null(polyline, polygon))
                return false;

            return polygon.Contains(polyline);
        }
示例#7
0
 /// <summary>
 /// Determines if the polygon intersects the other polygon.
 /// </summary>
 /// <param name="polygon1"></param>
 /// <param name="polygon2"></param>
 /// <returns></returns>
 public static bool Intersects(this Polygon polygon1, Polygon polygon2)
 {
     return new Polyline { paths = polygon1.rings }.Intersects(new Polyline { paths = polygon2.rings });
 }
示例#8
0
        /// <summary>
        /// Determines if the point is inside the polygon.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static bool Within(this Point point, Polygon polygon)
        {
            if (Null(point, polygon))
                return false;

            return polygon.Contains(point);
        }
示例#9
0
        /// <summary>
        /// Calculates the distance to the other polygon.
        /// </summary>
        /// <param name="polygon1"></param>
        /// <param name="polygon2"></param>
        /// <returns></returns>
        public static double Distance(this Polygon polygon1, Polygon polygon2)
        {
            AssertNotNull(polygon1, polygon2);

            if (polygon1.Equals(polygon2))
                return 0;

            if (polygon1.Intersects(polygon2))
                return 0;

            if (polygon1.Within(polygon2))
                return 0;

            if (polygon2.Within(polygon1))
                return 0;

            return Math.Min(polygon1.rings.Distance(polygon2.rings), polygon2.rings.Distance(polygon1.rings));
        }
示例#10
0
 /// <summary>
 /// Determines if the polyline intersects the polygon.
 /// </summary>
 /// <param name="polyline"></param>
 /// <param name="polygon"></param>
 /// <returns></returns>
 public static bool Intersects(this Polyline polyline, Polygon polygon)
 {
     return polyline.Intersects(new Polyline { paths = polygon.rings });
 }
示例#11
0
        /// <summary>
        /// Calculates the shortest distance to the polygon.
        /// </summary>
        /// <param name="polyline"></param>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static double Distance(this Polyline polyline, Polygon polygon)
        {
            AssertNotNull(polyline, polygon);

            if (polyline.Intersects(polygon))
                return 0;

            if (polyline.Within(polygon))
                return 0;

            return Math.Min(polyline.paths.Distance(polygon.rings), polygon.rings.Distance(polyline.paths));
        }
示例#12
0
        /// <summary>
        /// Calculates the shortest distance to the polygon.
        /// </summary>
        /// <param name="multipoint"></param>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static double Distance(this Multipoint multipoint, Polygon polygon)
        {
            AssertNotNull(multipoint, polygon);

            return multipoint.points.Min(p => new Point(p[0], p[1]).Distance(polygon));
        }
示例#13
0
        /// <summary>
        /// Calculates the shortest distance to the polygon.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static double Distance(this Point point, Polygon polygon)
        {
            AssertNotNull(point, polygon);

            if (polygon.Contains(point))
                return 0;

            return point.Distance(polygon.rings);
        }
示例#14
0
        /// <summary>
        /// Determines if the polygon completely contains the other polygon.
        /// </summary>
        /// <param name="polygon1"></param>
        /// <param name="polygon2"></param>
        /// <returns></returns>
        public static bool Contains(this Polygon polygon1, Polygon polygon2)
        {
            if (Null(polygon1, polygon2))
                return false;

            return !polygon1.Intersects(polygon2) && polygon2.rings.All(polygon1.Contains);
        }
示例#15
0
        /// <summary>
        /// Determines if the polygon is within the specified distance from the other polygon.
        /// </summary>
        /// <param name="polygon1"></param>
        /// <param name="polygon2"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static bool WithinDistance(this Polygon polygon1, Polygon polygon2, double distance)
        {
            if (Null(polygon1, polygon2))
                return false;

            return polygon1.Extent().Buffer(distance).Intersects(polygon2.Extent()) && polygon1.Distance(polygon2) < distance;
        }