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)));
            }
        }
Exemplo n.º 2
0
        public void TestSTLocateBetweenElevations()
        {
            const string Wkt = "LINESTRING(1 2 3, 4 5 6)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt))
                .Insert();

                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STLocateBetweenElevations(2.0, 4.0))
                             .Single() as NTSGS.MultiLineString;

                Assert.AreEqual(1, result.NumGeometries);

                Assert.AreEqual(1.0, result.Coordinates[0].X, 1.0E-8);
                Assert.AreEqual(2.0, result.Coordinates[0].Y, 1.0E-8);
                Assert.AreEqual(3.0, result.Coordinates[0].Z, 1.0E-8);

                Assert.AreEqual(2.0, result.Coordinates[1].X, 1.0E-8);
                Assert.AreEqual(3.0, result.Coordinates[1].Y, 1.0E-8);
                Assert.AreEqual(4.0, result.Coordinates[1].Z, 1.0E-8);

                Assert.IsNull(db.Select(() => LinearReferencing.STLocateBetweenElevations((NTSG)null, 0, 0)));

                Assert.AreEqual(
                    1,
                    (db.Select(() => LinearReferencing.STLocateBetweenElevations(Wkt, 2.0, 4.0)) as NTSGS.MultiLineString).NumGeometries);
            }
        }
Exemplo n.º 3
0
        public void TestSTAddMeasure()
        {
            const string Wkt = "LINESTRING(1 0, 2 0, 4 0)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt))
                .Insert();

                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STAddMeasure(1.0, 4.0))
                             .Single() as NTSGS.LineString;

                Assert.AreEqual(1.0, result.Coordinates[0].X, 1.0E-8);
                Assert.AreEqual(0.0, result.Coordinates[0].Y, 1.0E-8);
                Assert.AreEqual(1.0, result.Coordinates[0].M, 1.0E-8);

                Assert.AreEqual(2.0, result.Coordinates[1].X, 1.0E-8);
                Assert.AreEqual(0.0, result.Coordinates[1].Y, 1.0E-8);
                Assert.AreEqual(2.0, result.Coordinates[1].M, 1.0E-8);

                Assert.AreEqual(4.0, result.Coordinates[2].X, 1.0E-8);
                Assert.AreEqual(0.0, result.Coordinates[2].Y, 1.0E-8);
                Assert.AreEqual(4.0, result.Coordinates[2].M, 1.0E-8);

                Assert.IsNull(db.Select(() => LinearReferencing.STAddMeasure((NTSG)null, 0, 0)));

                Assert.IsNotNull(db.Select(() => LinearReferencing.STAddMeasure(Wkt, 0, 0)));
            }
        }
        public void TestSTGeogFromWKB()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                // Binary output of select ST_GeogFromText('POINT(127.0092 38.889588)');
                var wkbPoint = new byte[]
                {
                    0x01,
                    0x01, 0x00, 0x00, 0x20,
                    0xE6, 0x10, 0x00, 0x00,
                    0xE3, 0xC7, 0x98, 0xBB, 0x96, 0xC0, 0x5F, 0x40,
                    0x00, 0x75, 0x03, 0x05, 0xDE, 0x71, 0x43, 0x40
                };

                var geographyPoint = db.Select(() => GeometryInput.STGeomFromEWKB(wkbPoint));

                Assert.IsNotNull(geographyPoint);
                Assert.AreEqual(SRID4326, geographyPoint.SRID);
                Assert.AreEqual("Point", geographyPoint.GeometryType);
                Assert.AreEqual(127.0092, geographyPoint.Coordinates[0].X, 1.0E-4);
                Assert.AreEqual(38.889588, geographyPoint.Coordinates[0].Y, 1.0E-6);

                Assert.IsNull(db.Select(() => GeometryInput.STGeogFromWKB(null)));
            }
        }
