Esempio n. 1
0
        public void TestSTUnaryUnion()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "POLYGON((0 1, 0 3, 2 3, 2 1, 0 1))";
                const string Wkt2 = "POLYGON((1 0, 1 2, 3 2, 3 0, 1 0))";

                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1, SRID4326))
                .Insert();

                db.TestGeometries
                .Value(g => g.Id, 2)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2, SRID4326))
                .Insert();

                var result1 = db.TestGeometries
                              .Select(g => GeometryConstructors.STCollect(
                                          db.TestGeometries.Where(g1 => g1.Id == 1).Single().Geometry,
                                          db.TestGeometries.Where(g2 => g2.Id == 2).Single().Geometry)
                                      .STUnaryUnion())
                              .First() as NTSGS.Polygon;

                // "POLYGON((1 0,1 1,0 1,0 3,2 3,2 2,3 2,3 0,1 0))"
                Assert.IsNotNull(result1);
                Assert.AreEqual(9, result1.Coordinates.Length);

                var result2 = db.Select(() => OverlayFunctions.STUnaryUnion("MULTIPOLYGON(((0 1,0 3,2 3,2 1,0 1)),((1 0,1 2,3 2,3 0,1 0)))")) as NTSGS.Polygon;
                Assert.IsNotNull(result2);
                Assert.AreEqual(9, result2.Coordinates.Length);

                Assert.IsNull(db.Select(() => OverlayFunctions.STUnaryUnion((NTSG)null)));
            }
        }
Esempio n. 2
0
        public void TestSTCollect()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(p => p.Geometry, () => GeometryConstructors.STCollect(
                           GeometryInput.STGeomFromText("POINT(1 2)"),
                           GeometryInput.STGeomFromText("POINT(-2 3)")))
                .Insert();

                db.TestGeometries
                .Value(g => g.Id, 2)
                .Value(p => p.Geometry, () => GeometryConstructors.STCollect(
                           GeometryInput.STGeomFromText("POINT(1 2)"),
                           GeometryInput.STGeomFromText("LINESTRING(0 0, 0 1, 1 0, 1 1, 0 0)")))
                .Insert();

                var collected1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STAsText()).Single();
                Assert.AreEqual("MULTIPOINT(1 2,-2 3)", collected1);

                var collected2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STAsText()).Single();
                Assert.AreEqual("GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(0 0,0 1,1 0,1 1,0 0))", collected2);
            }
        }
Esempio n. 3
0
        public void TestSTHasArc()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () =>
                       GeometryConstructors.STCollect(
                           GeometryInput.STGeomFromText("LINESTRING(1 2, 3 4, 5 6)"),
                           GeometryInput.STGeomFromText("CIRCULARSTRING(1 1, 2 3, 4 5, 6 7, 5 6)")))
                .Insert();

                db.TestGeometries
                .Value(g => g.Id, 2)
                .Value(g => g.Geometry, () => null)
                .Insert();

                Assert.IsTrue(db.TestGeometries
                              .Where(g => g.Id == 1)
                              .Select(g => g.Geometry.STHasArc())
                              .Single());

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

                Assert.IsTrue(db.Select(() => GeometryAccessors.STHasArc("CIRCULARSTRING(1 1, 2 3, 4 5, 6 7, 5 6)")));
            }
        }
