public void TeStPointFirstNegativeXValues()
        {
            using (OracleTransaction tr = _con.BeginTransaction())
            {
                for (decimal i = 0; i >= -CoordinatesSystem.Resolution*100; i -= CoordinatesSystem.Resolution)
                {
                    string wkt = "POINT Z (" + i.ToString(CultureInfo.InvariantCulture) + " 0 0)";
                    StTestHelper.Write(wkt);

                    IEsriStGeometryType geo = StTestHelper.GetGeometry(wkt, _con);
                    StTestHelper.Write(geo.Points);
                    StTestHelper.Write(geo.Geometry);

                    // Create point with the same coordinates
                    var p1 = new StPoint(i, 0, 0);
                    StTestHelper.Write(p1);

                    // Assert values are equal
                    StTestHelper.AssertAreEqual((StPoint) geo.Geometry, p1);

                    // Create point from shape
                    var p2 = new StPoint(geo.Points);
                    StTestHelper.Write(p2);

                    // Assert values are equal
                    StTestHelper.AssertAreEqual((StPoint) geo.Geometry, p2);
                }

                tr.Rollback();
            }
        }
        public void TestCoordSystemLimitMaxX()
        {
            using (OracleTransaction tr = _con.BeginTransaction())
            {
                decimal val = CoordinatesSystem.MaxX;

                string wkt = "POINT Z (" + val.ToString("0.####", CultureInfo.InvariantCulture) + " 0 0)";
                StTestHelper.Write(wkt);

                IEsriStGeometryType geo = StTestHelper.GetGeometry(wkt, _con);
                StTestHelper.Write(geo.Points);
                StTestHelper.Write(geo.Geometry);

                // Create point with the same coordinates
                var p1 = new StPoint(val, 0, 0);
                StTestHelper.Write(p1);

                // Assert values are equal
                StTestHelper.AssertAreEqual((StPoint) geo.Geometry, p1);

                // Create point from shape
                var p2 = new StPoint(geo.Points);
                StTestHelper.Write(p2);

                // Assert values are equal
                StTestHelper.AssertAreEqual((StPoint) geo.Geometry, p2);

                tr.Rollback();
            }
        }
        public static string GetCoordinateWkt(StPoint point)
        {
            var str = new StringBuilder();
            str.Append(point.X).Append(" ").Append(point.Y);
            if (point.HasZ)
                str.Append(" ").Append(point.Z);
            if (point.HasM)
                str.Append(" ").Append(point.M);

            return str.ToString();
        }
 public static void AssertAreEqual(StPoint geo1, StPoint geo2)
 {
     // Compare geometry objects
     Assert.AreEqual(geo1.HasZ, geo2.HasZ);
     Assert.AreEqual(geo1.HasM, geo2.HasM);
     Assert.AreEqual(geo1.X.Value, geo2.X.Value);
     Assert.AreEqual(geo1.Y.Value, geo2.Y.Value);
     if (geo1.HasZ)
         Assert.AreEqual(geo1.Z.Value, geo2.Z.Value);
     if (geo1.HasM)
         Assert.AreEqual(geo1.M.Value, geo2.M.Value);
     // Compare bytes
     AssertAreEqual(geo1.Bytes, geo2.Bytes);
 }
        public StLineString(string wkt)
        {
            if (wkt.ToUpper().Contains("Z"))
            {
                HasZ = true;
            }
            if (wkt.ToUpper().Contains("M"))
            {
                HasM = true;
            }

            Points = new List <StPoint>();

            string coordsText = wkt.ToUpper().Replace("LINESTRING", String.Empty).Replace("Z", String.Empty).Replace("M", String.Empty).Replace("(", String.Empty).Replace(")", String.Empty).Trim();

            string[] points = coordsText.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string point in points)
            {
                string[] coords = point.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                decimal x = Convert.ToDecimal(coords[0], CultureInfo.InvariantCulture);
                decimal y = Convert.ToDecimal(coords[1], CultureInfo.InvariantCulture);
                decimal?z = null;
                decimal?m = null;

                if (HasZ && HasM)
                {
                    z = Convert.ToDecimal(coords[2], CultureInfo.InvariantCulture);
                    m = Convert.ToDecimal(coords[3], CultureInfo.InvariantCulture);
                }
                else if (HasZ)
                {
                    z = Convert.ToDecimal(coords[2], CultureInfo.InvariantCulture);
                }
                else if (HasM)
                {
                    m = Convert.ToDecimal(coords[2], CultureInfo.InvariantCulture);
                }

                var p = new StPoint(x, y, z, m);
                Points.Add(p);
            }

            CalculateMinMaxAndLengthValues();
            CalculateBytes();
        }
        public void TeStPointZZero()
        {
            using (OracleTransaction tr = _con.BeginTransaction())
            {
                string wkt = "POINT Z (0 0 0)";
                StTestHelper.Write(wkt);

                IEsriStGeometryType geo = StTestHelper.GetGeometry(wkt, _con);
                StTestHelper.Write(geo.Points);
                StTestHelper.Write(geo.Geometry);

                // Create point with the same coordinates
                var p1 = new StPoint(0m, 0, 0);
                StTestHelper.Write(p1);

                // Assert values are equal
                StTestHelper.AssertAreEqual((StPoint) geo.Geometry, p1);

                // Create point from shape
                var p2 = new StPoint(geo.Points);
                StTestHelper.Write(p2);

                // Assert values are equal
                StTestHelper.AssertAreEqual((StPoint) geo.Geometry, p2);

                tr.Rollback();
            }
        }
        public void TeStPointZWkt()
        {
            using (OracleTransaction tr = _con.BeginTransaction())
            {
                string wkt = "POINT Z (0.0001 0.0002 10)";
                StTestHelper.Write(wkt);

                var geo = new StPoint(0.0001m, 0.0002m, 10);
                StTestHelper.Write(geo);

                Assert.AreEqual(wkt, geo.ToString());

                tr.Rollback();
            }
        }
        public void TeStPointZerosPositiveLimitZ()
        {
            using (OracleTransaction tr = _con.BeginTransaction())
            {
                for (int j = 1; j < CoordinatesSystem.ByteFactors.Length; ++j)
                {
                    decimal diff = CoordinatesSystem.ByteFactors[j];

                    if (diff > CoordinatesSystem.MaxZ)
                    {
                        // Coordinates Limits are reached
                        // We do not test those values
                        continue;
                    }

                    for (int i = -5; i <= 5; ++i)
                    {
                        decimal val = diff + (i*CoordinatesSystem.Resolution);

                        string wkt = "POINT Z (0 0 " + val.ToString("0.####", CultureInfo.InvariantCulture) + ")";
                        StTestHelper.Write(wkt);

                        IEsriStGeometryType geo = StTestHelper.GetGeometry(wkt, _con);
                        StTestHelper.Write(geo.Points);
                        StTestHelper.Write(geo.Geometry);

                        // Create point with the same coordinates
                        var p1 = new StPoint(0, 0, val);
                        StTestHelper.Write(p1);

                        // Assert values are equal
                        StTestHelper.AssertAreEqual((StPoint) geo.Geometry, p1);

                        // Create point from shape
                        var p2 = new StPoint(geo.Points);
                        StTestHelper.Write(p2);

                        // Assert values are equal
                        StTestHelper.AssertAreEqual((StPoint) geo.Geometry, p2);
                    }
                }

                tr.Rollback();
            }
        }
        public StLineString(string wkt)
        {
            if (wkt.ToUpper().Contains("Z"))
                HasZ = true;
            if (wkt.ToUpper().Contains("M"))
                HasM = true;

            Points = new List<StPoint>();

            string coordsText = wkt.ToUpper().Replace("LINESTRING", String.Empty).Replace("Z", String.Empty).Replace("M", String.Empty).Replace("(", String.Empty).Replace(")", String.Empty).Trim();
            string[] points = coordsText.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string point in points)
            {
                string[] coords = point.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                decimal x = Convert.ToDecimal(coords[0], CultureInfo.InvariantCulture);
                decimal y = Convert.ToDecimal(coords[1], CultureInfo.InvariantCulture);
                decimal? z = null;
                decimal? m = null;

                if (HasZ && HasM)
                {
                    z = Convert.ToDecimal(coords[2], CultureInfo.InvariantCulture);
                    m = Convert.ToDecimal(coords[3], CultureInfo.InvariantCulture);
                }
                else if (HasZ)
                    z = Convert.ToDecimal(coords[2], CultureInfo.InvariantCulture);
                else if (HasM)
                    m = Convert.ToDecimal(coords[2], CultureInfo.InvariantCulture);

                var p = new StPoint(x, y, z, m);
                Points.Add(p);
            }

            CalculateMinMaxAndLengthValues();
            CalculateBytes();
        }
