示例#1
0
 public static PolylineBag2 <double> BuildMultiLineString(PositionSet ps)
 {
     try
     {
         if (ps != null)
         {
             if (ps.Positions.Count > 0)
             {
                 List <Polyline2 <double> > list = new List <Polyline2 <double> >();
                 foreach (Position position in ps.Positions)
                 {
                     Polyline2 <double> lineString = BuildLineString(position as PositionSet);
                     if (lineString == null)
                     {
                         return(null);
                     }
                     list.Add(lineString);
                 }
                 if (list.Count > 0)
                 {
                     return(factory.ConstructPolylineBag(list));
                 }
             }
         }
     }
     catch
     {
     }
     return(null);
 }
示例#2
0
        public override PolylineSet2 <double> ConstructPolylineSet(Polyline2 <double>[] chains)
        {
            if (chains == null || chains.Length < 1)
            {
                return(null);
            }

            Polyline2 <double>[]      Chains = new Polyline2 <double> [chains.Length];
            Polyline2 <double>        ch;
            PlanarChainGraph <double> graph = new PlanarChainGraph <double>();

            for (int i = 0; i < Chains.Length; i++)
            {
                ch = chains[i];
                if (ch == null)
                {
                    return(null); //can't have null chains
                }
                Chains[i] = ch;
                graph.Add(new LineChain2 <double>(ch.Points)); //TODO -- fix this, it's broken
            }
            if (PlanarGraphUtils.AnyIntersections(graph))      //there must be overlap
            {
                return(null);
            }

            return(new PolylineSet2 <double>(Chains));
        }
示例#3
0
 //Trusted constructor -- uses array directly -- no nulls!
 internal Polyline2(Polyline2 <T> other, bool isReversed)
 {
     if (other == null)
     {
         throw new ArgumentNullException();
     }
     this.Points     = other.Points;
     this.IsReversed = isReversed;
 }
示例#4
0
 public Polyline2(Polyline2 <T> other)
 {
     if (other == null)
     {
         throw new ArgumentNullException();
     }
     this.Points     = other.Points;
     this.IsReversed = other.IsReversed;
 }
示例#5
0
 public int CompareTo(Polyline2 <T> other)
 {
     if (other == null)
     {
         return(1);
     }
     if (object.ReferenceEquals(this, other))
     {
         return(0);
     }
     if (object.ReferenceEquals(this.Points, other.Points))
     {
         return(0);
     }
     return(this.Envelope.CompareTo(other.Envelope));
 }
示例#6
0
 public static string ToWkt(Polyline2 <double> geom)
 {
     if (geom != null)
     {
         StringBuilder sb = new StringBuilder();
         sb.Append("LINESTRING(");
         for (uint i = 0; i < geom.VertexCount; i++)
         {
             sb.Append(geom[i].X);
             sb.Append(' ');
             sb.Append(geom[i].Y);
             sb.Append(',');
         }
         sb[sb.Length - 1] = ')';
         return(sb.ToString());
     }
     return(string.Empty);
 }
示例#7
0
 public bool Equals(Polyline2 <T> other)
 {
     if (other == null)
     {
         return(false);
     }
     if (object.ReferenceEquals(this, other))
     {
         return(true); //cheat for memory eqivalence
     }
     if (object.ReferenceEquals(this.Points, other.Points))
     {
         return(true);
     }
     if (this.Points.Length != other.Points.Length)
     {
         return(false);
     }
     if (this.IsReversed == other.IsReversed)
     {
         for (int i = 0; i < this.Points.Length; i++)
         {
             if (!this.Points[i].Equals(other.Points[i]))
             {
                 return(false);
             }
         }
     }
     else
     {
         int le = this.Points.Length - 1;
         for (int i = 0; i < this.Points.Length; i++)
         {
             if (!this.Points[i].Equals(other.Points[le - i]))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#8
0
 public bool EqualsNonDirectional(Polyline2 <T> other)
 {
     if (other == null)
     {
         return(false);
     }
     if (object.ReferenceEquals(this, other))
     {
         return(true); //cheat for memory eqivalence
     }
     if (this.Points.Length != other.Points.Length)
     {
         return(false);
     }
     if (this.Points[0].Equals(other.Points[0])) //forward compare
     {
         for (int i = 0; i < this.Points.Length; i++)
         {
             if (!this.Points[i].Equals(other.Points[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
     else if (this.Points[this.Points.Length - 1].Equals(other.Points[0])) //reverse compare
     {
         int id = this.Points.Length - 1;
         for (int i = 0; i < this.Points.Length; i++)
         {
             if (!this.Points[id - i].Equals(other.Points[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
示例#9
0
        public static JObject ToGeoJson(Polyline2 <double> geom)
        {
            if (geom == null)
            {
                return((JObject)null);
            }
            JObject jobject = new JObject();

            jobject.Add("type", (JToken) new JValue("LineString"));
            JArray jarray = new JArray();

            foreach (Point2 <double> n in geom)
            {
                jarray.Add((JToken) new JArray()
                {
                    (JToken) new JValue(n.X),
                    (JToken) new JValue(n.Y)
                });
            }
            jobject.Add("coordinates", (JToken)jarray);
            return(jobject);
        }
示例#10
0
 public PolylineBag2 <T> ConstructPolylineBag(IList <Point2 <T> >[] chains)
 {
     if (chains != null)
     {
         List <Polyline2 <T> > constructed = new List <Polyline2 <T> >();
         foreach (Point2 <T>[] ch in chains)
         {
             if (ch == null)
             {
                 return(null);
             }
             Polyline2 <T> chn = ConstructPolyline(ch);
             if (chn == null)
             {
                 return(null);
             }
             constructed.Add(chn);
         }
         return(ConstructPolylineBag(constructed));
     }
     return(null);
 }
示例#11
0
        public override PolylineSet2 <double> ConstructPolylineSet(Point2 <double>[][] chains)
        {
            if (chains == null)
            {
                return(null);
            }
            List <Polyline2 <double> > constructed = new List <Polyline2 <double> >();

            foreach (Point2 <double>[] ch in chains)
            {
                if (ch == null)
                {
                    return(null);
                }
                Polyline2 <double> chn = ConstructPolyline(ch);
                if (chn == null)
                {
                    return(null);
                }
                constructed.Add(chn);
            }
            return(ConstructPolylineSet(constructed));
        }