示例#1
0
        public void TestSTAsText()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var g1 = db.Select(() => GeometryConstructors.STMakePoint(-71.064544, 42.28787));

                Assert.AreEqual("POINT(-71.064544 42.28787)", db.Select(() => GeometryOutput.STAsText(g1)));
                Assert.AreEqual("POINT(-71.065 42.288)", db.Select(() => GeometryOutput.STAsText(g1, 3)));
                Assert.AreEqual("POINT(-71 42)", db.Select(() => GeometryOutput.STAsText(g1, 0)));
                Assert.IsNull(db.Select(() => GeometryOutput.STAsText(null)));
            }
        }
        public void TestSTTranslatedXY()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string geomText = "POINT(-71.01 42.37)";
                db.TestGeometries.Value(g => g.Id, 1).Value(p => p.Geometry, () => GeometryInput.STGeomFromText(geomText, 4326)).Insert();
                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STTranslate(1, 0))
                             .Select(g => GeometryOutput.STAsText(g))
                             .Single();

                Assert.AreEqual("POINT(-70.01 42.37)", result);
            }
        }
        public void TestSTAsText()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var g1 = db.Select(() => GeometryConstructors.STMakePoint(-71.064544, 42.28787));

                Assert.AreEqual("POINT(-71.064544 42.28787)", db.Select(() => GeometryOutput.STAsText(g1)));
                Assert.AreEqual("POINT(-71.065 42.288)", db.Select(() => GeometryOutput.STAsText(g1, 3)));
                Assert.AreEqual("POINT(-71 42)", db.Select(() => GeometryOutput.STAsText(g1, 0)));

                Assert.AreEqual(
                    "POLYGON((0 0,0 1,1 1,1 0,0 0))",
                    db.Select(() => GeometryOutput.STAsText("01030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000")));

                Assert.AreEqual(
                    "POINT(111.11 1.11)",
                    db.Select(() => GeometryOutput.STAsText(GeometryInput.STGeomFromEWKT("SRID=4326;POINT(111.1111111 1.1111111)"), 2)));

                Assert.IsNull(db.Select(() => GeometryOutput.STAsText((NTSG)null)));


                const string Wkt2 = "LINESTRING(0 30,120 30)";

                db.TestGeographies
                .Value(g => g.Id, 1)
                .Value(g => g.Geography, () => GeometryInput.STGeogFromText(Wkt2))
                .Insert();

                var geographyText = db.TestGeographies
                                    .Where(g => g.Id == 1)
                                    .Select(g => g.Geography.STAsText())
                                    .Single();

                Assert.AreEqual(Wkt2, geographyText);
            }
        }