示例#1
0
        public void TestSTXYZM()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "POINT(1 2 3 4)";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();

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

                const string Wkt3 = "POINT EMPTY";
                db.TestGeometries.Value(g => g.Id, 3).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt3)).Insert();

                var query1 = db.TestGeometries.Where(g => g.Id == 1);
                Assert.AreEqual(1, query1.Select(g => g.Geometry.STX()).Single());
                Assert.AreEqual(2, query1.Select(g => g.Geometry.STY()).Single());
                Assert.AreEqual(3, query1.Select(g => g.Geometry.STZ()).Single());
                Assert.AreEqual(4, query1.Select(g => g.Geometry.STM()).Single());
                Assert.AreEqual(1, db.Select(() => GeometryAccessors.STX(Wkt1)));
                Assert.AreEqual(2, db.Select(() => GeometryAccessors.STY(Wkt1)));
                Assert.AreEqual(3, db.Select(() => GeometryAccessors.STZ(Wkt1)));
                Assert.AreEqual(4, db.Select(() => GeometryAccessors.STM(Wkt1)));

                var query2 = db.TestGeometries.Where(g => g.Id == 2);
                Assert.AreEqual(1, query2.Select(g => g.Geometry.STX()).Single());
                Assert.AreEqual(2, query2.Select(g => g.Geometry.STY()).Single());
                Assert.IsNull(query2.Select(g => g.Geometry.STZ()).Single());
                Assert.IsNull(query2.Select(g => g.Geometry.STM()).Single());
                Assert.IsNull(db.Select(() => GeometryAccessors.STZ(Wkt2)));
                Assert.IsNull(db.Select(() => GeometryAccessors.STM(Wkt2)));

                var query3 = db.TestGeometries.Where(g => g.Id == 3);
                Assert.IsNull(query3.Select(g => g.Geometry.STX()).Single());
                Assert.IsNull(query3.Select(g => g.Geometry.STY()).Single());
                Assert.IsNull(query2.Select(g => g.Geometry.STZ()).Single());
                Assert.IsNull(query2.Select(g => g.Geometry.STM()).Single());

                Assert.IsNull(db.Select(() => GeometryAccessors.STM((NTSG)null)));
                Assert.AreEqual(4, db.Select(() => GeometryAccessors.STM(Wkt1)));
                Assert.IsNull(db.Select(() => GeometryAccessors.STM(Wkt3)));
            }
        }