Exemplo n.º 5
0
        public void TestSTLineSubstring()
        {
            const string Wkt = "LINESTRING(25 50, 100 125, 150 190)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeometryFromText(Wkt))
                .Insert();

                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STLineSubstring(0.333, 0.666))
                             .Single() as NTSGS.LineString;

                Assert.AreEqual(3, result.Coordinates.Length);

                Assert.AreEqual(69.28469348539744, result.GetCoordinateN(0).X, 1.0E-8);
                Assert.AreEqual(94.28469348539744, result.GetCoordinateN(0).Y, 1.0E-8);

                Assert.AreEqual(100.0, result.GetCoordinateN(1).X, 1.0E-8);
                Assert.AreEqual(125.0, result.GetCoordinateN(1).Y, 1.0E-8);

                Assert.AreEqual(111.70035626068274, result.GetCoordinateN(2).X, 1.0E-8);
                Assert.AreEqual(140.21046313888758, result.GetCoordinateN(2).Y, 1.0E-8);

                Assert.IsNull(db.Select(() => LinearReferencing.STLineSubstring((NTSG)null, 0, 0)));

                Assert.AreEqual(
                    3,
                    (db.Select(() => LinearReferencing.STLineSubstring(Wkt, 0.333, 0.666)) as NTSGS.LineString).Coordinates.Length);
            }
        }
Exemplo n.º 6
0
        public void TestSTForceCollection()
        {
            const string Wkt = "POINT(0 0)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt))
                .Insert();

                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STForceCollection())
                             .Single() as NTSGS.GeometryCollection;

                Assert.AreEqual(1, result.NumGeometries);
                Assert.IsInstanceOf <NTSGS.Point>(result.Geometries[0]);
                Assert.AreEqual(0, result.Geometries[0].Coordinates[0].X);
                Assert.AreEqual(0, result.Geometries[0].Coordinates[0].Y);

                Assert.IsNull(db.Select(() => GeometryEditors.STForceCollection((NTSG)null)));

                Assert.AreEqual(
                    "GEOMETRYCOLLECTION(POLYGON((0 0 1,0 5 1,5 0 1,0 0 1),(1 1 1,3 1 1,1 3 1,1 1 1)))",
                    db.Select(() => GeometryEditors.STForceCollection("POLYGON((0 0 1,0 5 1,5 0 1,0 0 1),(1 1 1,3 1 1,1 3 1,1 1 1))").STAsEWKT()));
            }
        }
Exemplo n.º 7
0
        public void TestSTReverse()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryConstructors.STMakeLine(
                           GeometryConstructors.STMakePoint(1, 2),
                           GeometryConstructors.STMakePoint(1, 10)))
                .Insert();

                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STReverse().AsText())
                             .Single();

                Assert.AreEqual("LINESTRING (1 10, 1 2)", result);

                Assert.IsNull(db.Select(() => GeometryEditors.STReverse((NTSG)null)));

                Assert.AreEqual(
                    "LINESTRING(1 10,1 2)",
                    db.Select(() => GeometryEditors.STReverse("LINESTRING(1 2,1 10)").STAsText()));
            }
        }
Exemplo n.º 8
0
        public void TestSTDimension()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string wkt1 = "GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0))";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt1))
                .Insert();

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

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

                var dimension2 = db.TestGeometries
                                 .Where(g => g.Id == 2)
                                 .Select(g => g.Geometry.STDimension())
                                 .Single();
                Assert.AreEqual(0, dimension2);

                Assert.IsNull(db.Select(() => GeometryAccessors.STDimension((NTSG)null)));
                Assert.AreEqual(1, db.Select(() => GeometryAccessors.STDimension("GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0))")));
            }
        }