示例#10
0
        private void SetGeometry(List<List<byte>> bytesList)
        {
            // Bytes are NOT stored in an intuitive way : X1 Y1 Z1   X2 Y2 Z2   X3 Y3 Z3
            // But in a other way : X1 Y1   X2 Y2   X3 Y3   Z1 Z2 Z3
            // Ex : LINESTRING Z (0 0 0, 1 1 1) : {128 168 198 186 141 17} {128 239 136 224 159 19} {144 156 1} {144 156 1} {128 168 214 185 7} {144 156 1}

            if (HasM)
                throw new NotSupportedException("M not managed yet : Code is written, but not tested");

            Points = new List<StPoint>();

            int zIndex = 0;
            int mIndex = 0;
            int count = bytesList.Count;
            if (HasZ && HasM)
            {
                zIndex = bytesList.Count / 4 * 2;
                mIndex = bytesList.Count / 4 * 3;
                count = bytesList.Count / 2;
            }
            else if (HasZ || HasM)
            {
                zIndex = bytesList.Count / 3 * 2;
                mIndex = bytesList.Count / 3 * 2;
                count = bytesList.Count / 3 * 2;
            }

            // The first point will be set normaly
            StPoint point;
            if (HasZ && HasM)
                point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray(), bytesList[zIndex].ToArray(), bytesList[mIndex].ToArray());
            else if (HasZ)
                point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray(), bytesList[zIndex].ToArray());
            else if (HasM)
                point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray(), null, bytesList[mIndex].ToArray());
            else
                point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray());
            Points.Add(point);

            // The next point are set with the difference between the current coordinate and the previous one
            StPoint previousPoint = point;
            for (int i = 2; i < count; i += 2)
            {
                byte[] xBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[i].ToArray(), previousPoint.X.Bytes, StParameters.CoordinatesSystem, StCoordType.X);
                byte[] yBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[i + 1].ToArray(), previousPoint.Y.Bytes, StParameters.CoordinatesSystem, StCoordType.Y);

                if (HasZ && HasM)
                {
                    byte[] zBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[zIndex + i / 2].ToArray(), previousPoint.Z.Bytes, StParameters.CoordinatesSystem, StCoordType.Z);
                    byte[] mBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[mIndex + i / 2].ToArray(), previousPoint.M.Bytes, StParameters.CoordinatesSystem, StCoordType.M);
                    point = new StPoint(xBytes, yBytes, zBytes, mBytes);
                }
                else if (HasZ)
                {
                    byte[] zBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[zIndex + i / 2].ToArray(), previousPoint.Z.Bytes, StParameters.CoordinatesSystem, StCoordType.Z);
                    point = new StPoint(xBytes, yBytes, zBytes);
                }
                else if (HasM)
                {
                    byte[] mBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[mIndex + i / 2].ToArray(), previousPoint.M.Bytes, StParameters.CoordinatesSystem, StCoordType.M);
                    point = new StPoint(xBytes, yBytes, null, mBytes);
                }
                else
                    point = new StPoint(xBytes, yBytes);

                Points.Add(point);

                previousPoint = point;
            }
        }
