Exemplo n.º 1
0
            public void Filter(ICoordinateSequence seq, int i)
            {
                double x = seq.GetX(i);
                double y = seq.GetY(i);

                if (_ctx.IsGeo() && _normalizeGeomCoords)
                {
                    double xNorm = DistanceUtils.NormLonDEG(x);
                    if (x != xNorm)
                    {
                        changed = true;
                        seq.SetOrdinate(i, Ordinate.X, xNorm);
                    }

                    double yNorm = DistanceUtils.NormLatDEG(y);
                    if (y != yNorm)
                    {
                        changed = true;
                        seq.SetOrdinate(i, Ordinate.Y, yNorm);
                    }
                }
                else
                {
                    _ctx.VerifyX(x);
                    _ctx.VerifyY(y);
                }
            }
Exemplo n.º 2
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));
                }
            }
        }
Exemplo n.º 3
0
            public void Filter(ICoordinateSequence seq, int i)
            {
                double x = seq.GetX(i);
                double y = seq.GetY(i);

                //Note: we don't simply call ctx.normX & normY because
                //  those methods use the precisionModel, but WKTReader already
                //  used the precisionModel. It's be nice to turn that off somehow but alas.
                if (outerInstance.m_ctx.IsGeo && outerInstance.m_ctx.IsNormWrapLongitude)
                {
                    double xNorm = DistanceUtils.NormLonDEG(x);
                    if (x.CompareTo(xNorm) != 0)
                    {//handles NaN
                        changed = true;
                        seq.SetOrdinate(i, Ordinate.X, xNorm);
                    }
                    //          double yNorm = DistanceUtils.normLatDEG(y);
                    //          if (y != yNorm) {
                    //            changed = true;
                    //            seq.setOrdinate(i,CoordinateSequence.Y,yNorm);
                    //          }
                }
                outerInstance.m_ctx.VerifyX(x);
                outerInstance.m_ctx.VerifyY(y);
            }
        /// <summary>
        /// Creates a sequence based on the given coordinate sequence.
        /// </summary>
        /// <param name="coordSeq">The coordinate sequence.</param>
        /// <param name="ordinates">The ordinates to copy</param>
        public DotSpatialAffineCoordinateSequence(ICoordinateSequence coordSeq, Ordinates ordinates)
        {
            var count = coordSeq.Count;

            _xy = new double[2 * count];
            if ((ordinates & Ordinates.Z) == Ordinates.Z)
            {
                _z = new double[count];
            }
            if ((ordinates & Ordinates.M) == Ordinates.M)
            {
                _m = new double[count];
            }

            var dsCoordSeq = coordSeq as DotSpatialAffineCoordinateSequence;

            if (dsCoordSeq != null)
            {
                double[] nullOrdinateArray = null;
                Buffer.BlockCopy(dsCoordSeq._xy, 0, _xy, 0, 16 * count);
                if ((ordinates & Ordinates.Z) == Ordinates.Z)
                {
                    var copyOrdinateArray = dsCoordSeq.Z != null
                        ? dsCoordSeq.Z
                        : nullOrdinateArray = NullOrdinateArray(count);
                    Buffer.BlockCopy(copyOrdinateArray, 0, _z, 0, 8 * count);
                }

                if ((ordinates & Ordinates.M) == Ordinates.M)
                {
                    var copyOrdinateArray = dsCoordSeq.M != null
                        ? dsCoordSeq.M
                        : nullOrdinateArray ?? NullOrdinateArray(count);
                    Buffer.BlockCopy(copyOrdinateArray, 0, _m, 0, 8 * count);
                }

                _ordinates = ordinates;
                return;
            }

            var j = 0;

            for (var i = 0; i < coordSeq.Count; i++)
            {
                _xy[j++] = coordSeq.GetX(i);
                _xy[j++] = coordSeq.GetY(i);
                if (_z != null)
                {
                    _z[i] = coordSeq.GetOrdinate(i, Ordinate.Z);
                }
                if (_m != null)
                {
                    _m[i] = coordSeq.GetOrdinate(i, Ordinate.M);
                }
            }
        }
 public OctagonalEnvelope ExpandToInclude(ICoordinateSequence seq)
 {
     for (int i = 0; i < seq.Count; i++)
     {
         double x = seq.GetX(i);
         double y = seq.GetY(i);
         ExpandToInclude(x, y);
     }
     return(this);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Tests for equality using all supported accessors,
        /// to provides test coverage for them.
        /// </summary>
        /// <param name="seq"></param>
        /// <param name="coords"></param>
        /// <returns></returns>
        bool IsEqual(ICoordinateSequence seq, Coordinate[] coords)
        {
            if (seq.Count != coords.Length)
            {
                return(false);
            }

            Coordinate p = new Coordinate();

            for (int i = 0; i < seq.Count; i++)
            {
                if (!coords[i].Equals(seq.GetCoordinate(i)))
                {
                    return(false);
                }

                // Ordinate named getters
                if (coords[i].X != seq.GetX(i))
                {
                    return(false);
                }
                if (coords[i].Y != seq.GetY(i))
                {
                    return(false);
                }

                // Ordinate indexed getters
                if (coords[i].X != seq.GetOrdinate(i, Ordinate.X))
                {
                    return(false);
                }
                if (coords[i].Y != seq.GetOrdinate(i, Ordinate.Y))
                {
                    return(false);
                }
                if (coords[i].Z != seq.GetOrdinate(i, Ordinate.Z))
                {
                    return(false);
                }

                // Coordinate getter
                seq.GetCoordinate(i, p);
                if (coords[i].X != p.X)
                {
                    return(false);
                }
                if (coords[i].Y != p.Y)
                {
                    return(false);
                }
                //TODO: Remove commented line below when NTS supports Z ordinates in CoordinateArraySequence.GetCoordinate and PackedCoordinateSequence.GetCoordinate
                //if (coords[i].Z != p.Z) return false;
            }
            return(true);
        }
        /// <summary>
        /// Creates a sequence based on the given coordinate sequence.
        /// </summary>
        /// <param name="coordSeq">The coordinate sequence.</param>
        public DotSpatialAffineCoordinateSequence(ICoordinateSequence coordSeq)
        {
            var dsCoordSeq = coordSeq as DotSpatialAffineCoordinateSequence;
            var count      = coordSeq.Count;

            if (dsCoordSeq != null)
            {
                _xy = new double[2 * count];
                Buffer.BlockCopy(dsCoordSeq._xy, 0, _xy, 0, 16 * count);
                if (dsCoordSeq.Z != null)
                {
                    _z = new double[dsCoordSeq.Count];
                    Buffer.BlockCopy(dsCoordSeq._z, 0, _z, 0, 8 * count);
                }

                if (dsCoordSeq.M != null)
                {
                    _m = new double[dsCoordSeq.Count];
                    Buffer.BlockCopy(dsCoordSeq._m, 0, _m, 0, 8 * count);
                }

                _ordinates = dsCoordSeq._ordinates;
                return;
            }

            _xy = new double[2 * coordSeq.Count];
            if ((coordSeq.Ordinates & Ordinates.Z) != 0)
            {
                _z = new double[coordSeq.Count];
            }

            if ((coordSeq.Ordinates & Ordinates.M) != 0)
            {
                _m = new double[coordSeq.Count];
            }

            var j = 0;

            for (var i = 0; i < coordSeq.Count; i++)
            {
                _xy[j++] = coordSeq.GetX(i);
                _xy[j++] = coordSeq.GetY(i);
                if (_z != null)
                {
                    _z[i] = coordSeq.GetOrdinate(i, Ordinate.Z);
                }
                if (_m != null)
                {
                    _m[i] = coordSeq.GetOrdinate(i, Ordinate.M);
                }
            }
        }
Exemplo n.º 8
0
 ///<summary>Appends the i'th coordinate from the sequence to the writer</summary>
 /// <param name="seq">the <see cref="ICoordinateSequence"/> to process</param>
 /// <param name="i">the index of the coordinate to write</param>
 /// <param name="writer">writer the output writer to append to</param>
 ///<exception cref="IOException"></exception>
 private void AppendCoordinate(ICoordinateSequence seq, int i, TextWriter writer)
 {
     writer.Write(WriteNumber(seq.GetX(i)) + " " + WriteNumber(seq.GetY(i)));
     if (_outputDimension >= 3 && seq.Dimension >= 3)
     {
         double z = seq.GetOrdinate(i, Ordinate.Z);
         if (!Double.IsNaN(z))
         {
             writer.Write(" ");
             writer.Write(WriteNumber(z));
         }
     }
 }
            public ICoordinateSequence Transform(ICoordinateSequence coordinateSequence)
            {
                var res = coordinateSequence.Copy();

                for (int i = 0; i < coordinateSequence.Count; i++)
                {
                    double[] pt = Transform(new [] { coordinateSequence.GetX(i), coordinateSequence.GetY(i) });
                    res.SetOrdinate(i, Ordinate.X, pt[0]);
                    res.SetOrdinate(i, Ordinate.Y, pt[1]);
                }

                return(res);
            }
Exemplo n.º 10
0
        /// <summary>
        /// Transforms a coordinate sequence. The input coordinate sequence remains unchanged.
        /// </summary>
        /// <param name="coordinateSequence">The coordinate sequence to transform.</param>
        /// <returns>The transformed coordinate sequence.</returns>
        public ICoordinateSequence Transform(ICoordinateSequence coordinateSequence)
        {
            //if (coordinateSequence)

            var xy           = new double[coordinateSequence.Count * 2];
            var numOrdinates = coordinateSequence.Dimension;
            var z            = numOrdinates > 2 ? new double[coordinateSequence.Count] : null;
            var m            = numOrdinates > 3 ? new double[coordinateSequence.Count] : null;

            var j = 0;

            for (var i = 0; i < coordinateSequence.Count; i++)
            {
                xy[j++] = coordinateSequence.GetX(i);
                xy[j++] = coordinateSequence.GetY(i);
                if (numOrdinates > 2)
                {
                    z[i] = coordinateSequence.GetOrdinate(i, Ordinate.Z);
                }
                if (numOrdinates > 3)
                {
                    m[i] = coordinateSequence.GetOrdinate(i, Ordinate.M);
                }
            }

            // Do the reprojection
            Reproject.ReprojectPoints(xy, z, _order[0], _order[1], 0, coordinateSequence.Count);

            // Set up result
            j = 0;
            var res = (ICoordinateSequence)coordinateSequence.Clone();

            for (var i = 0; i < coordinateSequence.Count; i++)
            {
                res.SetOrdinate(i, Ordinate.X, xy[j++]);
                res.SetOrdinate(i, Ordinate.Y, xy[j++]);
                if (numOrdinates > 2)
                {
                    res.SetOrdinate(i, Ordinate.Z, z[i]);
                }
                else if (numOrdinates > 3)
                {
                    res.SetOrdinate(i, Ordinate.M, m[i]);
                }
            }

            // return it
            return(res);
        }
        public SpatialLite.Core.API.Coordinate ToCoordinate(ICoordinateSequence seq, int i)
        {
            var c = new SpatialLite.Core.API.Coordinate();

            c.X = seq.GetX(i);
            c.Y = seq.GetY(i);
            if ((seq.Ordinates & Ordinates.Z) == Ordinates.Z)
            {
                c.Z = seq.GetOrdinate(i, Ordinate.Z);
            }
            if ((seq.Ordinates & Ordinates.M) == Ordinates.M)
            {
                c.M = seq.GetOrdinate(i, Ordinate.M);
            }
            return(c);
        }
Exemplo n.º 12
0
        private int AddOrdinatesInReverse(ICoordinateSequence sequence, List <decimal> ords)
        {
            int dimension   = sequence.Dimension;
            int numOfPoints = sequence.Count;

            for (int i = numOfPoints - 1; i >= 0; i--)
            {
                ords.Add((decimal)sequence.GetX(i));
                ords.Add((decimal)sequence.GetY(i));
                if (dimension == 3)
                {
                    ords.Add((decimal)sequence.GetOrdinate(i, Ordinate.Z));
                }
            }

            return(numOfPoints * dimension);
        }
Exemplo n.º 13
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();
 }
