コード例 #1
0
        public override RingSet2 <double> ConstructRingSet(Ring2 <double>[] chains)
        {
            if (chains == null || chains.Length < 1)
            {
                return(null);
            }
            Ring2 <double>[] Chains = new Ring2 <double> [chains.Length];
            Array.Copy(chains, Chains, Chains.Length);

            PlanarChainGraph <double> graph = new PlanarChainGraph <double>();

            foreach (Ring2 <double> ch in Chains)
            {
                if (ch == null)
                {
                    return(null); //can't have null chains
                }
                graph.Add(ch);
            }
            if (PlanarGraphUtils.AnyIntersections(graph)) //there must be overlap
            {
                return(null);
            }

            return(new RingSet2 <double>(Chains));
        }
コード例 #2
0
ファイル: Polyline2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 internal Polyline2(Ring2 <T> other)
 {
     //this is safe since a ring is simple and closed, therefore a chain will be as well
     //converse is not true -- closing a ring can create a self-intersection
     this.Points     = other.Points;
     this.IsReversed = other.IsReversed;
 }
コード例 #3
0
ファイル: WKTReader.cs プロジェクト: OSRS/Oncor_OsrsLegacy
        /// <summary>
        /// Creates a <c>Polygon</c> using the next token in the stream.
        /// </summary>
        /// <param name="tokens">
        ///   Tokenizer over a stream of text in Well-known Text
        ///   format. The next tokens must form a Polygon Text.
        /// </param>
        /// <param name="factory"> </param>
        /// <returns>
        /// A <c>Polygon</c> specified by the next token
        /// in the stream.
        /// </returns>
        private Polygon2 <double> ReadPolygonText(IEnumerator <Token> tokens)
        {
            string nextToken = GetNextEmptyOrOpener(tokens);

            if (nextToken.Equals("EMPTY"))
            {
                return(null);
            }

            var holes = new List <Ring2 <double> >();
            var shell = ReadLinearRingText(tokens);

            nextToken = GetNextCloserOrComma(tokens);
            while (nextToken.Equals(","))
            {
                Ring2 <double> hole = ReadLinearRingText(tokens);
                holes.Add(hole);
                nextToken = GetNextCloserOrComma(tokens);
            }
            if (holes.Count < 1)
            {
                return(factory.ConstructPolygon(shell));
            }
            return(factory.ConstructPolygon(shell, factory.ConstructRingSet(holes)));
        }
コード例 #4
0
ファイル: Polygon2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
        public Polygon2 <T> Reverse()
        {
            Ring2 <T>    o = this.OuterRing.Reverse();
            RingSet2 <T> i = this.InnerRings.Reverse();

            return(new Polygon2 <T>(o, i));
        }
コード例 #5
0
ファイル: Polygon2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
        public bool HasCoincidentPoints()
        {
            if (this.InnerRings == null)
            {
                return(false); //duh, only one chain
            }
            HashSet <Point2 <T> > distinctPoints = new HashSet <Point2 <T> >();
            Ring2 <T>             curChain       = this.OuterRing;

            foreach (Point2 <T> curPoint in curChain.Points)
            {
                distinctPoints.Add(curPoint);
            }

            Ring2 <T>[] rings = this.InnerRings.Rings;
            for (int i = 0; i < rings.Length; i++)
            {
                curChain = rings[i];
                foreach (Point2 <T> curPoint in curChain.Points)
                {
                    if (distinctPoints.Contains(curPoint))
                    {
                        return(true); //found a dup!
                    }
                    distinctPoints.Add(curPoint);
                }
            }
            return(false);
        }
コード例 #6
0
        public bool HasCoincidentPoints()
        {
            if (this.Rings.Length < 2)
            {
                return(false); //duh, only one chain
            }
            HashSet <Point2 <T> > distinctPoints = new HashSet <Point2 <T> >();
            Ring2 <T>             curChain       = this.Rings[0];

            foreach (Point2 <T> curPoint in curChain.Points)
            {
                distinctPoints.Add(curPoint);
            }

            for (int i = 1; i < this.Rings.Length; i++)
            {
                curChain = this.Rings[i];
                foreach (Point2 <T> curPoint in curChain.Points)
                {
                    if (distinctPoints.Contains(curPoint))
                    {
                        return(true); //found a dup!
                    }
                    distinctPoints.Add(curPoint);
                }
            }
            return(false);
        }
