/// <summary> /// Creates a new instance of <see cref="Polygon"/> using serialization information. /// </summary> protected Polygon(SerializationInfo info, StreamingContext context) { var coordinates = (double[][][])info.GetValue("coordinates", typeof(double[][][])); Rings = AsReadOnlyCollection(coordinates .Select(r => (IList <Point>)r.Select(p => new Point(p[0], p[1])).ToList()) .ToList()); _ringsWithOrderedPoints = Rings.Select(r => (IList <Point>)r.OrderBy(p => p).ToList()).ToList(); }
/// <summary> /// Creates a new instance of <see cref="Polygon"/> using multiple rings. /// </summary> /// <param name="rings">The polygon rings</param> public Polygon(IList <IList <Point> > rings) { if (rings == null) { throw new ArgumentNullException("rings"); } Rings = AsReadOnlyCollection(rings, r => AsReadOnlyCollection(r)); _ringsWithOrderedPoints = Rings.Select(r => (IList <Point>)r.OrderBy(p => p).ToList()).ToList(); }
internal Polygon(JObject obj) { var coordinates = obj.GetValue("coordinates").ToObject <double[][][]>(); Rings = AsReadOnlyCollection(coordinates .Select(r => (IList <Point>)r.Select(p => new Point(p[0], p[1])).ToList()) .ToList()); _ringsWithOrderedPoints = Rings.Select(r => (IList <Point>)r.OrderBy(p => p).ToList()).ToList(); }
/// <summary> /// Returns Well-known text (WKT) representation of the geometry object. /// </summary> public override string ToString() { if (Rings.Count == 0) { return("POLYGON EMPTY"); } return(string.Format("POLYGON ({0})", string.Join(", ", Rings.Select(r => "(" + string.Join(", ", r.Select(p => p.X.ToString(CultureInfo.InvariantCulture) + " " + p.Y.ToString(CultureInfo.InvariantCulture))) + ")")))); }
private string PolygonToWkt() { if (!(Rings?.Length > 0)) { return("POLYGON EMPTY"); } else if (Rings.Length == 1) { return(FormattableString.Invariant($"POLYGON({EsriJsonHelper.PointArrayToString(Rings[0])})")); } else { return(FormattableString.Invariant($"MULTIPOLYGON({string.Join(", ", Rings.Select(i => $"({EsriJsonHelper.PointArrayToString(i)})"))})")); } }
/// <summary> /// Returns the hash code based on the value of this instance. /// </summary> public override int GetHashCode() { // ReSharper disable once NonReadonlyMemberInGetHashCode return(CombineHashCode(Rings.Select(r => CombineHashCode(r.Select(p => p.GetHashCode()))))); }