Exemplo n.º 14
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();
 }
Exemplo n.º 15
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));
            }
        }
Exemplo n.º 16
0
        private static void GetMetric(ICoordinateSequence seq, out Interval xrange, out Interval yrange,
                                      out Interval zrange,
                                      out Interval mrange)
        {
            xrange = Interval.Create();
            yrange = Interval.Create();
            zrange = Interval.Create();
            mrange = Interval.Create();

            for (var i = 0; i < seq.Count; i++)
            {
                xrange = xrange.ExpandedByValue(seq.GetX(i));
                yrange = yrange.ExpandedByValue(seq.GetY(i));
                if ((seq.Ordinates & Ordinates.Z) == Ordinates.Z)
                {
                    zrange = zrange.ExpandedByValue(seq.GetOrdinate(i, Ordinate.Z));
                }
                if ((seq.Ordinates & Ordinates.M) == Ordinates.M)
                {
                    mrange = mrange.ExpandedByValue(seq.GetOrdinate(i, Ordinate.M));
                }
            }
        }
Exemplo n.º 17
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)
        {
            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(seq.GetX(i) + " " + seq.GetY(i));
                }
                buf.Append(")");
            }
            return(buf.ToString());
        }
        /// <summary>
        /// Tests for equality using all supported accessors,
        /// to provides test coverage for them.
        /// </summary>
        /// <param name="seq"></param>
        /// <param name="coords"></param>
        /// <returns></returns>
        bool IsEqual(ICoordinateSequence seq, Coordinate[] coords)
        {
            if (seq.Count != coords.Length)
                return false;

            Coordinate p = new Coordinate();

            for (int i = 0; i < seq.Count; i++)
            {
                if (!coords[i].Equals(seq.GetCoordinate(i)))
                    return false;

                // Ordinate named getters
                if (coords[i].X != seq.GetX(i))
                    return false;
                if (coords[i].Y != seq.GetY(i))
                    return false;

                // Ordinate indexed getters
                if (coords[i].X != seq.GetOrdinate(i, Ordinate.X))
                    return false;
                if (coords[i].Y != seq.GetOrdinate(i, Ordinate.Y))
                    return false;
                if (coords[i].Z != seq.GetOrdinate(i, Ordinate.Z))
                    return false;

                // Coordinate getter
                seq.GetCoordinate(i, p);
                if (coords[i].X != p.X)
                    return false;
                if (coords[i].Y != p.Y)
                    return false;
                //TODO: Remove commented line below when NTS supports Z ordinates in CoordinateArraySequence.GetCoordinate and PackedCoordinateSequence.GetCoordinate
                //if (coords[i].Z != p.Z) return false;

            }
            return true;
        }
