internal static void LoadWkt(this Polyline polyline, string wkt) { var json = wkt.ToJson("MULTILINESTRING"); polyline.paths = json == null ? new double[][][] { } : json.Deserialize <double[][][]>(); }
/// <summary> /// Creates a new polyline from well-known text (WKT). /// </summary> /// <param name="wkt"></param> /// <returns></returns> public static Polyline FromWkt(string wkt) { if (wkt == null) return null; var polyline = new Polyline(); polyline.LoadWkt(wkt); return polyline; }
/// <summary> /// Determines if the polygon intersects the polyline. /// </summary> /// <param name="polygon"></param> /// <param name="polyline"></param> /// <returns></returns> public static bool Intersects(this Polygon polygon, Polyline polyline) { return new Polyline { paths = polygon.rings }.Intersects(polyline); }
/// <summary> /// Determines if the multipoint is within the specified distance from the polyline. /// </summary> /// <param name="multipoint"></param> /// <param name="polyline"></param> /// <param name="distance"></param> /// <returns></returns> public static bool WithinDistance(this Multipoint multipoint, Polyline polyline, double distance) { if (Null(multipoint, polyline)) return false; return multipoint.Extent().Buffer(distance).Intersects(polyline.Extent()) && multipoint.Distance(polyline) < distance; }
/// <summary> /// Returns intersection points between the two polylines. /// </summary> /// <param name="polyline1"></param> /// <param name="polyline2"></param> /// <returns></returns> public static Point[] Intersect(this Polyline polyline1, Polyline polyline2) { if (Null(polyline1, polyline2)) return new Point[] { }; return !polyline1.Extent().Intersects(polyline2.Extent()) ? new Point[] { } : Intersect(polyline1.paths, polyline2.paths); }
/// <summary> /// Determines if the polyline intersects the other polyline. /// </summary> /// <param name="polyline1"></param> /// <param name="polyline2"></param> /// <returns></returns> public static bool Intersects(this Polyline polyline1, Polyline polyline2) { return polyline1.Intersect(polyline2).Any(); }
/// <summary> /// Calculates the distance to the other polyline. /// </summary> /// <param name="polyline1"></param> /// <param name="polyline2"></param> /// <returns></returns> public static double Distance(this Polyline polyline1, Polyline polyline2) { AssertNotNull(polyline1, polyline2); if (polyline1.Equals(polyline2)) return 0; if (polyline1.Intersects(polyline2)) return 0; return Math.Min(polyline1.paths.Distance(polyline2.paths), polyline2.paths.Distance(polyline1.paths)); }
/// <summary> /// Calculates the shortest distance to the polyline. /// </summary> /// <param name="polygon"></param> /// <param name="polyline"></param> /// <returns></returns> public static double Distance(this Polygon polygon, Polyline polyline) { AssertNotNull(polygon, polyline); return polyline.Distance(polygon); }
/// <summary> /// Calculates the shortest distance to the polyline. /// </summary> /// <param name="multipoint"></param> /// <param name="polyline"></param> /// <returns></returns> public static double Distance(this Multipoint multipoint, Polyline polyline) { AssertNotNull(multipoint, polyline); return multipoint.points.Min(p => new Point(p[0], p[1]).Distance(polyline)); }
/// <summary> /// Calculates the shortest distance to the polyline. /// </summary> /// <param name="point"></param> /// <param name="polyline"></param> /// <returns></returns> public static double Distance(this Point point, Polyline polyline) { AssertNotNull(point, polyline); return point.Distance(polyline.paths); }
/// <summary> /// Determines if the polygon is within the specified distance from the polyline. /// </summary> /// <param name="polygon"></param> /// <param name="polyline"></param> /// <param name="distance"></param> /// <returns></returns> public static bool WithinDistance(this Polygon polygon, Polyline polyline, double distance) { if (Null(polygon, polyline)) return false; return polyline.Distance(polygon) < distance; }
/// <summary> /// Determines if the polygon completely contains the polyline. /// </summary> /// <param name="polygon"></param> /// <param name="polyline"></param> /// <returns></returns> public static bool Contains(this Polygon polygon, Polyline polyline) { if (Null(polygon, polyline)) return false; return !polygon.Intersects(polyline) && polyline.paths.All(polygon.Contains); }
/// <summary> /// Determines if the polyline is within the specified distance from the other polyline. /// </summary> /// <param name="polyline1"></param> /// <param name="polyline2"></param> /// <param name="distance"></param> /// <returns></returns> public static bool WithinDistance(this Polyline polyline1, Polyline polyline2, double distance) { if (Null(polyline1, polyline2)) return false; return polyline1.Extent().Buffer(distance).Intersects(polyline2.Extent()) && polyline1.Distance(polyline2) < distance; }