コード例 #7
0
        public override RingSet2 <double> ConstructRingSet(IList <Ring2 <double> > chains)
        {
            if (chains == null || chains.Count < 1)
            {
                return(null);
            }
            Ring2 <double>[] Chains = new Ring2 <double> [chains.Count];
            for (int i = 0; i < Chains.Length; i++)
            {
                Chains[i] = chains[i];
            }

            PlanarChainGraph <double> graph = new PlanarChainGraph <double>();

            foreach (Ring2 <double> ch in Chains)
            {
                if (ch == null)
                {
                    return(null); //can't have null chains
                }
                graph.Add(ch);
            }
            if (PlanarGraphUtils.AnyIntersections(graph)) //there must be overlap
            {
                return(null);
            }

            return(new RingSet2 <double>(Chains));
        }
コード例 #8
0
ファイル: Polygon2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 internal Polygon2(Ring2 <T> outerRing)
 {
     if (outerRing == null)
     {
         throw new ArgumentNullException();
     }
     this.OuterRing = outerRing;
 }
コード例 #9
0
ファイル: Polygon2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 internal Polygon2(Ring2 <T> outerRing, RingSet2 <T> innerRings)
 {
     if (outerRing == null)
     {
         throw new ArgumentNullException();
     }
     this.OuterRing  = outerRing;
     this.InnerRings = innerRings;
 }
コード例 #10
0
ファイル: Polygon2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 public Polygon2(Polygon2 <T> cloned)
 {
     if (cloned == null)
     {
         throw new ArgumentNullException();
     }
     this.OuterRing  = cloned.OuterRing;
     this.InnerRings = cloned.InnerRings;
 }
コード例 #11
0
 public RingSet2 <T> Reverse()
 {
     Ring2 <T>[] r = new Ring2 <T> [this.Rings.Length];
     for (int i = 0; i < r.Length; i++)
     {
         r[i] = this.Rings[i].Reverse();
     }
     return(new RingSet2 <T>(r));
 }
コード例 #12
0
ファイル: Ring2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 //Trusted constructor -- uses array directly -- no nulls!
 internal Ring2(Ring2 <T> other, bool isReversed, Orientation orientation)
 {
     if (other == null)
     {
         throw new ArgumentNullException();
     }
     this.Points      = other.Points;
     this.IsReversed  = isReversed;
     this.Orientation = Orientation.Counterclockwise;
 }
コード例 #13
0
ファイル: Ring2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 public Ring2(Ring2 <T> other)
 {
     if (other == null)
     {
         throw new ArgumentNullException();
     }
     this.Points      = other.Points;
     this.IsReversed  = other.IsReversed;
     this.Orientation = other.Orientation;
 }
コード例 #14
0
ファイル: LineChain2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 internal LineChain2(Ring2 <T> other, bool isReversed)
 {
     //this is safe since a ring is simple and closed, therefore a chain will be as well
     //converse is not true -- closing a ring can create a self-intersection
     if (other == null)
     {
         throw new ArgumentNullException();
     }
     this.Points     = other.Points;
     this.IsReversed = isReversed;
 }
コード例 #15
0
 public Polygon2 <T> ConstructPolygon(Ring2 <T> outerRing, Ring2 <T>[] innerRings)
 {
     if (outerRing != null && innerRings != null)
     {
         RingSet2 <T> rs = ConstructRingSet(innerRings);
         if (rs != null)
         {
             return(ConstructPolygon(outerRing, rs));
         }
     }
     return(null);
 }