Exemplo n.º 19
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 (int 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());
        }
        /// <summary>
        /// Creates a sequence based on the given coordinate sequence.
        /// </summary>
        /// <param name="coordSeq">The coordinate sequence.</param>
        public DotSpatialAffineCoordinateSequence(ICoordinateSequence coordSeq)
        {
            var dsCoordSeq = coordSeq as DotSpatialAffineCoordinateSequence;
            var count = coordSeq.Count;
            if (dsCoordSeq != null)
            {
                _xy = new double[2 * count];
                Buffer.BlockCopy(dsCoordSeq._xy, 0, _xy, 0, 16 * count);
                if (dsCoordSeq.Z != null)
                {
                    _z = new double[dsCoordSeq.Count];
                    Buffer.BlockCopy(dsCoordSeq._z, 0, _z, 0, 8 * count);
                }

                if (dsCoordSeq.M != null)
                {
                    _m = new double[dsCoordSeq.Count];
                    Buffer.BlockCopy(dsCoordSeq._m, 0, _m, 0, 8 * count);
                }

                _ordinates = dsCoordSeq._ordinates;
                return;
            }

            _xy = new double[2 * coordSeq.Count];
            if ((coordSeq.Ordinates & Ordinates.Z) != 0)
                _z = new double[coordSeq.Count];

            if ((coordSeq.Ordinates & Ordinates.M) != 0)
                _m = new double[coordSeq.Count];

            var j = 0;
            for (var i = 0; i < coordSeq.Count; i++)
            {
                _xy[j++] = coordSeq.GetX(i);
                _xy[j++] = coordSeq.GetY(i);
                if (_z != null) _z[i] = coordSeq.GetOrdinate(i, Ordinate.Z);
                if (_m != null) _m[i] = coordSeq.GetOrdinate(i, Ordinate.M);
            }
        }
