Example #1
0
        public void TestSTNumGeometries()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();

                const string Wkt2 = "GEOMETRYCOLLECTION(MULTIPOINT(-2 3 , -2 2), LINESTRING(5 5, 10 10), POLYGON((-7 4.2, -7.1 5, -7.1 4.3, -7 4.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();
                db.TestGeometries.Value(g => g.Id, 4).Value(g => g.Geometry, () => null).Insert();

                Assert.AreEqual(
                    1,
                    db.TestGeometries
                    .Where(g => g.Id == 1)
                    .Select(g => g.Geometry.STNumGeometries())
                    .Single());

                Assert.AreEqual(
                    3,
                    db.TestGeometries
                    .Where(g => g.Id == 2)
                    .Select(g => g.Geometry.STNumGeometries())
                    .Single());

                Assert.AreEqual(
                    0,
                    db.TestGeometries
                    .Where(g => g.Id == 3)
                    .Select(g => g.Geometry.STNumGeometries())
                    .Single());

                Assert.IsNull(db.TestGeometries
                              .Where(g => g.Id == 4)
                              .Select(g => g.Geometry.STNumGeometries())
                              .Single());

                Assert.AreEqual(
                    3,
                    db.Select(() => GeometryAccessors.STNumGeometries(Wkt2)));
            }
        }