示例#11
0
        private void SetGeometry(List <List <byte> > bytesList)
        {
            // Bytes are NOT stored in an intuitive way : X1 Y1 Z1   X2 Y2 Z2   X3 Y3 Z3
            // But in a other way : X1 Y1   X2 Y2   X3 Y3   Z1 Z2 Z3
            // Ex : LINESTRING Z (0 0 0, 1 1 1) : {128 168 198 186 141 17} {128 239 136 224 159 19} {144 156 1} {144 156 1} {128 168 214 185 7} {144 156 1}

            if (HasM)
            {
                throw new NotSupportedException("M not managed yet : Code is written, but not tested");
            }

            Points = new List <StPoint>();

            int zIndex = 0;
            int mIndex = 0;
            int count  = bytesList.Count;

            if (HasZ && HasM)
            {
                zIndex = bytesList.Count / 4 * 2;
                mIndex = bytesList.Count / 4 * 3;
                count  = bytesList.Count / 2;
            }
            else if (HasZ || HasM)
            {
                zIndex = bytesList.Count / 3 * 2;
                mIndex = bytesList.Count / 3 * 2;
                count  = bytesList.Count / 3 * 2;
            }

            // The first point will be set normaly
            StPoint point;

            if (HasZ && HasM)
            {
                point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray(), bytesList[zIndex].ToArray(), bytesList[mIndex].ToArray());
            }
            else if (HasZ)
            {
                point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray(), bytesList[zIndex].ToArray());
            }
            else if (HasM)
            {
                point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray(), null, bytesList[mIndex].ToArray());
            }
            else
            {
                point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray());
            }
            Points.Add(point);

            // The next point are set with the difference between the current coordinate and the previous one
            StPoint previousPoint = point;

            for (int i = 2; i < count; i += 2)
            {
                byte[] xBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[i].ToArray(), previousPoint.X.Bytes, StParameters.CoordinatesSystem, StCoordType.X);
                byte[] yBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[i + 1].ToArray(), previousPoint.Y.Bytes, StParameters.CoordinatesSystem, StCoordType.Y);

                if (HasZ && HasM)
                {
                    byte[] zBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[zIndex + i / 2].ToArray(), previousPoint.Z.Bytes, StParameters.CoordinatesSystem, StCoordType.Z);
                    byte[] mBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[mIndex + i / 2].ToArray(), previousPoint.M.Bytes, StParameters.CoordinatesSystem, StCoordType.M);
                    point = new StPoint(xBytes, yBytes, zBytes, mBytes);
                }
                else if (HasZ)
                {
                    byte[] zBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[zIndex + i / 2].ToArray(), previousPoint.Z.Bytes, StParameters.CoordinatesSystem, StCoordType.Z);
                    point = new StPoint(xBytes, yBytes, zBytes);
                }
                else if (HasM)
                {
                    byte[] mBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[mIndex + i / 2].ToArray(), previousPoint.M.Bytes, StParameters.CoordinatesSystem, StCoordType.M);
                    point = new StPoint(xBytes, yBytes, null, mBytes);
                }
                else
                {
                    point = new StPoint(xBytes, yBytes);
                }

                Points.Add(point);

                previousPoint = point;
            }
        }
