public void TestST3DShortestLine()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string PointWkt = "POINT(100 100 30)";
                const string LineWkt  = "LINESTRING (20 80 20, 98 190 1, 110 180 3, 50 75 1000)";
                var          point    = db.Select(() => GeometryInput.STPointFromText(PointWkt));
                var          line     = db.Select(() => GeometryInput.STLineFromText(LineWkt));

                var sline1 = db.Select(() => MeasurementFunctions.ST3DShortestLine(line, point)) as NTSGS.LineString;
                Assert.AreEqual(54.6993798867619, sline1.Coordinates[0].X, 1.0E-6);
                Assert.AreEqual(128.935022917228, sline1.Coordinates[0].Y, 1.0E-6);
                Assert.AreEqual(11.5475869506606, sline1.Coordinates[0].Z, 1.0E-9);
                Assert.AreEqual(100, sline1.Coordinates[1].X, 1.0E-6);
                Assert.AreEqual(100, sline1.Coordinates[1].Y, 1.0E-6);
                Assert.AreEqual(30, sline1.Coordinates[1].Z, 1.0E-9);

                var sline2 = db.Select(() => MeasurementFunctions.ST3DShortestLine(LineWkt, PointWkt)) as NTSGS.LineString;
                Assert.AreEqual(54.6993798867619, sline2.Coordinates[0].X, 1.0E-6);
                Assert.AreEqual(128.935022917228, sline2.Coordinates[0].Y, 1.0E-6);
                Assert.AreEqual(11.5475869506606, sline2.Coordinates[0].Z, 1.0E-9);
                Assert.AreEqual(100, sline2.Coordinates[1].X, 1.0E-6);
                Assert.AreEqual(100, sline2.Coordinates[1].Y, 1.0E-6);
                Assert.AreEqual(30, sline2.Coordinates[1].Z, 1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.ST3DShortestLine((NTSG)null, null)));
            }
        }
        public void TestSTDistanceSphere()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var point = db.Select(() => GeometryInput.STGeomFromText("POINT(-118 38)", SRID4326));
                var geom  = db.Select(() => GeometryInput.STGeomFromText("LINESTRING(-118.584 38.374,-118.583 38.5)", SRID4326));

                var dist_meters                = db.Select(() => geom.STCentroid().STDistanceSphere(point));
                var dist_utm11_meters          = db.Select(() => geom.STCentroid().STTransform(32611).STDistance(point.STTransform(32611)));
                var dist_degrees               = db.Select(() => geom.STCentroid().STDistance(point));
                var min_dist_line_point_meters = db.Select(() => geom.STTransform(32611).STDistance(point.STTransform(32611)));

                Assert.AreEqual(70424.71, dist_meters.Value, 0.01);
                Assert.AreEqual(70438.00, dist_utm11_meters.Value, 0.01);
                Assert.AreEqual(0.72900, dist_degrees.Value, 0.00001);
                Assert.AreEqual(65871.18, min_dist_line_point_meters.Value, 0.01);

                Assert.AreEqual(
                    111195.07973463,
                    db.Select(() => MeasurementFunctions.STDistanceSphere(
                                  "SRID=4326;POINT(0 0)",
                                  "SRID=4326;POINT(0 1)")).Value,
                    1.0E-6);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STDistanceSphere((NTSG)null, (NTSG)null)));
            }
        }
        public void TestSTArea()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Ewkt1 = "SRID=2249;POLYGON((743238 2967416,743238 2967450, 743265 2967450,743265.625 2967416,743238 2967416))";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Ewkt1))
                .Insert();

                const string Wkt2 = "LINESTRING(0 0, 1 1)";
                db.TestGeometries
                .Value(g => g.Id, 2)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2))
                .Insert();
                db.TestGeometries
                .Value(g => g.Id, 3)
                .Value(g => g.Geometry, () => null)
                .Insert();

                Assert.AreEqual(928.625, db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STArea()).Single().Value, 1.0E-3);
                Assert.AreEqual(86.2724306, db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STTransform(26986).STArea()).Single().Value, 1.0E-5);
                Assert.AreEqual(0.0, db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STArea()).Single().Value);
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STArea()).Single());

                Assert.AreEqual(928.625, db.Select(() => MeasurementFunctions.STArea(Ewkt1)).Value, 1.0E-3);
                Assert.AreEqual(0.0, db.Select(() => MeasurementFunctions.STArea(Wkt2)));
            }
        }
        public void TestSTDistanceSpheroid()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Spheroid = "SPHEROID[\"WGS 84\",6378137,298.257223563]";
                var          point    = db.Select(() => GeometryInput.STGeomFromText("POINT(-118 38)", SRID4326));
                var          geom     = db.Select(() => GeometryInput.STGeomFromText("LINESTRING(-118.584 38.374,-118.583 38.5)", SRID4326));

                var dist_meters_spheroid = db.Select(() => geom.STCentroid().STDistanceSpheroid(point, Spheroid));
                var dist_meters_sphere   = db.Select(() => geom.STCentroid().STDistanceSphere(point));
                var dist_utm11_meters    = db.Select(() => geom.STCentroid().STTransform(32611).STDistance(point.STTransform(32611)));

                Assert.AreEqual(70454.92, dist_meters_spheroid.Value, 0.01);
                Assert.AreEqual(70424.71, dist_meters_sphere.Value, 0.01);
                Assert.AreEqual(70438.00, dist_utm11_meters.Value, 0.01);

                Assert.AreEqual(
                    4434.73734584354,
                    db.Select(() => MeasurementFunctions.STDistanceSpheroid(
                                  "SRID=4326;POINT(120.08 30.96)",
                                  "SRID=4326;POINT(120.08 30.92)",
                                  Spheroid)).Value,
                    1.0E-8);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STDistanceSpheroid((NTSG)null, (NTSG)null, Spheroid)));
            }
        }
        public void TestSTLengthSpheroid()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Spheroid = "SPHEROID[\"GRS_1980\",6378137,298.257222101]";
                const string Wkt      = "MULTILINESTRING((-118.584 38.374,-118.583 38.5), (-71.05957 42.3589, -71.061 43))";
                var          geom1    = db.Select(() => GeometryInput.STGeomFromText(Wkt));

                var length1 = db.Select(() => MeasurementFunctions.STLengthSpheroid(geom1, Spheroid));
                Assert.AreEqual(85204.5207711811, length1.Value, 1.0E-9);

                var length2 = db.Select(() => MeasurementFunctions.STLengthSpheroid(geom1.STGeometryN(1), Spheroid));
                Assert.AreEqual(13986.8725282447, length2.Value, 1.0E-9);

                var length3 = db.Select(() => MeasurementFunctions.STLengthSpheroid(geom1.STGeometryN(2), Spheroid));
                Assert.AreEqual(71217.6482429363, length3.Value, 1.0E-9);

                Assert.AreEqual(
                    85204.5207711811,
                    db.Select(() => MeasurementFunctions.STLengthSpheroid(Wkt, Spheroid)).Value,
                    1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STLengthSpheroid((NTSG)null, Spheroid)));
            }
        }
        public void TestST3DClosestPoint()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string PointWkt = "POINT(100 100 30)";
                const string LineWkt  = "LINESTRING (20 80 20, 98 190 1, 110 180 3, 50 75 1000)";

                var point = db.Select(() => GeometryInput.STPointFromText(PointWkt));
                var line  = db.Select(() => GeometryInput.STLineFromText(LineWkt));

                var point1 = db.Select(() => MeasurementFunctions.ST3DClosestPoint(line, point)) as NTSGS.Point;
                var point2 = db.Select(() => MeasurementFunctions.STClosestPoint(line, point)) as NTSGS.Point;

                Assert.AreEqual(54.6993798867619, point1.X, 1.0E-9);
                Assert.AreEqual(128.935022917228, point1.Y, 1.0E-9);
                Assert.AreEqual(11.5475869506606, point1.Z, 1.0E-9);

                Assert.AreEqual(73.0769230769231, point2.X, 1.0E-9);
                Assert.AreEqual(115.384615384615, point2.Y, 1.0E-9);

                Assert.AreEqual(
                    54.6993798867619,
                    db.Select(() => MeasurementFunctions.ST3DClosestPoint(LineWkt, PointWkt).STX()).Value,
                    1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.ST3DClosestPoint((NTSG)null, (NTSG)null)));
            }
        }
        public void TestST3DPerimeter()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var geometry1  = db.Select(() => GeometryInput.STGeomFromEWKT("SRID=2249;POLYGON((743238 2967416 2,743238 2967450 1,743265.625 2967416 1, 743238 2967416 2))"));
                var perimeter1 = db.Select(() => MeasurementFunctions.ST3DPerimeter(geometry1));
                Assert.AreEqual(105.465793597674, perimeter1, 1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.ST3DPerimeter(null)));
            }
        }
        public void TestSTMinimumClearanceLine()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var geometry1 = db.Select(() => GeometryInput.STGeomFromText("POLYGON ((0 0, 1 0, 1 1, 0.5 3.2e-4, 0 0))"));
                var lline1    = db.Select(() => MeasurementFunctions.STMinimumClearanceLine(geometry1).STAsEWKT());
                Assert.AreEqual("LINESTRING(0.5 0.00032,0.5 0)", lline1);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STMinimumClearanceLine(null)));
            }
        }
        public void TestSTMinimumClearance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var geometry1         = db.Select(() => GeometryInput.STGeomFromText("POLYGON ((0 0, 1 0, 1 1, 0.5 3.2e-4, 0 0))"));
                var minimumClearance1 = db.Select(() => MeasurementFunctions.STMinimumClearance(geometry1));
                Assert.AreEqual(0.00032, minimumClearance1, 1.0E-5);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STMinimumClearance(null)));
            }
        }
        public void TestST3DMaxDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var pt   = db.Select(() => GeometryInput.STGeomFromEWKT("SRID=4326;POINT(-72.1235 42.3521 10000)").STTransform(2163));
                var line = db.Select(() => GeometryInput.STGeomFromEWKT("SRID=4326;LINESTRING(-72.1260 42.45 15, -72.123 42.1546 20)").STTransform(2163));

                var maxDistance1 = db.Select(() => MeasurementFunctions.ST3DMaxDistance(pt, line));
                Assert.AreEqual(24383.7467488441, maxDistance1, 1.0E-9);
            }
        }
        public void TestSTMaxDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var pt   = db.Select(() => GeometryInput.STPointFromText("POINT(0 0)"));
                var line = db.Select(() => GeometryInput.STLineFromText("LINESTRING ( 2 2, 2 2 )"));

                var maxDistance1 = db.Select(() => MeasurementFunctions.STMaxDistance(pt, line));
                Assert.AreEqual(2.82842712474619, maxDistance1, 1.0E-9);
            }
        }
        public void TestST3DLongestLine()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var pt   = db.Select(() => GeometryInput.STPointFromText("POINT(100 100 30)"));
                var line = db.Select(() => GeometryInput.STLineFromText("LINESTRING (20 80 20, 98 190 1, 110 180 3, 50 75 1000)"));

                var lline1 = db.Select(() => MeasurementFunctions.ST3DLongestLine(line, pt).STAsEWKT());

                Assert.AreEqual("LINESTRING(50 75 1000,100 100 30)", lline1);
            }
        }
        public void TestST3DLength()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var geom1 = db.Select(() => GeometryInput.STGeomFromText("LINESTRING(743238 2967416 1,743238 2967450 1,743265 2967450 3,743265.625 2967416 3, 743238 2967416 3)", 2249));

                var length1 = db.Select(() => MeasurementFunctions.ST3DLength(geom1));
                Assert.AreEqual(122.704716741457, length1, 1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.ST3DLength(null)));
            }
        }
        public void TestSTShortestLine()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var pt   = db.Select(() => GeometryInput.STPointFromText("POINT(100 100)"));
                var line = db.Select(() => GeometryInput.STLineFromText("LINESTRING (20 80, 98 190, 110 180, 50 75)"));

                var sline1 = db.Select(() => MeasurementFunctions.STShortestLine(pt, line).STAsText());
                Assert.AreEqual("LINESTRING(100 100,73.0769230769231 115.384615384615)", sline1);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STShortestLine(null, null)));
            }
        }
        public void TestST3DShortestLine()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var pt   = db.Select(() => GeometryInput.STPointFromText("POINT(100 100 30)"));
                var line = db.Select(() => GeometryInput.STLineFromText("LINESTRING (20 80 20, 98 190 1, 110 180 3, 50 75 1000)"));

                var sline1 = db.Select(() => MeasurementFunctions.ST3DShortestLine(line, pt).STAsEWKT());
                Assert.AreEqual("LINESTRING(54.6993798867619 128.935022917228 11.5475869506606,100 100 30)", sline1);

                Assert.IsNull(db.Select(() => MeasurementFunctions.ST3DShortestLine(null, null)));
            }
        }
        public void TestST3DDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                Assert.AreEqual(
                    1.732,
                    db.Select(() => MeasurementFunctions.ST3DDistance(
                                  "POINT(0 0 0)",
                                  "POINT(1 1 1)")).Value,
                    1.0E-3);

                Assert.IsNull(db.Select(() => MeasurementFunctions.ST3DDistance((NTSG)null, (NTSG)null)));
            }
        }
        public void TestSTClosestPoint()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var pt   = db.Select(() => GeometryInput.STPointFromText("POINT(100 100)"));
                var line = db.Select(() => GeometryInput.STLineFromText("LINESTRING (20 80, 98 190, 110 180, 50 75)"));

                var p1 = db.Select(() => MeasurementFunctions.STClosestPoint(pt, line).STAsText());
                var p2 = db.Select(() => MeasurementFunctions.STClosestPoint(line, pt).STAsText());

                Assert.AreEqual("POINT(100 100)", p1);
                Assert.AreEqual("POINT(73.0769230769231 115.384615384615)", p2);
            }
        }
        public void TestSTMinimumClearance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt              = "POLYGON ((0 0, 1 0, 1 1, 0.5 3.2e-4, 0 0))";
                var          geometry         = db.Select(() => GeometryInput.STGeomFromText(Wkt));
                var          minimumClearance = db.Select(() => MeasurementFunctions.STMinimumClearance(geometry));
                Assert.AreEqual(0.00032, minimumClearance.Value, 1.0E-5);

                Assert.AreEqual(0.00032, db.Select(() => MeasurementFunctions.STMinimumClearance(Wkt)).Value, 1.0E-5);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STMinimumClearance((NTSG)null)));
            }
        }
        public void TestST3DClosestPoint()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var pt   = db.Select(() => GeometryInput.STPointFromText("POINT(100 100 30)"));
                var line = db.Select(() => GeometryInput.STLineFromText("LINESTRING (20 80 20, 98 190 1, 110 180 3, 50 75 1000)"));

                var p1 = db.Select(() => MeasurementFunctions.ST3DClosestPoint(line, pt).STAsEWKT());
                var p2 = db.Select(() => MeasurementFunctions.STClosestPoint(line, pt).STAsEWKT());

                Assert.AreEqual("POINT(54.6993798867619 128.935022917228 11.5475869506606)", p1);
                Assert.AreEqual("POINT(73.0769230769231 115.384615384615)", p2);
            }
        }
        public void TestSTFrechetDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var geom1 = db.Select(() => GeometryInput.STGeomFromText("LINESTRING (0 0, 100 0)"));
                var geom2 = db.Select(() => GeometryInput.STGeomFromText("LINESTRING (0 0, 50 50, 100 0)"));

                var dist1 = db.Select(() => geom1.STFrechetDistance(geom2));
                Assert.AreEqual(70.7106781186548, dist1, 1.0E-9);

                var dist2 = db.Select(() => geom1.STFrechetDistance(geom2, 0.5));
                Assert.AreEqual(50.0, dist2, 1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STFrechetDistance(null, null)));
            }
        }
        public void TestSTHausdorffDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var geom1  = db.Select(() => GeometryInput.STGeomFromText("LINESTRING (0 0, 2 0)"));
                var geom2  = db.Select(() => GeometryInput.STGeomFromText("MULTIPOINT (0 1, 1 0, 2 1)"));
                var dist12 = db.Select(() => geom1.STHausdorffDistance(geom2));
                Assert.AreEqual(1, dist12, 1.0E-9);

                var geom3  = db.Select(() => GeometryInput.STGeomFromText("LINESTRING (130 0, 0 0, 0 150)"));
                var geom4  = db.Select(() => GeometryInput.STGeomFromText("LINESTRING (10 10, 10 150, 130 10)"));
                var dist34 = db.Select(() => geom3.STHausdorffDistance(geom4, 0.5));
                Assert.AreEqual(70, dist34, 70.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STHausdorffDistance(null, null)));
            }
        }
        public void TestSTAngle()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var p1 = db.Select(() => GeometryConstructors.STPoint(0, 0));
                var p2 = db.Select(() => GeometryConstructors.STPoint(100, 100));
                var p3 = db.Select(() => GeometryConstructors.STPoint(0, 0));
                var p4 = db.Select(() => GeometryConstructors.STPoint(100, 0));

                var a1 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAngle(p1, p2, p3, p4)));
                Assert.AreEqual(45, a1.Value, 1.0E-8);

                var a2 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAngle(p2, p1, p4)));
                Assert.AreEqual(45, a2.Value, 1.0E-8);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STAngle(p1, p1, p1, p1)));
            }
        }
        public void TestSTAzimuth()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var p1 = db.Select(() => GeometryConstructors.STPoint(25, 45));
                var p2 = db.Select(() => GeometryConstructors.STPoint(75, 100));

                var a1 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAzimuth(p1, p2)));
                var a2 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAzimuth(p2, p1)));

                Assert.AreEqual(42.2736890060937, a1, 1.0E-8);
                Assert.AreEqual(222.273689006094, a2, 1.0E-8);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(p1, p1)));
                Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(p1, null)));
                Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(null, p1)));
            }
        }
        public void TestST3DLongestLine()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string PointWkt = "POINT(100 100 30)";
                const string LineWkt  = "LINESTRING (20 80 20, 98 190 1, 110 180 3, 50 75 1000)";
                var          point    = db.Select(() => GeometryInput.STPointFromText(PointWkt));
                var          line     = db.Select(() => GeometryInput.STLineFromText(LineWkt));

                var lline1 = db.Select(() => MeasurementFunctions.ST3DLongestLine(line, point).STAsEWKT());

                Assert.AreEqual("LINESTRING(50 75 1000,100 100 30)", lline1);

                Assert.AreEqual(
                    "LINESTRING(50 75 1000,100 100 30)",
                    db.Select(() => MeasurementFunctions.ST3DLongestLine(LineWkt, PointWkt).STAsEWKT()));

                Assert.IsNull(db.Select(() => MeasurementFunctions.ST3DLongestLine((NTSG)null, (NTSG)null)));
            }
        }
        public void TestSTProject()
        {
            const string wkt = "POINT(0 0)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var result1 = db.Select(() => MeasurementFunctions.STProject(GeometryInput.STGeomFromText(wkt), 100000, (Math.PI / 180.0) * 45.0)) as NTSGS.Point;
                var result2 = db.Select(() => MeasurementFunctions.STProject(wkt, 100000, (Math.PI / 180.0) * 45.0)) as NTSGS.Point;
                var result3 = db.Select(() => MeasurementFunctions.STProject((NTSG)null, 100000, (Math.PI / 180.0) * 45.0)) as NTSGS.Point;

                Assert.IsNotNull(result1);
                Assert.AreEqual(0.635231029125537, result1.X, 1.0E-5);
                Assert.AreEqual(0.639472334729198, result1.Y, 1.0E-5);

                Assert.IsNotNull(result2);
                Assert.AreEqual(0.635231029125537, result2.X, 1.0E-5);
                Assert.AreEqual(0.639472334729198, result2.Y, 1.0E-5);

                Assert.IsNull(result3);
            }
        }
        public void TestSTAzimuth()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var p1 = db.Select(() => GeometryConstructors.STPoint(25, 45));
                var p2 = db.Select(() => GeometryConstructors.STPoint(75, 100));

                var a1 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAzimuth(p1, p2)));
                var a2 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAzimuth(p2, p1)));

                Assert.AreEqual(42.2736890060937, a1.Value, 1.0E-8);
                Assert.AreEqual(222.273689006094, a2.Value, 1.0E-8);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(p1, p1)));
                Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(p1, null)));
                Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(null, p1)));
                ////Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth((NTSG)null, (NTSG)null)));


                var pointA = new NTSGS.Point(0, 0)
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeographyEntity(1, pointA));

                var pointB = new NTSGS.Point(15, 5)
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeographyEntity(2, pointB));

                var azimuth = db.TestGeographies
                              .Where(g => g.Id == 1)
                              .Select(g => g.Geography.STAzimuth(db.TestGeographies.Where(g0 => g0.Id == 2).Single().Geography))
                              .Single();

                Assert.AreEqual(1.24683, azimuth.Value, 1.0E-5);
            }
        }
        public void TestST3DMaxDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string PointEwkt = "SRID=4326;POINT(-72.1235 42.3521 10000)";
                const string LineEwkt  = "SRID=4326;LINESTRING(-72.1260 42.45 15, -72.123 42.1546 20)";
                var          point     = db.Select(() => GeometryInput.STGeomFromEWKT(PointEwkt).STTransform(2163));
                var          line      = db.Select(() => GeometryInput.STGeomFromEWKT(LineEwkt).STTransform(2163));

                var maxDistance1 = db.Select(() => MeasurementFunctions.ST3DMaxDistance(point, line));
                Assert.AreEqual(24383.7467488441, maxDistance1.Value, 1.0E-9);

                Assert.AreEqual(
                    1.732,
                    db.Select(() => MeasurementFunctions.ST3DMaxDistance(
                                  "POINT(0 0 0)",
                                  "POINT(1 1 1)")).Value,
                    1.0E-3);

                Assert.IsNull(db.Select(() => MeasurementFunctions.ST3DMaxDistance((NTSG)null, (NTSG)null)));
            }
        }
        public void TestSTMaxDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string PointWkt = "POINT(0 0)";
                const string LineWkt  = "LINESTRING (2 2, 2 2)";
                var          point    = db.Select(() => GeometryInput.STPointFromText(PointWkt));
                var          line     = db.Select(() => GeometryInput.STLineFromText(LineWkt));

                Assert.AreEqual(
                    2.82842712474619,
                    db.Select(() => MeasurementFunctions.STMaxDistance(point, line)).Value,
                    1.0E-9);

                Assert.AreEqual(
                    2.82842712474619,
                    db.Select(() => MeasurementFunctions.STMaxDistance(PointWkt, LineWkt)).Value,
                    1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STMaxDistance((NTSG)null, (NTSG)null)));
            }
        }
        public void TestSTShortestLine()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string PointWkt = "POINT(100 100)";
                const string LineWkt  = "LINESTRING (20 80, 98 190, 110 180, 50 75)";
                var          point    = db.Select(() => GeometryInput.STPointFromText(PointWkt));
                var          line     = db.Select(() => GeometryInput.STLineFromText(LineWkt));

                var sline1 = db.Select(() => MeasurementFunctions.STShortestLine(point, line)) as NTSGS.LineString;
                Assert.AreEqual(100, sline1.Coordinates[0].X, 1.0E-6);
                Assert.AreEqual(100, sline1.Coordinates[0].Y, 1.0E-6);
                Assert.AreEqual(73.0769230769231, sline1.Coordinates[1].X, 1.0E-9);
                Assert.AreEqual(115.384615384615, sline1.Coordinates[1].Y, 1.0E-9);

                var sline2 = db.Select(() => MeasurementFunctions.STShortestLine(PointWkt, LineWkt)) as NTSGS.LineString;
                Assert.AreEqual(100, sline2.Coordinates[0].X, 1.0E-6);
                Assert.AreEqual(100, sline2.Coordinates[0].Y, 1.0E-6);
                Assert.AreEqual(73.0769230769231, sline2.Coordinates[1].X, 1.0E-9);
                Assert.AreEqual(115.384615384615, sline2.Coordinates[1].Y, 1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STShortestLine((NTSG)null, null)));
            }
        }
        public void TestSTClosestPoint()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string PointWkt = "POINT(100 100)";
                const string LineWkt  = "LINESTRING (20 80, 98 190, 110 180, 50 75)";

                var point = db.Select(() => GeometryInput.STPointFromText(PointWkt));
                var line  = db.Select(() => GeometryInput.STLineFromText(LineWkt));

                var p1 = db.Select(() => MeasurementFunctions.STClosestPoint(point, line).STAsText());
                var p2 = db.Select(() => MeasurementFunctions.STClosestPoint(line, point)) as NTSGS.Point;

                Assert.AreEqual("POINT(100 100)", p1);
                Assert.AreEqual(73.0769230769231, p2.X, 1.0E-9);
                Assert.AreEqual(115.384615384615, p2.Y, 1.0E-9);

                Assert.AreEqual(
                    "POINT(100 100)",
                    db.Select(() => MeasurementFunctions.STClosestPoint(PointWkt, LineWkt).STAsText()));

                Assert.IsNull(db.Select(() => MeasurementFunctions.STClosestPoint((NTSG)null, (NTSG)null)));
            }
        }