public void TestSTDistanceSpheroid()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Spheroid = "SPHEROID[\"WGS 84\",6378137,298.257223563]";
                var          point    = db.Select(() => GeometryInput.STGeomFromText("POINT(-118 38)", SRID4326));
                var          geom     = db.Select(() => GeometryInput.STGeomFromText("LINESTRING(-118.584 38.374,-118.583 38.5)", SRID4326));

                var dist_meters_spheroid = db.Select(() => geom.STCentroid().STDistanceSpheroid(point, Spheroid));
                var dist_meters_sphere   = db.Select(() => geom.STCentroid().STDistanceSphere(point));
                var dist_utm11_meters    = db.Select(() => geom.STCentroid().STTransform(32611).STDistance(point.STTransform(32611)));

                Assert.AreEqual(70454.92, dist_meters_spheroid.Value, 0.01);
                Assert.AreEqual(70424.71, dist_meters_sphere.Value, 0.01);
                Assert.AreEqual(70438.00, dist_utm11_meters.Value, 0.01);

                Assert.AreEqual(
                    4434.73734584354,
                    db.Select(() => MeasurementFunctions.STDistanceSpheroid(
                                  "SRID=4326;POINT(120.08 30.96)",
                                  "SRID=4326;POINT(120.08 30.92)",
                                  Spheroid)).Value,
                    1.0E-8);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STDistanceSpheroid((NTSG)null, (NTSG)null, Spheroid)));
            }
        }
Ejemplo n.º 2
0
        public void TestSTGeomFromText()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string wkt1 = "POINT(100 250)";
                db.TestGeometries.Value(g => g.Id, 1).Value(p => p.Geometry, () => GeometryInput.STGeomFromText(wkt1)).Insert();

                var srid1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STSrId()).Single();
                Assert.AreEqual(0, srid1);

                var ewkt1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STAsEWKT()).Single();
                Assert.AreEqual("POINT(100 250)", ewkt1);

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

                var srid2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STSrId()).Single();
                Assert.AreEqual(SRID3857, srid2);

                var ewkt2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STAsEWKT()).Single();
                Assert.AreEqual("SRID=3857;POINT(100 250)", ewkt2);

                db.TestGeometries.Value(g => g.Id, 3).Value(p => p.Geometry, () => null).Insert();
                var srid3 = db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STSrId()).Single();
                Assert.IsNull(srid3);
            }
        }
Ejemplo n.º 3
0
        public void TestSTUnion()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "POINT(1 2)";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1))
                .Insert();

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

                var geometry2 = db.TestGeometries.Single(g => g.Id == 2).Geometry;
                var union     = db.TestGeometries
                                .Where(g => g.Id == 1)
                                .Select(g => g.Geometry.STUnion(geometry2).STAsText())
                                .Single();

                Assert.AreEqual("MULTIPOINT(1 2,-2 3)", union);
            }
        }
Ejemplo n.º 4
0
        public void TestSTMakeLine()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(p => p.Geometry, () => GeometryConstructors.STMakeLine(
                           GeometryInput.STGeomFromText("POINT(1 2)"),
                           GeometryInput.STGeomFromText("POINT(3 4)")))
                .Insert();

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

                var line1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STAsText()).Single();
                Assert.AreEqual("LINESTRING(1 2,3 4)", line1);

                var line2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STAsText()).Single();
                Assert.AreEqual("LINESTRING(0 0,1 1,2 2,3 3)", line2);
            }
        }
Ejemplo n.º 5
0
        public void TestSTAsGeoJSON()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string wkt1 = "POINT(2.48 4.75)";
                db.TestGeometries.Value(g => g.Id, 1).Value(p => p.Geometry, () => GeometryInput.STGeomFromText(wkt1)).Insert();

                var geojson1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STAsGeoJSON()).Single();
                Assert.AreEqual("{\"type\":\"Point\",\"coordinates\":[2.48,4.75]}", geojson1);

                var geojson1crs = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STAsGeoJSON(1, 4)).Single();
                Assert.AreEqual("{\"type\":\"Point\",\"coordinates\":[2.5,4.8]}", geojson1crs);


                const string wkt2 = "LINESTRING(1 2 3, 4 5 6)";
                db.TestGeometries.Value(g => g.Id, 2).Value(p => p.Geometry, () => GeometryInput.STGeomFromText(wkt2)).Insert();

                var geojson2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STAsGeoJSON()).Single();
                Assert.AreEqual("{\"type\":\"LineString\",\"coordinates\":[[1,2,3],[4,5,6]]}", geojson2);


                const string ewkt3 = "SRID=3857;POINT(2.48 4.75)";
                db.TestGeometries.Value(g => g.Id, 3).Value(p => p.Geometry, () => GeometryInput.STGeomFromEWKT(ewkt3)).Insert();

                var geojson3 = db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STAsGeoJSON()).Single();
                Assert.AreEqual("{\"type\":\"Point\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:3857\"}},\"coordinates\":[2.48,4.75]}", geojson3);

                var geojson3crs = db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STAsGeoJSON(1, 4)).Single();
                Assert.AreEqual("{\"type\":\"Point\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"urn:ogc:def:crs:EPSG::3857\"}},\"coordinates\":[2.5,4.8]}", geojson3crs);

                Assert.IsNull(db.Select(() => GeometryOutput.STAsGeoJSON(null)));
            }
        }
        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)));
            }
        }