コード例 #16
0
ファイル: PolygonUtils.cs プロジェクト: OSRS/Oncor_OsrsLegacy
        public static Polygon2 <double> OpenSimplePolygonPoints(Point2 <double>[] outerRingPoints, Ring2 <double>[] innerRings)
        {
            Ring2 <double> ring = RingUtils.OpenSimpleRingPoints(outerRingPoints);

            if (ring == null)
            {
                return(null);
            }

            Polygon2 <double> tmpP;

            tmpP = ring.Factory.ConstructPolygon(ring, innerRings);
            return(tmpP);
        }
コード例 #17
0
 public Polygon2 <T> ConstructPolygon(Point2 <T>[] outerRing, Point2 <T>[][] innerRings)
 {
     if (outerRing != null && innerRings != null)
     {
         Ring2 <T> outer = ConstructRing(outerRing);
         if (outer != null)
         {
             RingSet2 <T> inner = ConstructRingSet(innerRings);
             if (inner != null)
             {
                 return(ConstructPolygon(outer, inner));
             }
         }
     }
     return(null);
 }
コード例 #18
0
ファイル: Ring2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 public int CompareTo(Ring2 <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));
 }
コード例 #19
0
 public override Polygon2 <double> ConstructPolygon(Ring2 <double> outerRing, RingSet2 <double> innerRings)
 {
     if (outerRing == null)
     {
         return(null);
     }
     if (innerRings == null)
     {
         return(new Polygon2 <double>(outerRing));
     }
     if (PlanarGraphUtils.ValidPolygon(outerRing, innerRings))
     {
         return(new Polygon2 <double>(outerRing, innerRings));
     }
     return(null);
 }
コード例 #20
0
 public RingBag2 <T> ConstructRingBag(IList <Ring2 <T> > chains)
 {
     if (chains != null && chains.Count > 0)
     {
         Ring2 <T>[] Chains = new Ring2 <T> [chains.Count];
         for (int i = 0; i < Chains.Length; i++)
         {
             Ring2 <T> ch = chains[i];
             if (ch == null)
             {
                 return(null); //can't have null chains
             }
             Chains[i] = ch;
         }
         return(new RingBag2 <T>(Chains));
     }
     return(null);
 }
コード例 #21
0
        public RingBag2 <T> ConstructRingBag(Ring2 <T>[] chains)
        {
            if (chains != null && chains.Length > 0)
            {
                Ring2 <T>[] Chains = new Ring2 <T> [chains.Length];
                Array.Copy(chains, Chains, Chains.Length);

                foreach (Ring2 <T> ch in Chains)
                {
                    if (ch == null)
                    {
                        return(null); //can't have null chains
                    }
                }
                return(new RingBag2 <T>(Chains));
            }
            return(null);
        }
コード例 #22
0
ファイル: PolygonUtils.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 public static Polygon2 <double> InvertExtent(PolygonSet2 <double> polys)
 {
     if (polys != null)
     {
         Ring2 <double>   outer  = polys.Factory.ConstructRing(polys.Envelope);
         Ring2 <double>[] inners = new Ring2 <double> [polys.Polygons.Length];
         for (int i = 0; i < inners.Length; i++)
         {
             inners[i] = polys.Polygons[i].OuterRing;
         }
         RingSet2 <double> innerSet = polys.Factory.ConstructRingSet(inners);
         if (innerSet == null)
         {
             return(null);
         }
         return(polys.Factory.ConstructPolygon(outer, innerSet));
     }
     return(null);
 }
コード例 #23
0
 //POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))
 public static string ToWkt(Ring2 <double> geom)
 {
     if (geom != null)
     {
         StringBuilder sb = new StringBuilder();
         sb.Append("POLYGON((");
         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] = ')';
         sb.Append(')');
         return(sb.ToString());
     }
     return(string.Empty);
 }
コード例 #24
0
ファイル: Ring2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 public bool Equals(Ring2 <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);
 }
コード例 #25
0
 public RingBag2 <T> ConstructRingBag(IList <Point2 <T> >[] chains)
 {
     if (chains != null)
     {
         List <Ring2 <T> > constructed = new List <Ring2 <T> >();
         foreach (Point2 <T>[] ch in chains)
         {
             if (ch == null)
             {
                 return(null);
             }
             Ring2 <T> chn = ConstructRing(ch);
             if (chn == null)
             {
                 return(null);
             }
             constructed.Add(chn);
         }
         return(ConstructRingBag(constructed));
     }
     return(null);
 }
