public ICoordinateSequence Reproject(ICoordinateSequence sequence, ISpatialReference @from, ISpatialReference to)
 {
     double[] xy, z, m;
     ToDotSpatial(sequence, out xy, out z, out m);
     DotSpatial.Projections.Reproject.ReprojectPoints(xy, z, GetProjectionInfo(@from), GetProjectionInfo(to), 0, sequence.Count);
     return ToGeoAPI(DefaultSequenceFactory, xy, z, m);
 }
示例#2
0
 /// <summary>
 /// Reverses the coordinates in a sequence in-place.
 /// </summary>
 /// <param name="seq"></param>
 public static void Reverse(ICoordinateSequence seq)
 {
     int last = seq.Count - 1;
     int mid = last / 2;
     for (int i = 0; i <= mid; i++)
         Swap(seq, i, last - i);
 }
示例#3
0
 /// <summary>
 /// Constructs a <c>Point</c> with the given coordinate.
 /// </summary>
 /// <param name="coordinates">
 /// Contains the single coordinate on which to base this <c>Point</c>,
 /// or <c>null</c> to create the empty point.
 /// </param>
 /// <param name="factory"></param>
 public Point(ICoordinateSequence coordinates, IGeometryFactory factory) : base(factory)
 {               
     if (coordinates == null) 
         coordinates = factory.CoordinateSequenceFactory.Create(new ICoordinate[] { });
     Debug.Assert(coordinates.Count <= 1);
     this.coordinates = (ICoordinateSequence) coordinates;
 }        
 public void Filter(ICoordinateSequence seq, int i)
 {
     if (i == 0) return;
     seq.GetCoordinate(i - 1, p0);
     seq.GetCoordinate(i, p1);
     rcc.CountSegment(p0, p1);
 }
示例#5
0
 /// <summary>
 /// Constructs a <c>Point</c> with the given coordinate.
 /// </summary>
 /// <param name="coordinates">
 /// Contains the single coordinate on which to base this <c>Point</c>,
 /// or <c>null</c> to create the empty point.
 /// </param>
 /// <param name="factory"></param>
 public Point(ICoordinateSequence coordinates, IGeometryFactory factory) : base(factory)
 {               
     if (coordinates == null) 
         coordinates = factory.CoordinateSequenceFactory.Create(new Coordinate[] { });
     NetTopologySuite.Utilities.Assert.IsTrue(coordinates.Count <= 1);
     this._coordinates = coordinates;
 }        