Esempio n. 4
0
        public void TestSTOrientedEnvelope()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string wkt = "MULTIPOINT ((0 0), (-1 -1), (3 2))";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt))
                .Insert();

                db.TestGeometries
                .Value(g => g.Id, 2)
                .Value(g => g.Geometry, () =>
                       GeometryConstructors.STCollect(
                           GeometryInput.STGeomFromText("LINESTRING(55 75,125 150)"),
                           GeometryConstructors.STPoint(20, 80)))
                .Insert();

                var result1 = db.TestGeometries
                              .Where(g => g.Id == 1)
                              .Select(g => g.Geometry.STOrientedEnvelope().STAsText())
                              .Single();

                Assert.AreEqual("POLYGON((3 2,2.88 2.16,-1.12 -0.84,-1 -1,3 2))", result1);

                var result2 = db.TestGeometries
                              .Where(g => g.Id == 2)
                              .Select(g => g.Geometry.STOrientedEnvelope())
                              .Single() as NTSGS.Polygon;

                Assert.AreEqual(20, result2.ExteriorRing.GetPointN(0).X, 1.0E-8);
                Assert.AreEqual(80, result2.ExteriorRing.GetPointN(0).Y, 1.0E-8);
            }
        }
Esempio n. 5
0
        public void TestSTMinimumBoundingCircle()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string wkt = "LINESTRING(55 75,125 150)";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () =>
                       GeometryConstructors.STCollect(
                           GeometryInput.STGeomFromText(wkt),
                           GeometryConstructors.STPoint(20, 80)))
                .Insert();

                var geometry = db.TestGeometries
                               .Where(g => g.Id == 1)
                               .Select(g => g.Geometry.STAsText())
                               .Single();

                Assert.AreEqual("GEOMETRYCOLLECTION(LINESTRING(55 75,125 150),POINT(20 80))", geometry);

                // TODO: fix 'points must form a closed linestring'
                ////var circle = db.TestGeometries
                ////    .Where(g => g.Id == 1)
                ////    .Select(g => g.Geometry.STMinimumBoundingCircle(8))
                ////    .Single();

                //Assert.AreEqual(135.59714732062, circle.InteriorRings[0].GetPointN(0).X, 1.0E-8);
                //Assert.AreEqual(115, circle.InteriorRings[0].GetPointN(0).Y, 1.0E-8);
            }
        }
        public void TestSTCollect()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryConstructors.STCollect(
                           GeometryInput.STGeomFromText("POINT(1 2)"),
                           GeometryInput.STGeomFromText("POINT(-2 3)")))
                .Insert();

                db.TestGeometries
                .Value(g => g.Id, 2)
                .Value(g => g.Geometry, () => GeometryConstructors.STCollect(
                           GeometryInput.STGeomFromText("POINT(1 2)"),
                           GeometryInput.STGeomFromText("LINESTRING(0 0, 0 1, 1 0, 1 1, 0 0)")))
                .Insert();

                db.TestGeometries
                .Value(g => g.Id, 3)
                .Value(g => g.Geometry, () => GeometryConstructors.STCollect(
                           "POINT(1 2)",
                           "POINT(-2 3)"))
                .Insert();

                db.TestGeometries
                .Value(g => g.Id, 4)
                .Value(g => g.Geometry, () => GeometryConstructors.STCollect(
                           "CIRCULARSTRING(220268 150415,220227 150505,220227 150406)",
                           "CIRCULARSTRING(220227 150406,2220227 150407,220227 150406)"))
                .Insert();

                var collected1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STAsText()).Single();
                Assert.AreEqual("MULTIPOINT(1 2,-2 3)", collected1);

                var collected2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STAsText()).Single();
                Assert.AreEqual("GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(0 0,0 1,1 0,1 1,0 0))", collected2);

                Assert.AreEqual(
                    "MULTIPOINT(1 2,-2 3)",
                    db.TestGeometries
                    .Where(g => g.Id == 3)
                    .Select(g => g.Geometry.STAsText())
                    .Single());

                // Converting to WKT using STAsText to avoid 'Geometry type not recognized. GeometryCode: 11' error.
                Assert.AreEqual(
                    "MULTICURVE(CIRCULARSTRING(220268 150415,220227 150505,220227 150406),CIRCULARSTRING(220227 150406,2220227 150407,220227 150406))",
                    db.TestGeometries
                    .Where(g => g.Id == 4)
                    .Select(g => g.Geometry.STAsText())
                    .Single());
            }
        }