コード例 #26
0
ファイル: Ring2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
 public bool EqualsNonDirectional(Ring2 <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);
 }
コード例 #27
0
 public override PolygonSet2 <double> ConstructPolygonSet(Polygon2 <double>[] parts)
 {
     if (parts == null)
     {
         return(null);
     }
     Ring2 <double>[] shells = new Ring2 <double> [parts.Length];
     for (int i = 0; i < parts.Length; i++)
     {
         Polygon2 <double> curA = parts[i];
         if (curA == null)
         {
             return(null);
         }
         shells[i] = curA.OuterRing;
     }
     if (PlanarGraphUtils.ValidRingSet(shells))
     {
         return(new PolygonSet2 <double>(parts));
     }
     return(null);
 }
コード例 #28
0
ファイル: Polygon2.cs プロジェクト: OSRS/Oncor_OsrsLegacy
        public PointSet2 <T> CoincidentPoints()
        {
            //since each line chain by definition has no coincident points, we only need to compare between chains
            if (this.InnerRings == null)
            {
                return(null); //duh, only one chain
            }
            HashSet <Point2 <T> > distinctPoints = new HashSet <Point2 <T> >();
            HashSet <Point2 <T> > dupPoints      = new HashSet <Point2 <T> >();
            Ring2 <T>             curChain       = this.OuterRing;

            foreach (Point2 <T> curPoint in curChain.Points)
            {
                distinctPoints.Add(curPoint);
            }

            Ring2 <T>[] rings = this.InnerRings.Rings;
            for (int i = 0; i < rings.Length; i++)
            {
                curChain = rings[i];
                foreach (Point2 <T> curPoint in curChain.Points)
                {
                    if (distinctPoints.Contains(curPoint))
                    {
                        dupPoints.Add(curPoint); //found a dup!
                    }
                    else
                    {
                        distinctPoints.Add(curPoint);
                    }
                }
            }
            if (dupPoints.Count < 1)
            {
                return(null);
            }
            return(new PointSet2 <T>(dupPoints.ToArray())); //avoid overhead checking for dups in constructor
        }
コード例 #29
0
        public override RingSet2 <double> ConstructRingSet(IEnumerable <Point2 <double>[]> chains)
        {
            if (chains == null)
            {
                return(null);
            }
            List <Ring2 <double> > constructed = new List <Ring2 <double> >();

            foreach (Point2 <double>[] ch in chains)
            {
                if (ch == null)
                {
                    return(null);
                }
                Ring2 <double> chn = ConstructRing(ch);
                if (chn == null)
                {
                    return(null);
                }
                constructed.Add(chn);
            }
            return(ConstructRingSet(constructed));
        }
コード例 #30
0
 public static Polygon2 <double> BuildPolygon(PositionSet ps)
 {
     try
     {
         if (ps != null && ps.Positions.Count > 0)
         {
             List <Point2 <double> > list1 = BuildCoords(ps.Positions[0] as PositionSet);
             if (list1 != null && list1.Count > 2)
             {
                 if (ps.Positions.Count == 1)
                 {
                     return(factory.ConstructPolygon(factory.ConstructRing(list1)));
                 }
                 Ring2 <double>         linearRing1 = factory.ConstructRing(list1);
                 List <Ring2 <double> > list2       = new List <Ring2 <double> >();
                 for (int index = 1; index < ps.Positions.Count; ++index)
                 {
                     Position position = ps.Positions[index];
                     if (position != null)
                     {
                         List <Point2 <double> > list3 = BuildCoords(position as PositionSet);
                         if (list3 != null)
                         {
                             Ring2 <double> linearRing2 = factory.ConstructRing(list3);
                             list2.Add(linearRing2);
                         }
                     }
                 }
                 return(factory.ConstructPolygon(linearRing1, list2.ToArray()));
             }
         }
     }
     catch
     {
     }
     return(null);
 }