Exemplo n.º 9
0
        public void TestSTEnvelope()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt = "LINESTRING(0 0, 1 3)";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt))
                .Insert();

                var envelope = db.TestGeometries
                               .Where(g => g.Id == 1)
                               .Select(g => g.Geometry.STEnvelope().STAsText())
                               .Single();
                Assert.AreEqual("POLYGON((0 0,0 3,1 3,1 0,0 0))", envelope);

                // TODO: need explicit cast text to geometry
                if (this.CurrentVersion >= new Version("3.0.0"))
                {
                    Assert.AreEqual(
                        "POLYGON((0 0,0 3,1 3,1 0,0 0))",
                        db.Select(() => GeometryAccessors.STEnvelope(Wkt).STAsText()));

                    Assert.IsNull(db.Select(() => GeometryAccessors.STEnvelope((NTSG)null)));
                }
            }
        }
        public void TestSTAsSVG()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var geometry1 = db.Select(() => GeometryInput.STGeomFromText("POLYGON((0 0,0 1,1 1,1 0,0 0))"));

                var svg1 = db.Select(() => GeometryOutput.STAsSVG(geometry1));
                Assert.AreEqual("M 0 0 L 0 -1 1 -1 1 0 Z", svg1);

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

                // geography
                db.TestGeographies
                .Value(g => g.Id, 1)
                .Value(g => g.Geography, () => GeometryInput.STGeographyFromText("POINT(30 60)"))
                .Insert();

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

                Assert.AreEqual(
                    "cx=\"30\" cy=\"-60\"",
                    svg2);
            }
        }