Ejemplo n.º 7
0
        public void TestSTSwapOrdinates()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                Assert.AreEqual(
                    "POINT(2 1)",
                    db.Select(() => GeometryInput
                              .STGeomFromText("POINT(1 2)")
                              .STSwapOrdinates("xy")
                              .STAsText()));

                Assert.AreEqual(
                    "POINT(2 1)",
                    db.Select(() => GeometryEditors
                              .STSwapOrdinates("POINT(1 2)", "xy")
                              .STAsText()));

                Assert.AreEqual(
                    "POINT ZM (0 0 0 4)",
                    db.Select(() => GeometryInput
                              .STGeomFromText("POINT ZM (0 0 0 2)")
                              .STSwapOrdinates("xm")
                              .STScale(2, 1)
                              .STSwapOrdinates("xm")
                              .STAsText()));

                Assert.IsNull(db.Select(() => GeometryEditors.STSwapOrdinates((NTSGS.Geometry)null, null)));
                Assert.IsNull(db.Select(() => GeometryEditors.STSwapOrdinates((NTSGS.Geometry)null, String.Empty)));
                Assert.IsNull(db.Select(() => GeometryEditors.STSwapOrdinates((string)null, null)));
            }
        }
Ejemplo 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))")));
            }
        }
Ejemplo 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);
            }
        }
        public void TestSTMakePolygon()
        {
            const string Wkt1 = "LINESTRING(75.15 29.53 1,77 29 1,77.6 29.5 1, 75.15 29.53 1)";
            const string Wkt2 = "LINESTRINGM(75.15 29.53 1,77 29 1,77.6 29.5 2, 75.15 29.53 2)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryConstructors.STMakePolygon(GeometryInput.STGeomFromText(Wkt1)))
                .Insert();

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

                Assert.AreEqual("POLYGON((75.15 29.53 1,77 29 1,77.6 29.5 1,75.15 29.53 1))",
                                db.TestGeometries
                                .Where(g => g.Id == 1)
                                .Select(g => g.Geometry.STAsEWKT())
                                .Single());

                Assert.AreEqual("POLYGONM((75.15 29.53 1,77 29 1,77.6 29.5 2,75.15 29.53 2))",
                                db.TestGeometries
                                .Where(g => g.Id == 2)
                                .Select(g => g.Geometry.STAsEWKT())
                                .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 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 TestSTLengthSpheroid()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Spheroid = "SPHEROID[\"GRS_1980\",6378137,298.257222101]";
                const string Wkt      = "MULTILINESTRING((-118.584 38.374,-118.583 38.5), (-71.05957 42.3589, -71.061 43))";
                var          geom1    = db.Select(() => GeometryInput.STGeomFromText(Wkt));

                var length1 = db.Select(() => MeasurementFunctions.STLengthSpheroid(geom1, Spheroid));
                Assert.AreEqual(85204.5207711811, length1.Value, 1.0E-9);

                var length2 = db.Select(() => MeasurementFunctions.STLengthSpheroid(geom1.STGeometryN(1), Spheroid));
                Assert.AreEqual(13986.8725282447, length2.Value, 1.0E-9);

                var length3 = db.Select(() => MeasurementFunctions.STLengthSpheroid(geom1.STGeometryN(2), Spheroid));
                Assert.AreEqual(71217.6482429363, length3.Value, 1.0E-9);

                Assert.AreEqual(
                    85204.5207711811,
                    db.Select(() => MeasurementFunctions.STLengthSpheroid(Wkt, Spheroid)).Value,
                    1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STLengthSpheroid((NTSG)null, Spheroid)));
            }
        }
Ejemplo n.º 15
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)));
            }
        }
Ejemplo n.º 16
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)")));
            }
        }
Ejemplo n.º 17
0
        public void TestSTSummary()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText("LINESTRING(0 0, 1 1)"))
                .Insert();

                Assert.AreEqual("LineString[] with 2 points", db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STSummary()).Single());

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

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

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

                Assert.AreEqual(
                    "Point[GS]",
                    db.TestGeographies
                    .Where(g => g.Id == 1)
                    .Select(g => g.Geography.STSummary())
                    .Single());
            }
        }
Ejemplo n.º 18
0
        public void TestSTIsPolygonCW()
        {
            const string Wkt = "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))";

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

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

                Assert.IsTrue(result1.HasValue);
                Assert.IsTrue(result1);

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

                Assert.IsTrue(result2.HasValue);
                Assert.IsTrue(result2);

                Assert.IsNull(db.Select(() => GeometryAccessors.STIsPolygonCW((NTSG)null)));
            }
        }