示例#6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="points">
 /// The points of the linestring, or <c>null</c>
 /// to create the empty point. Consecutive points may not be equal.
 /// </param>
 /// <param name="factory"></param>
 public LineString(ICoordinateSequence points, IGeometryFactory factory) : base(factory)
 {            
     if (points == null) 
         points = factory.CoordinateSequenceFactory.Create(new ICoordinate[] { });
     if (points.Count == 1)
         throw new ArgumentException("point array must contain 0 or >1 elements", "points");
     this.points = points;
 }
 // ReSharper disable InconsistentNaming
 /// <summary>
 /// Creates a wrapper projecting to the XY plane.
 /// </summary>
 /// <param name="seq">The sequence to be projected</param>
 /// <returns>A sequence which projects coordinates</returns>
 public static ICoordinateSequence ProjectToXY(ICoordinateSequence seq)
 {
     /**
      * This is just a no-op, but return a wrapper
      * to allow better testing
      */
     return new AxisPlaneCoordinateSequence(seq, XYIndex);
 }
 /// <summary>
 /// Constructs a sequence based on the given array (the array is not copied).
 /// </summary>
 /// <param name="coordSeq">The coordinate array that will be referenced.</param>      
 public CoordinateArraySequence(ICoordinateSequence coordSeq)
 {
     if (coordSeq != null)
          coordinates = new ICoordinate[coordSeq.Count];
     else coordinates = new ICoordinate[0];
     for (int i = 0; i < coordinates.Length; i++) 
         coordinates[i] = coordSeq.GetCoordinateCopy(i);
 }
 private static ICoordinateSequence CopyToSequence(Coordinate[] coords, ICoordinateSequence sequence)
 {
     for (int i = 0; i < coords.Length; i++)
     {
         sequence.SetOrdinate(i, Ordinate.X, coords[i].X);
         sequence.SetOrdinate(i, Ordinate.Y, coords[i].Y);                
     }
     return sequence;
 }
		public static MCoordinate[] Copy(ICoordinateSequence coordSeq)
		{
			MCoordinate[] copy = new MCoordinate[coordSeq.Count];
			for (int i = 0; i < coordSeq.Count; i++)
			{
				copy[i] = new MCoordinate(coordSeq.GetCoordinate(i));
			}
			return copy;
		}
 private ILinearRing CreateLinearRing(ICoordinateSequence coordinates, bool ccw)
 {
     if (coordinates != null && Algorithm.CGAlgorithms.IsCCW(coordinates) != ccw)
     {
         //CoordinateSequences.Reverse(coordinates);
         coordinates = coordinates.Reversed();
     }
     return CreateLinearRing(coordinates);
 }
 ///<summary>
 /// Copies a coordinate of a <see cref="ICoordinateSequence"/> to another <see cref="ICoordinateSequence"/>.
 /// The sequences may have different dimensions;
 /// in this case only the common dimensions are copied.
 ///</summary>
 /// <param name="src">The sequence to copy coordinate from</param>
 /// <param name="srcPos">The index of the coordinate to copy</param>
 /// <param name="dest">The sequence to which the coordinate should be copied to</param>
 /// <param name="destPos">The index of the coordinate in <see paramref="dest"/></param>
 public static void CopyCoord(ICoordinateSequence src, int srcPos, ICoordinateSequence dest, int destPos)
 {
     int minDim = Math.Min(src.Dimension, dest.Dimension);
     for (int dim = 0; dim < minDim; dim++)
     {
         Ordinate ordinate = (Ordinate)dim;
         double value = src.GetOrdinate(srcPos, ordinate);
         dest.SetOrdinate(destPos, ordinate, value);
     }
 }
示例#13
0
        protected void WriteInterval(ICoordinateSequence sequence, Ordinate ordinate, BinaryWriter writer)
        {
            var val = GetOrdinate(sequence, ordinate, 0);
            var interval = Interval.Create(val);
            for (var i = 1; i < sequence.Count; i++)
                interval = interval.ExpandedByValue(GetOrdinate(sequence, ordinate, i));

            writer.Write(interval.Min);
            writer.Write(interval.Max);
        }