Exemplo n.º 11
0
        public void TestSTZmflag()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "LINESTRING(1 2, 3 4)";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt1)).Insert();

                const string Wkt2 = "LINESTRINGM(1 2 3, 3 4 3)";
                db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt2)).Insert();

                const string Wkt3 = "CIRCULARSTRING(1 2 3, 3 4 3, 5 6 3)";
                db.TestGeometries.Value(g => g.Id, 3).Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt3)).Insert();

                const string Wkt4 = "POINT(1 2 3 4)";
                db.TestGeometries.Value(g => g.Id, 4).Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt4)).Insert();
                db.TestGeometries.Value(g => g.Id, 5).Value(g => g.Geometry, () => null).Insert();

                Assert.AreEqual(0, db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STZmflag()).Single());
                Assert.AreEqual(1, db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STZmflag()).Single());
                Assert.AreEqual(2, db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STZmflag()).Single());
                Assert.AreEqual(3, db.TestGeometries.Where(g => g.Id == 4).Select(g => g.Geometry.STZmflag()).Single());
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 5).Select(g => g.Geometry.STZmflag()).Single());

                Assert.AreEqual(0, db.Select(() => GeometryAccessors.STZmflag(Wkt1)));
                Assert.AreEqual(1, db.Select(() => GeometryAccessors.STZmflag(Wkt2)));
                Assert.AreEqual(2, db.Select(() => GeometryAccessors.STZmflag(Wkt3)));
                Assert.AreEqual(3, db.Select(() => GeometryAccessors.STZmflag(Wkt4)));
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 5).Select(g => g.Geometry.STZmflag()).Single());
            }
        }
        public void TestSTAsKML()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var g1 = db.Select(() => GeometryInput.STGeomFromText("POLYGON((0 0,0 1,1 1,1 0,0 0))", 4326));

                var kml1 = db.Select(() => GeometryOutput.STAsKML(g1));
                Assert.AreEqual("<Polygon><outerBoundaryIs><LinearRing><coordinates>0,0 0,1 1,1 1,0 0,0</coordinates></LinearRing></outerBoundaryIs></Polygon>", kml1);

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

                // geography
                db.TestGeographies
                .Value(g => g.Id, 1)
                .Value(g => g.Geography, () => GeometryInput.STGeographyFromText("POINT(30 60)"))
                .Insert();

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

                Assert.AreEqual(
                    "<Point><coordinates>30,60</coordinates></Point>",
                    kml2);
            }
        }
        public void TestSTAsEWKT()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                Assert.AreEqual(
                    "SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0 0))",
                    db.Select(() => GeometryOutput.STAsEWKT("0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000")));

                Assert.AreEqual(
                    "CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)",
                    db.Select(() => GeometryOutput.STAsEWKT("0108000080030000000000000060E30A4100000000785C0241000000000000F03F0000000018E20A4100000000485F024100000000000000400000000018E20A4100000000305C02410000000000000840")));

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

                // geography
                db.TestGeographies
                .Value(g => g.Id, 1)
                .Value(g => g.Geography, () => GeometryInput.STGeographyFromText("POINT(30 60)"))
                .Insert();

                Assert.AreEqual(
                    "SRID=4326;POINT(30 60)",
                    db.TestGeographies
                    .Where(g => g.Id == 1)
                    .Select(g => g.Geography.STAsEWKT())
                    .Single());
            }
        }
        public void TestSTAsGML()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var g1   = db.Select(() => GeometryInput.STGeomFromText("POLYGON((0 0,0 1,1 1,1 0,0 0))", 4326));
                var gml1 = db.Select(() => GeometryOutput.STAsGML(g1));
                Assert.AreEqual("<gml:Polygon srsName=\"EPSG:4326\"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0,0 0,1 1,1 1,0 0,0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>", gml1);

                // TODO:  Version 3
                ////var g2 = db.Select(() => GeometryInput.STGeomFromText("POINT(5.234234233242 6.34534534534)", 4326));
                ////var gml2 = db.Select(() => GeometryOutput.STAsGML(3, g2, 5, 16 | 1));
                ////Assert.AreEqual("<gml:Point srsName=\"urn:ogc:def:crs:EPSG::4326\"><gml:pos>6.34535 5.23423</gml:pos></gml:Point>", gml2);

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

                // geography
                db.TestGeographies
                .Value(g => g.Id, 1)
                .Value(g => g.Geography, () => GeometryInput.STGeographyFromText("POINT(30 60)"))
                .Insert();

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

                Assert.AreEqual(
                    "<gml:Point srsName=\"EPSG:4326\"><gml:coordinates>30,60</gml:coordinates></gml:Point>",
                    gml2);
            }
        }
        public void TestSTCPAWithin()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "LINESTRING ZM (0 0 0 1432623600,10 0 5 1432627200)";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1))
                .Insert();

                const string Wkt2 = "LINESTRING ZM (0 2 10 1432623600,12 1 2 1432627200)";
                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.IsTrue(db.TestGeometries.Where(g => g.Id == 1)
                              .Select(g => g.Geometry.STCPAWithin(db.TestGeometries.Where(g2 => g2.Id == 2).Single().Geometry, 2))
                              .Single());

                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STCPAWithin(null, 2)).Single());

                Assert.IsTrue(db.Select(() => TrajectoryFunctions.STCPAWithin(Wkt1, Wkt2, 2)));
                Assert.IsNull(db.Select(() => TrajectoryFunctions.STCPAWithin((string)null, (string)null, 2)));
            }
        }
Exemplo n.º 16
0
        public void TestSTGeometryN()
        {
            const string Ewkt =
                @"TIN (((
                            0 0 0,
                            0 0 1,
                            0 1 0,
                            0 0 0
                        )), ((
                            0 0 0,
                            0 1 0,
                            1 1 0,
                            0 0 0
                        )))";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                Assert.AreEqual(
                    "TRIANGLE((0 0 0,0 1 0,1 1 0,0 0 0))",
                    db.Select(() => GeometryInput.STGeomFromEWKT(Ewkt)
                              .STGeometryN(2)
                              .STAsEWKT()));

                Assert.AreEqual(
                    "TRIANGLE((0 0 0,0 1 0,1 1 0,0 0 0))",
                    db.Select(() => GeometryAccessors.STGeometryN(Ewkt, 2)
                              .STAsEWKT()));

                Assert.IsNull(db.Select(() => GeometryAccessors.STGeometryN((NTSG)null, 1)));
            }
        }