Ejemplo n.º 19
0
        public void TestSTCurveToLine()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt = "CIRCULARSTRING(0 0,100 -100,200 0)";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt))
                .Insert();

                var result1 = db.TestGeometries
                              .Where(g => g.Id == 1)
                              .Select(g => g.Geometry.STCurveToLine(20, 1, 1))
                              .Single() as NTSGS.LineString;

                Assert.AreEqual(0, result1.Coordinates[0].X);
                Assert.AreEqual(0, result1.Coordinates[0].Y);
                Assert.AreEqual(50, result1.Coordinates[1].X, 1.0E-9);
                Assert.AreEqual(-86.6025403784438, result1.Coordinates[1].Y, 1.0E-9);
                Assert.AreEqual(150, result1.Coordinates[2].X, 1.0E-9);
                Assert.AreEqual(-86.6025403784439, result1.Coordinates[2].Y, 1.0E-9);
                Assert.AreEqual(200, result1.Coordinates[3].X, 1.0E-9);
                Assert.AreEqual(0, result1.Coordinates[3].Y, 1.0E-9);

                Assert.IsNull(db.Select(() => GeometryEditors.STCurveToLine(null, 20, 1, 1)));
            }
        }
Ejemplo n.º 20
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());
            }
        }
Ejemplo n.º 21
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);
            }
        }
Ejemplo n.º 22
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)")));
                }
            }
        }
Ejemplo n.º 23
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)));
            }
        }
Ejemplo n.º 24
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)));
                }
            }
        }
Ejemplo n.º 25
0
        public void TestGeometryFromWKB()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string wkt1 = "POINT(2 5)";
                const string wkt2 = "LINESTRING(2 5,2 6)";
                var          wkb1 = db.Select(() => GeometryInput.STGeomFromText(wkt1).STAsBinary());
                var          wkb2 = db.Select(() => GeometryInput.STGeomFromText(wkt2).STAsBinary());

                Assert.AreEqual(wkt1, db.Select(() => GeometryInput.STWKBToSQL(wkb1).STAsText()));
                Assert.AreEqual(wkt1, db.Select(() => GeometryInput.STGeomFromWKB(wkb1).STAsText()));
                Assert.AreEqual(wkt1, db.Select(() => GeometryInput.STPointFromWKB(wkb1).STAsText()));

                Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STGeomFromWKB(wkb1, SRID3857).STSrId()));
                Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STPointFromWKB(wkb1, SRID3857).STSrId()));

                Assert.AreEqual(wkt2, db.Select(() => GeometryInput.STGeomFromWKB(wkb2).STAsText()));
                Assert.AreEqual(wkt2, db.Select(() => GeometryInput.STLineFromWKB(wkb2).STAsText()));
                Assert.AreEqual(wkt2, db.Select(() => GeometryInput.STLinestringFromWKB(wkb2).STAsText()));

                Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STGeomFromWKB(wkb2, SRID3857).STSrId()));
                Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STLineFromWKB(wkb2, SRID3857).STSrId()));
                Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STLinestringFromWKB(wkb2, SRID3857).STSrId()));

                Assert.IsNull(db.Select(() => GeometryInput.STGeomFromEWKB(null)));
            }
        }
Ejemplo n.º 26
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)));
            }
        }
        public void TestSTTransScale()
        {
            var expected = new double[][]
            {
                new[] { 1.5, 6, 3 },
                new[] { 1.5, 4, 1 },
            };

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt = "LINESTRING(1 2 3, 1 1 1)";
                db.TestGeometries.Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt))
                .Insert();

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

                CheckLineEquals(expected, result, 1.0E-8);

                var result2 = db
                              .Select(() => AffineTransformations.STTransScale(Wkt, 0.5, 1, 1, 2)) as NTSGS.LineString;

                CheckLineEquals(expected, result2, 1.0E-8);
            }
        }
Ejemplo n.º 28
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)));
            }
        }
Ejemplo n.º 29
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)));
            }
        }
        public void TestSTDistanceSphere()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var point = db.Select(() => GeometryInput.STGeomFromText("POINT(-118 38)", SRID4326));
                var geom  = db.Select(() => GeometryInput.STGeomFromText("LINESTRING(-118.584 38.374,-118.583 38.5)", SRID4326));

                var dist_meters                = db.Select(() => geom.STCentroid().STDistanceSphere(point));
                var dist_utm11_meters          = db.Select(() => geom.STCentroid().STTransform(32611).STDistance(point.STTransform(32611)));
                var dist_degrees               = db.Select(() => geom.STCentroid().STDistance(point));
                var min_dist_line_point_meters = db.Select(() => geom.STTransform(32611).STDistance(point.STTransform(32611)));

                Assert.AreEqual(70424.71, dist_meters.Value, 0.01);
                Assert.AreEqual(70438.00, dist_utm11_meters.Value, 0.01);
                Assert.AreEqual(0.72900, dist_degrees.Value, 0.00001);
                Assert.AreEqual(65871.18, min_dist_line_point_meters.Value, 0.01);

                Assert.AreEqual(
                    111195.07973463,
                    db.Select(() => MeasurementFunctions.STDistanceSphere(
                                  "SRID=4326;POINT(0 0)",
                                  "SRID=4326;POINT(0 1)")).Value,
                    1.0E-6);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STDistanceSphere((NTSG)null, (NTSG)null)));
            }
        }