Exemplo n.º 21
0
            public void Filter(ICoordinateSequence seq, int i)
            {
                double x = seq.GetX(i);
                double y = seq.GetY(i);

                if (_ctx.IsGeo() && _normalizeGeomCoords)
                {
                    double xNorm = DistanceUtils.NormLonDEG(x);
                    if (x != xNorm)
                    {
                        changed = true;
                        seq.SetOrdinate(i, Ordinate.X, xNorm);
                    }

                    double yNorm = DistanceUtils.NormLatDEG(y);
                    if (y != yNorm)
                    {
                        changed = true;
                        seq.SetOrdinate(i, Ordinate.Y, yNorm);
                    }
                }
                else
                {
                    _ctx.VerifyX(x);
                    _ctx.VerifyY(y);
                }
            }
 public OctagonalEnvelope ExpandToInclude(ICoordinateSequence seq)
 {
     for (int i = 0; i < seq.Count; i++)
     {
         double x = seq.GetX(i);
         double y = seq.GetY(i);
         ExpandToInclude(x, y);
     }
     return this;
 }
Exemplo n.º 23
0
 public void Filter(ICoordinateSequence seq, int i)
 {
     double x = seq.GetX(i);
     double xNorm = _ctx.NormX(x);
     if (x != xNorm)
     {
         changed = true;
         seq.SetOrdinate(i, Ordinate.X, xNorm);
     }
     double y = seq.GetY(i);
     double yNorm = _ctx.NormY(y);
     if (y != yNorm)
     {
         changed = true;
         seq.SetOrdinate(i, Ordinate.Y, yNorm);
     }
 }
Exemplo n.º 24
0
 ///<summary>Appends the i'th coordinate from the sequence to the writer</summary>
 /// <param name="seq">the <see cref="ICoordinateSequence"/> to process</param>
 /// <param name="i">the index of the coordinate to write</param>
 /// <param name="writer">writer the output writer to append to</param>
 ///<exception cref="IOException"></exception>
 private void AppendCoordinate(ICoordinateSequence seq, int i, TextWriter writer)
 {
     writer.Write(WriteNumber(seq.GetX(i)) + " " + WriteNumber(seq.GetY(i)));
     if (_outputDimension >= 3 && seq.Dimension >= 3)
     {
         double z = seq.GetOrdinate(i, Ordinate.Z);
         if (!Double.IsNaN(z))
         {
             writer.Write(" ");
             writer.Write(WriteNumber(z));
         }
     }
 }