示例#12
0
        private void CalculateMinMaxAndLengthValues()
        {
            MaxX = MinX = Points[0].X.Value;
            MaxY = MinY = Points[0].Y.Value;
            MaxZ = MinZ = (HasZ) ? Points[0].Z.Value : 0;
            MaxM = MinM = (HasM) ? Points[0].M.Value : 0;

            Length2D = Length3D = 0;

            for (int i = 1; i < Points.Count; ++i)
            {
                StPoint point = Points[i];

                // Min & Max
                if (point.X.Value > MaxX)
                {
                    MaxX = point.X.Value;
                }
                if (point.X.Value < MinX)
                {
                    MinX = point.X.Value;
                }

                if (point.Y.Value > MaxY)
                {
                    MaxY = point.Y.Value;
                }
                if (point.Y.Value < MinY)
                {
                    MinY = point.Y.Value;
                }

                if (HasZ)
                {
                    if (point.Z.Value > MaxZ)
                    {
                        MaxZ = point.Z.Value;
                    }
                    if (point.Z.Value < MinZ)
                    {
                        MinZ = point.Z.Value;
                    }
                }

                if (HasM)
                {
                    if (point.M.Value > MaxM)
                    {
                        MaxM = point.M.Value;
                    }
                    if (point.M.Value < MinM)
                    {
                        MinM = point.M.Value;
                    }
                }

                // Length
                StPoint previousPoint = Points[i - 1];
                decimal x2            = Math.Abs(point.X.Value - previousPoint.X.Value);
                decimal y2            = Math.Abs(point.Y.Value - previousPoint.Y.Value);
                var     l2D           = (decimal)Math.Sqrt((Math.Pow((double)x2, 2) + Math.Pow((double)y2, 2)));
                Length2D += l2D;

                if (HasZ)
                {
                    decimal z2  = Math.Abs(point.Z.Value - previousPoint.Z.Value);
                    var     l3D = (decimal)Math.Sqrt((Math.Pow((double)l2D, 2) + Math.Pow((double)z2, 2)));
                    Length3D += l3D;
                }
            }
        }