Exemplo n.º 17
0
        public void TestSTForce2D()
        {
            const string Wkt = "LINESTRING(25 50 1, 100 125 1, 150 190 1)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt))
                .Insert();

                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STForce2D())
                             .Single() as NTSGS.LineString;

                Assert.AreEqual(2, result.CoordinateSequence.Dimension);
                Assert.AreEqual(25, result.GetCoordinateN(0).X);
                Assert.AreEqual(50, result.GetCoordinateN(0).Y);
                Assert.AreEqual(100, result.GetCoordinateN(1).X);
                Assert.AreEqual(125, result.GetCoordinateN(1).Y);
                Assert.AreEqual(150, result.GetCoordinateN(2).X);
                Assert.AreEqual(190, result.GetCoordinateN(2).Y);

                Assert.IsNull(db.Select(() => GeometryEditors.STForce2D((NTSG)null)));

                Assert.AreEqual(
                    2,
                    ((NTSGS.LineString)db.Select(() => GeometryEditors.STForce2D(Wkt))).CoordinateSequence.Dimension);
            }
        }
Exemplo n.º 18
0
        public void TestSTIsClosed()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "LINESTRING(0 0, 1 1)";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();

                const string Wkt2 = "LINESTRING(0 0, 0 1, 1 1, 0 0)";
                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.IsFalse(db.TestGeometries
                               .Where(g => g.Id == 1)
                               .Select(g => g.Geometry.STIsClosed())
                               .Single());
                Assert.IsTrue(db.TestGeometries
                              .Where(g => g.Id == 2)
                              .Select(g => g.Geometry.STIsClosed())
                              .Single());

                Assert.IsFalse(db.Select(() => GeometryAccessors.STIsClosed(Wkt1)));
                Assert.IsTrue(db.Select(() => GeometryAccessors.STIsClosed(Wkt2)));

                Assert.IsNull(db.TestGeometries
                              .Where(g => g.Id == 3)
                              .Select(g => g.Geometry.STIsClosed())
                              .Single());
            }
        }
Exemplo n.º 19
0
        public void TestSTForceCurve()
        {
            const string Wkt      = "POLYGON((0 0 1,5 0 1,0 5 1,0 0 1),(1 1 1,1 3 1,3 1 1,1 1 1))";
            const string Expected = "CURVEPOLYGON Z ((0 0 1,5 0 1,0 5 1,0 0 1),(1 1 1,1 3 1,3 1 1,1 1 1))";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt))
                .Insert();

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

                Assert.AreEqual(Expected, curvedGeomStr);

                Assert.IsNull(db.Select(() => GeometryEditors.STForceCurve((NTSG)null)));

                Assert.AreEqual(
                    Expected,
                    db.Select(() => GeometryEditors.STForceCurve(Wkt).STAsText()));
            }
        }
Exemplo n.º 20
0
        public void TestSTIsEmpty()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "GEOMETRYCOLLECTION EMPTY";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();

                const string Wkt2 = "POLYGON((1 2, 3 4, 5 6, 1 2))";
                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.IsTrue(db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STIsEmpty()).Single());
                Assert.IsFalse(db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STIsEmpty()).Single());
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STIsEmpty()).Single());

                // TODO: Need some research for reason of error:
                // function st_isempty(unknown) is not unique. Could not choose a best candidate function. You might need to add explicit type casts.
                var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
                if (version > new Version("3.0.0"))
                {
                    Assert.IsNull(db.Select(() => GeometryAccessors.STIsEmpty((NTSG)null)));
                    Assert.IsTrue(db.Select(() => GeometryAccessors.STIsEmpty("CIRCULARSTRING EMPTY")));
                    Assert.IsFalse(db.Select(() => GeometryAccessors.STIsEmpty("POINT(0 0)")));
                }
            }
        }