示例#14
0
 private static ICoordinateSequence CreateClosedRing(ICoordinateSequenceFactory fact, ICoordinateSequence seq, int size)
 {
     var newseq = fact.Create(size, seq.Dimension);
     int n = seq.Count;
     Copy(seq, 0, newseq, 0, n);
     // fill remaining coordinates with start point
     for (int i = n; i < size; i++)
         Copy(seq, 0, newseq, i, 1);
     return newseq;
 }
 public PointF[] Transform(ICoordinateSequence modelSequence)
 {
     var res = new PointF[modelSequence.Count];
     for (var i = 0; i < modelSequence.Count; i++)
     {
         res[i] = Transform(modelSequence.GetOrdinate(0, Ordinate.X), 
                            modelSequence.GetOrdinate(0, Ordinate.Y));
     }
     return res;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="seq"></param>
 /// <param name="lines"></param>
 /// <returns></returns>
 public bool HasIntersectionWithLineStrings(ICoordinateSequence seq, ICollection<IGeometry> lines)
 {
     foreach (ILineString line in lines)
     {
         HasIntersection(seq, line.CoordinateSequence);
         if (_hasIntersection)
             break;
     }
     return _hasIntersection;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="seq"></param>
 /// <param name="lines"></param>
 /// <returns></returns>
 public bool HasIntersectionWithLineStrings(ICoordinateSequence seq, IList lines)
 {
     for (IEnumerator i = lines.GetEnumerator(); i.MoveNext(); ) 
     {
         ILineString line = (ILineString) i.Current;
         HasIntersection(seq, line.CoordinateSequence);
         if (hasIntersection)
             break;
     }
     return hasIntersection;
 }
示例#18
0
        /// <summary>
        /// Swaps two coordinates in a sequence.
        /// </summary>
        /// <param name="seq"></param>
        /// <param name="i"></param>
        /// <param name="j"></param>
        public static void Swap(ICoordinateSequence seq, int i, int j)
        {
            if (i == j)
                return;

            for (int dim = 0; dim < seq.Dimension; dim++)
            {
                double tmp = seq.GetOrdinate(i, (Ordinates)dim);
                seq.SetOrdinate(i, (Ordinates)dim, seq.GetOrdinate(j, (Ordinates)dim));
                seq.SetOrdinate(j, (Ordinates)dim, tmp);
            }
        }
        /// <summary>
        /// Creates a new sequence based on a deep copy of the given <see cref="ICoordinateSequence"/>.
        /// </summary>
        /// <param name="coordSeq">The coordinate sequence that will be copied</param>
        public CoordinateArraySequence(ICoordinateSequence coordSeq)
        {
            if (coordSeq == null)
            {
                Coordinates = new Coordinate[0];
                return;
            }

            _dimension = coordSeq.Dimension;
            Coordinates = new Coordinate[coordSeq.Count];

            for (var i = 0; i < Coordinates.Length; i++) 
                Coordinates[i] = coordSeq.GetCoordinateCopy(i);
        }
示例#20
0
        /// <summary>
        /// Ensures that a CoordinateSequence forms a valid ring, 
        /// returning a new closed sequence of the correct length if required.
        /// If the input sequence is already a valid ring, it is returned 
        /// without modification.
        /// If the input sequence is too short or is not closed, 
        /// it is extended with one or more copies of the start point.
        /// </summary>
        /// <param name="fact">The CoordinateSequenceFactory to use to create the new sequence</param>
        /// <param name="seq">The sequence to test</param>
        /// <returns>The original sequence, if it was a valid ring, or a new sequence which is valid.</returns>
        public static ICoordinateSequence EnsureValidRing(ICoordinateSequenceFactory fact, ICoordinateSequence seq)
        {
            var n = seq.Count;
            // empty sequence is valid
            if (n == 0) return seq;
            // too short - make a new one
            if (n <= 3)
                return CreateClosedRing(fact, seq, 4);

            var isClosed = Math.Abs(seq.GetOrdinate(0, Ordinate.X) - seq.GetOrdinate(n - 1, Ordinate.X)) < double.Epsilon &&
                           Math.Abs(seq.GetOrdinate(0, Ordinate.Y) - seq.GetOrdinate(n - 1, Ordinate.Y)) < double.Epsilon;
            if (isClosed) return seq;
            // make a new closed ring
            return CreateClosedRing(fact, seq, n + 1);
        }
 private ICoordinateSequence Add(ICoordinateSequence seq1,
     ICoordinateSequence seq2)
 {
     if (seq1 == null) {
         return seq2;
     }
     if (seq2 == null) {
         return seq1;
     }
     ICoordinate[] c1 = seq1.ToCoordinateArray();
     ICoordinate[] c2 = seq2.ToCoordinateArray();
     ICoordinate[] c3 = new Coordinate[c1.Length + c2.Length];
     Array.Copy(c1, 0, c3, 0, c1.Length);
     Array.Copy(c2, 0, c3, c1.Length, c2.Length);
     return factory.CoordinateSequenceFactory.Create(c3);
 }
        /// <summary>
        /// Determines the <see cref="Location"/> of a point in a ring.
        /// </summary>
        /// <param name="p">The point to test</param>
        /// <param name="ring">A coordinate sequence forming a ring</param>
        /// <returns>The location of the point in the ring</returns>
        public static Location LocatePointInRing(Coordinate p, ICoordinateSequence ring)
        {
            var counter = new RayCrossingCounter(p);

            var p1 = new Coordinate();
            var p2 = new Coordinate();
            for (var i = 1; i < ring.Count; i++)
            {
                ring.GetCoordinate(i, p1);
                ring.GetCoordinate(i - 1, p2);
                counter.CountSegment(p1, p2);
                if (counter.IsOnSegment)
                    return counter.Location;
            }
            return counter.Location;
        }
 private static void AddFacetSequences(ICoordinateSequence pts, List<FacetSequence> sections)
 {
     int i = 0;
     int size = pts.Count;
     while (i <= size - 1)
     {
         int end = i + FacetSequenceSize + 1;
         // if only one point remains after this section, include it in this
         // section
         if (end >= size - 1)
             end = size;
         var sect = new FacetSequence(pts, i, end);
         sections.Add(sect);
         i = i + FacetSequenceSize;
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="seq0"></param>
 /// <param name="seq1"></param>
 /// <returns></returns>
 public bool HasIntersection(ICoordinateSequence seq0, ICoordinateSequence seq1) 
 {
     for (int i = 1; i < seq0.Count && ! hasIntersection; i++) 
     {
         seq0.GetCoordinate(i - 1, pt00);
         seq0.GetCoordinate(i, pt01);
         for (int j = 1; j < seq1.Count && ! hasIntersection; j++) 
         {
             seq1.GetCoordinate(j - 1, pt10);
             seq1.GetCoordinate(j, pt11);
             li.ComputeIntersection(pt00, pt01, pt10, pt11);
             if (li.HasIntersection)
                 hasIntersection = true;
         }
     }
     return hasIntersection;
 }
示例#25
0
 /// <summary>
 /// Generates the WKT for a N-point <c>LineString</c> specified by a <see cref="ICoordinateSequence"/>.
 /// </summary>
 /// <param name="seq">The sequence to write.</param>
 /// <returns>The WKT</returns>
 public static String ToLineString(ICoordinateSequence seq)
 {
     var buf = new StringBuilder();
     buf.Append("LINESTRING");
     if (seq.Count == 0)
         buf.Append(" EMPTY");
     else 
     {
         buf.Append("(");
         for (var i = 0; i < seq.Count; i++) 
         {
             if (i > 0)
                 buf.Append(", ");
             buf.Append(String.Format(CultureInfo.InvariantCulture, "{0} {1}", seq.GetX(i), seq.GetY(i)));
       }
       buf.Append(")");
     }
     return buf.ToString();
 }
示例#26
0
 /// <summary>
 /// Generates the WKT for a N-point <c>LineString</c>.
 /// </summary>
 /// <param name="seq">The sequence to output.</param>
 /// <returns></returns>
 public static String ToLineString(ICoordinateSequence seq)
 {
     StringBuilder buf = new StringBuilder();
     buf.Append("LINESTRING");
     if (seq.Count == 0)
         buf.Append(" EMPTY");
     else 
     {
         buf.Append("(");
         for (int i = 0; i < seq.Count; i++) 
         {
             if (i > 0)
                 buf.Append(",");
             buf.Append(seq.GetX(i) + " " + seq.GetY(i));
       }
       buf.Append(")");
     }
     return buf.ToString();
 }
 /**
  * Computes an average normal vector from a list of polygon coordinates.
  * Uses Newell's method, which is based
  * on the fact that the vector with components
  * equal to the areas of the projection of the polygon onto 
  * the Cartesian axis planes is normal.
  * 
  * @param seq the sequence of coordinates for the polygon
  * @return a normal vector
  */
 private static Vector3D AverageNormal(ICoordinateSequence seq)
 {
     var n = seq.Count;
     var sum = new Coordinate(0, 0, 0);
     var p1 = new Coordinate(0, 0, 0);
     var p2 = new Coordinate(0, 0, 0);
     for (var i = 0; i < n - 1; i++)
     {
         seq.GetCoordinate(i, p1);
         seq.GetCoordinate(i + 1, p2);
         sum.X += (p1.Y - p2.Y) * (p1.Z + p2.Z);
         sum.Y += (p1.Z - p2.Z) * (p1.X + p2.X);
         sum.Z += (p1.X - p2.X) * (p1.Y + p2.Y);
     }
     sum.X /= n;
     sum.Y /= n;
     sum.Z /= n;
     var norm = Vector3D.Create(sum).Normalize();
     return norm;
 }
        private static void DoTest(ICoordinateSequence forward, ICoordinateSequence reversed)
        {
            const double eps = 1e-12;

            Assert.AreEqual(forward.Count, reversed.Count, "Coordinate sequences don't have same size");
            Assert.AreEqual(forward.Ordinates, reversed.Ordinates, "Coordinate sequences don't serve same ordinate values");

            var ordinates = OrdinatesUtility.ToOrdinateArray(forward.Ordinates);
            var j = forward.Count;
            for (var i = 0; i < forward.Count; i++)
            {
                j--;
                foreach(var ordinate in ordinates)
                    Assert.AreEqual(forward.GetOrdinate(i, ordinate), reversed.GetOrdinate(j, ordinate), eps, string.Format("{0} values are not within tolerance", ordinate));
                var cf = forward.GetCoordinate(i);
                var cr = reversed.GetCoordinate(j);

                Assert.IsFalse(ReferenceEquals(cf, cr), "Coordinate sequences deliver same coordinate instances");
                Assert.IsTrue(cf.Equals(cr), "Coordinate sequences do not provide equal coordinates");
            }
        }
示例#29
0
        protected void WriteCoordinates(ICoordinateSequence sequence, BinaryWriter writer, Ordinates ordinates)
        {
            for (var i = 0; i < sequence.Count; i++)
            {
                writer.Write(sequence.GetX(i));
                writer.Write(sequence.GetY(i));
            }

            if ((ordinates & Ordinates.Z) == Ordinates.Z)
            {
                WriteInterval(sequence, Ordinate.Z, writer);                
                for (var i = 0; i < sequence.Count; i++)
                    writer.Write(GetOrdinate(sequence, Ordinate.Z, i));
            }

            if ((ordinates & Ordinates.M) == Ordinates.M)
            {
                WriteInterval(sequence, Ordinate.M, writer);
                for (var i = 0; i < sequence.Count; i++)
                    writer.Write(GetOrdinate(sequence, Ordinate.M, i));
            }
        }
示例#30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="coords"></param>
 /// <param name="parent"></param>
 /// <returns></returns>
 protected override ICoordinateSequence TransformCoordinates(ICoordinateSequence coords, IGeometry parent)
 {
     Coordinate[] srcPts = coords.ToCoordinateArray();
     Coordinate[] newPts = SnapLine(srcPts, _snapPts);
     return(Factory.CoordinateSequenceFactory.Create(newPts));
 }
示例#31
0
 /// <summary>
 /// Creates a <c>Point</c> using the given <c>CoordinateSequence</c>; a null or empty
 /// CoordinateSequence will create an empty Point.
 /// </summary>
 /// <param name="coordinates">a CoordinateSequence (possibly empty), or null</param>
 /// <returns>A <see cref="IPoint"/> object</returns>
 public IPoint CreatePoint(ICoordinateSequence coordinates)
 {
     return(new Point(coordinates, this));
 }
示例#32
0
 /// <summary>
 /// Creates a <c>LinearRing</c> using the given <c>CoordinateSequence</c>; a null or empty CoordinateSequence
 /// creates an empty LinearRing. The points must form a closed and simple
 /// linestring. Consecutive points must not be equal.
 /// </summary>
 /// <param name="coordinates">A CoordinateSequence (possibly empty), or null.</param>
 /// <returns>A <see cref="ILinearRing"/> object</returns>
 /// <exception cref="ArgumentException"> If the ring is not closed, or has too few points</exception>
 public ILinearRing CreateLinearRing(ICoordinateSequence coordinates)
 {
     return(new LinearRing(coordinates, this));
 }
示例#33
0
 /// <summary>
 /// Constructs a <c>Polygon</c> with the given exterior boundary.
 /// </summary>
 /// <param name="coordinates">the outer boundary of the new <c>Polygon</c>, or
 /// <c>null</c> or an empty <c>LinearRing</c> if
 /// the empty geometry is to be created.</param>
 /// <returns>A <see cref="IPolygon"/> object</returns>
 /// <exception cref="ArgumentException">If the boundary ring is invalid</exception>
 public virtual IPolygon CreatePolygon(ICoordinateSequence coordinates)
 {
     return(CreatePolygon(CreateLinearRing(coordinates)));
 }
示例#34
0
 /// <summary>
 /// Convenience method which provides statndard way of copying {CoordinateSequence}s
 /// </summary>
 /// <param name="seq">The sequence to copy.</param>
 /// <returns>A deep copy of the sequence.</returns>
 protected virtual ICoordinateSequence Copy(ICoordinateSequence seq)
 {
     return((ICoordinateSequence)seq.Clone());
 }
示例#35
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="coords"></param>
 /// <param name="parent"></param>
 /// <returns></returns>
 protected virtual ICoordinateSequence TransformCoordinates(ICoordinateSequence coords, IGeometry parent)
 {
     return(Copy(coords));
 }
 public MLineString(ICoordinateSequence points, IGeometryFactory factory)
     : base(points, factory)
 {
     DetermineMonotone();
 }
示例#37
0
        /// <summary>
        /// Ensures that a CoordinateSequence forms a valid ring,
        /// returning a new closed sequence of the correct length if required.
        /// If the input sequence is already a valid ring, it is returned
        /// without modification.
        /// If the input sequence is too short or is not closed,
        /// it is extended with one or more copies of the start point.
        /// </summary>
        /// <param name="fact">The CoordinateSequenceFactory to use to create the new sequence</param>
        /// <param name="seq">The sequence to test</param>
        /// <returns>The original sequence, if it was a valid ring, or a new sequence which is valid.</returns>
        public static ICoordinateSequence EnsureValidRing(ICoordinateSequenceFactory fact, ICoordinateSequence seq)
        {
            var n = seq.Count;

            // empty sequence is valid
            if (n == 0)
            {
                return(seq);
            }
            // too short - make a new one
            if (n <= 3)
            {
                return(CreateClosedRing(fact, seq, 4));
            }

            var isClosed = Math.Abs(seq.GetOrdinate(0, Ordinate.X) - seq.GetOrdinate(n - 1, Ordinate.X)) < double.Epsilon &&
                           Math.Abs(seq.GetOrdinate(0, Ordinate.Y) - seq.GetOrdinate(n - 1, Ordinate.Y)) < double.Epsilon;

            if (isClosed)
            {
                return(seq);
            }
            // make a new closed ring
            return(CreateClosedRing(fact, seq, n + 1));
        }
示例#38
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="iCoordinateSequence"></param>
        /// <returns></returns>
        private static bool hasZ(ICoordinateSequence coords)
        {
            if (coords == null || coords.Count == 0)
                return false;

            int dimensions = coords.Dimension;
            if (coords.Dimension == 3)
            {
                // CoordinateArraySequence will always return 3, so we have to
                // check, if the third ordinate contains NaN, then the geom is actually 2-dimensional
                return Double.IsNaN(coords.GetOrdinate(0, Ordinates.Z)) ? false : true;
            }
            else return false;
        }
 public ICoordinateSequence Create(ICoordinateSequence coordSeq)
 {
     throw new NotImplementedException();
 }