Exemplo n.º 21
0
        public void TestSTAsBinary()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string wkt1 = "POINT(2.0 4.0)";
                db.TestGeometries.Value(g => g.Id, 1).Value(p => p.Geometry, () => GeometryInput.STGeomFromText(wkt1)).Insert();

                var wkb = db.TestGeometries.Select(g => g.Geometry.STAsBinary()).Single();

                Assert.AreEqual(21, wkb.Length);
                Assert.AreEqual(1, wkb[0]); // TODO: depends on server machine endianness
                Assert.AreEqual(1, BitConverter.ToUInt32(wkb, 1));
                Assert.AreEqual(2, BitConverter.ToDouble(wkb, 5));
                Assert.AreEqual(4, BitConverter.ToDouble(wkb, 13));

                const string wkt2 = "POLYGON((0 0,0 1,1 1,1 0,0 0))";

                var wkbLittleEndian = db.Select(() => GeometryInput.STGeometryFromText(wkt2).STAsBinary(EndiannessEncoding.LittleEndian));
                Assert.AreEqual(1, wkbLittleEndian[0]);
                Assert.AreEqual(3, wkbLittleEndian[1]);

                var wkbBigEndian = db.Select(() => GeometryInput.STGeometryFromText(wkt2).STAsBinary(EndiannessEncoding.BigEndian));
                Assert.AreEqual(0, wkbBigEndian[0]);
                Assert.AreEqual(3, wkbBigEndian[4]);

                Assert.IsNull(db.Select(() => GeometryOutput.STAsBinary(null, EndiannessEncoding.BigEndian)));
            }
        }
Exemplo n.º 22
0
        public void TestSTMemSize()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText("POINT(0 0)"))
                .Insert();
                db.TestGeometries
                .Value(g => g.Id, 2)
                .Value(g => g.Geometry, () => null)
                .Insert();

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

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

                // TODO: need explicit cast text to geometry
                if (this.CurrentVersion >= new Version("3.0.0"))
                {
                    Assert.AreEqual(32, db.Select(() => GeometryAccessors.STMemSize("POINT(0 0)")));
                    Assert.IsNull(db.Select(() => GeometryAccessors.STMemSize((NTSG)null)));
                }
            }
        }
Exemplo n.º 23
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)));
            }
        }
Exemplo n.º 24
0
        public void TestSTNPoints()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "POINT(77.29 29.07)";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();

                const string Wkt2 = "LINESTRING(77.29 29.07 1,77.42 29.26 0,77.27 29.31 -1,77.29 29.07 3)";
                db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)).Insert();

                const string Wkt3 = "LINESTRING 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();

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

                var nPoints2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STNPoints()).Single();
                Assert.AreEqual(4, nPoints2);

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

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

                Assert.IsNull(db.Select(() => GeometryAccessors.STNPoints((NTSG)null)));
                Assert.AreEqual(1, db.Select(() => GeometryAccessors.STNPoints(Wkt1)));
                Assert.AreEqual(4, db.Select(() => GeometryAccessors.STNPoints(Wkt2)));
                Assert.AreEqual(0, db.Select(() => GeometryAccessors.STNPoints(Wkt3)));
            }
        }
Exemplo n.º 25
0
        public void TestSTLineInterpolatePoint()
        {
            const string Wkt = "LINESTRING(25 50, 100 125, 150 190)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt))
                .Insert();

                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STLineInterpolatePoint(0.20))
                             .Single() as NTSGS.Point;

                Assert.AreEqual(51.5974135047432, result.X, 1.0E-8);
                Assert.AreEqual(76.5974135047432, result.Y, 1.0E-8);

                Assert.IsNull(db.Select(() => LinearReferencing.STLineInterpolatePoint((NTSG)null, 0.5)));
                Assert.IsNull(db.Select(() => LinearReferencing.STLineInterpolatePoint((string)null, 0.5)));

                var result2 = db.Select(() => LinearReferencing.STLineInterpolatePoint(Wkt, 0.20)) as NTSGS.Point;
                Assert.AreEqual(51.5974135047432, result2.X, 1.0E-8);
                Assert.AreEqual(76.5974135047432, result2.Y, 1.0E-8);
            }
        }
Exemplo n.º 26
0
        public void TestSTNRings()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt = "POLYGON((1 2, 3 4, 5 6, 1 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, () => null)
                .Insert();

                Assert.AreEqual(1, db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STNRings()).Single());
                Assert.AreEqual(0, db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STNumInteriorRings()).Single());
                Assert.AreEqual(0, db.Select(() => GeometryAccessors.STNumInteriorRings(Wkt)));

                // STNumInteriorRing is synonym to STNumInteriorRings. See http://postgis.net/docs/manual-1.5/ST_NumInteriorRing.html
                Assert.AreEqual(0, db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STNumInteriorRing()).Single());
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STNRings()).Single());

                Assert.IsNull(db.Select(() => GeometryAccessors.STNRings((NTSG)null)));
                Assert.AreEqual(1, db.Select(() => GeometryAccessors.STNRings(Wkt)));
                Assert.AreEqual(0, db.Select(() => GeometryAccessors.STNumInteriorRing(Wkt)));
            }
        }
Exemplo n.º 27
0
        public void TestSTInterpolatePoint()
        {
            const string LineWkt  = "LINESTRING M (0 0 0, 10 0 20)";
            const string PointWkt = "POINT(5 5)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeometryFromText(LineWkt))
                .Insert();

                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STInterpolatePoint(GeometryInput.STGeometryFromText(PointWkt)))
                             .Single();

                Assert.AreEqual(10.0, result.Value, 1.0E-8);

                Assert.IsNull(db.Select(() => LinearReferencing.STInterpolatePoint((NTSG)null, (NTSG)null)));

                Assert.AreEqual(
                    10.0,
                    db.Select(() => LinearReferencing.STInterpolatePoint(LineWkt, PointWkt)));
            }
        }
Exemplo n.º 28
0
        public void TestSTStartPoint()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "LINESTRING(0 1, 0 2)";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();

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

                Assert.AreEqual(
                    "POINT(0 1)",
                    db.TestGeometries
                    .Where(g => g.Id == 1)
                    .Select(g => g.Geometry.STStartPoint().STAsText())
                    .Single());

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

                Assert.AreEqual("POINT(0 1)", db.Select(() => GeometryAccessors.STStartPoint(Wkt1).STAsText()));
                Assert.IsNull(db.Select(() => GeometryAccessors.STStartPoint(Wkt2)));
                Assert.IsNull(db.Select(() => GeometryAccessors.STStartPoint((NTSG)null)));
            }
        }
Exemplo n.º 29
0
        public void TestST3DLineInterpolatePoint()
        {
            const string Wkt = "LINESTRING(25 50 70, 100 125 90, 150 190 200)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
                if (version >= new Version("3.0.0"))
                {
                    db.TestGeometries
                    .Value(g => g.Id, 1)
                    .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt))
                    .Insert();

                    var result = db.TestGeometries
                                 .Where(g => g.Id == 1)
                                 .Select(g => g.Geometry.ST3DLineInterpolatePoint(0.20))
                                 .Single() as NTSGS.Point;

                    Assert.AreEqual(59.0675892910822, result.X, 1.0E-8);
                    Assert.AreEqual(84.0675892910822, result.Y, 1.0E-8);
                    Assert.AreEqual(79.0846904776219, result.Z, 1.0E-8);

                    Assert.IsNull(db.Select(() => LinearReferencing.ST3DLineInterpolatePoint((NTSG)null, 0.5)));

                    var result2 = db.Select(() => LinearReferencing.ST3DLineInterpolatePoint(Wkt, 0.20)) as NTSGS.Point;
                    Assert.AreEqual(59.0675892910822, result2.X, 1.0E-8);
                    Assert.AreEqual(84.0675892910822, result2.Y, 1.0E-8);
                    Assert.AreEqual(79.0846904776219, result2.Z, 1.0E-8);
                }
            }
        }
        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)));
            }
        }