Esempio n. 1
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()));
            }
        }
Esempio 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);
            }
        }
Esempio 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)));
            }
        }
Esempio n. 4
0
        public void TestSTIntersection()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "POINT (30 60)";
                const string Wkt2 = "LINESTRING (0 0,30 60)";

                db.TestGeographies
                .Value(g => g.Id, 1)
                .Value(g => g.Geography, () => GeometryInput.STGeographyFromText(Wkt1))
                .Insert();

                db.TestGeographies
                .Value(g => g.Id, 2)
                .Value(g => g.Geography, () => GeometryInput.STGeographyFromText(Wkt2))
                .Insert();

                var intersection1 = db.TestGeographies
                                    .Where(g => g.Id == 1)
                                    .Select(g => g.Geography.STIntersection(
                                                db.TestGeographies.Where(g1 => g1.Id == 2).Single().Geography))
                                    .First() as NTSGS.Point;

                Assert.IsNotNull(intersection1);
                Assert.AreEqual(1, intersection1.Coordinates.Length);
                Assert.AreEqual("Point", intersection1.GeometryType);
            }
        }
Esempio 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);
            }
        }
        public void TestSTRotate()
        {
            var expected = new double[][]
            {
                new[] { -50.0, -160.0 },
                new[] { -50.0, -50.0 },
                new[] { -100.0, -50.0 }
            };

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt = "LINESTRING (50 160, 50 50, 100 50)";
                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.STRotate(Math.PI))
                             .Single() as NTSGS.LineString;

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

                var result2 = db
                              .Select(() => AffineTransformations.STRotate(Wkt, Math.PI)) as NTSGS.LineString;

                CheckLineEquals(expected, result2, 1.0E-8);
            }
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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)));
            }
        }
Esempio n. 9
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)));
            }
        }
Esempio n. 10
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. 11
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);
            }
        }
Esempio n. 12
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)));
            }
        }
Esempio n. 13
0
        public void TestSTShiftLongitude()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Ewkt1 = "SRID=4326;POINT(-118.58 38.38 10)";
                const string Ewkt2 = "SRID=4326;POINT(241.42 38.38 10)";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Ewkt1))
                .Insert();
                db.TestGeometries
                .Value(g => g.Id, 2)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Ewkt2))
                .Insert();

                var result1 = db.TestGeometries
                              .Where(g => g.Id == 1)
                              .Select(g => g.Geometry.STShiftLongitude())
                              .Single() as NTSGS.Point;

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

                Assert.AreEqual(241.42, result1.X, 1.0E-2);
                Assert.AreEqual(38.38, result1.Y, 1.0E-2);

                Assert.AreEqual(-118.58, result2.X, 1.0E-2);
                Assert.AreEqual(38.38, result2.Y, 1.0E-2);
            }
        }
Esempio n. 14
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()));
            }
        }
        public void TestSTScaleFalseOrigin()
        {
            var expected = new double[][]
            {
                new[] { 1.00, 1.00 },
                new[] { 3.00, 3.00 },
            };

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt = "LINESTRING(1 1, 2 2)";
                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.STScale(GeometryInput.STGeomFromEWKT("POINT(2 2)"), GeometryInput.STGeomFromEWKT("POINT(1 1)")))
                             .Single() as NTSGS.LineString;

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

                var result2 = db
                              .Select(() => AffineTransformations.STScale(
                                          Wkt,
                                          GeometryInput.STGeomFromEWKT("POINT(2 2)"),
                                          GeometryInput.STGeomFromEWKT("POINT(1 1)"))) as NTSGS.LineString;

                CheckLineEquals(expected, result2, 1.0E-8);
            }
        }
        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)));
            }
        }
        public void TestSTAffine2D()
        {
            var expected = new double[][]
            {
                new[] { 0.0, 0.0, 3.0 },
                new[] { 0.0, 0.0, 3.0 },
            };

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt = "LINESTRING(1 2 3, 1 4 3)";
                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.STAffine(0, 0, 0, 0, 0, 0))
                             .Single() as NTSGS.LineString;

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

                var result2 = db
                              .Select(() => AffineTransformations.STAffine(Wkt, 0, 0, 0, 0, 0, 0)) as NTSGS.LineString;

                CheckLineEquals(expected, result2, 1.0E-8);
            }
        }
        public void TestSTPointFromGeoHash()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string GeoHash = "9qqj7nmxncgyy4d0dbxqz0";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STPointFromGeoHash(GeoHash)).Insert();
                db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STPointFromGeoHash(GeoHash, 4)).Insert();
                db.TestGeometries.Value(g => g.Id, 3).Value(g => g.Geometry, () => GeometryInput.STPointFromGeoHash(GeoHash, 10)).Insert();

                var point1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry).Single() as NTSGS.Point;
                Assert.AreEqual(-115.172816, point1.X, 1.0E-6);
                Assert.AreEqual(36.114646, point1.Y, 1.0E-6);

                var point2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry).Single() as NTSGS.Point;
                Assert.AreEqual(-115.13671875, point2.X, 1.0E-8);
                Assert.AreEqual(36.123046875, point2.Y, 1.0E-8);

                var point3 = db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry).Single() as NTSGS.Point;
                Assert.AreEqual(-115.172815918922, point3.X, 1.0E-12);
                Assert.AreEqual(36.1146435141563, point3.Y, 1.0E-12);

                db.TestGeometries.Value(g => g.Id, 4).Value(g => g.Geometry, () => GeometryInput.STPointFromGeoHash(String.Empty)).Insert();
                db.TestGeometries.Value(g => g.Id, 5).Value(g => g.Geometry, () => GeometryInput.STPointFromGeoHash(null)).Insert();

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

                var wkt5 = db.TestGeometries.Where(g => g.Id == 5).Select(g => g.Geometry.STAsText()).Single();
                Assert.IsNull(wkt5);
            }
        }
Esempio n. 19
0
        public void TestSTSymDifference()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "LINESTRING(50 100, 50 200)";
                const string Wkt2 = "LINESTRING(50 50, 50 150)";

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

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

                var result = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STSymDifference(db.TestGeometries.Where(g2 => g2.Id == 2).Single().Geometry))
                             .Single() as NTSGS.MultiLineString;

                // Order of portions was changed in PostGIS 3.1.1 Assert.AreEqual("MULTILINESTRING((50 150,50 200),(50 50,50 100))", result);

                Assert.IsNotNull(result);
                Assert.AreEqual(2, result.Geometries.Length);
                Assert.IsTrue(result.Geometries.All(g => g.NumPoints == 2));
                Assert.IsTrue(result.Geometries.All(g => g.Coordinates[0][0] == 50));
            }
        }
Esempio n. 20
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)));
            }
        }
Esempio n. 21
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. 22
0
        public void TestSTPointFromGeoHash()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string geohash1 = "9qqj7nmxncgyy4d0dbxqz0";
                db.TestGeometries.Value(g => g.Id, 1).Value(p => p.Geometry, () => GeometryInput.STPointFromGeoHash(geohash1)).Insert();
                db.TestGeometries.Value(g => g.Id, 2).Value(p => p.Geometry, () => GeometryInput.STPointFromGeoHash(geohash1, 4)).Insert();
                db.TestGeometries.Value(g => g.Id, 3).Value(p => p.Geometry, () => GeometryInput.STPointFromGeoHash(geohash1, 10)).Insert();

                var wkt1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STAsText()).Single();
                Assert.AreEqual("POINT(-115.172816 36.114646)", wkt1);

                var wkt2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STAsText()).Single();
                Assert.AreEqual("POINT(-115.13671875 36.123046875)", wkt2);

                var wkt3 = db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STAsText()).Single();
                Assert.AreEqual("POINT(-115.172815918922 36.1146435141563)", wkt3);

                db.TestGeometries.Value(g => g.Id, 4).Value(p => p.Geometry, () => GeometryInput.STPointFromGeoHash(String.Empty)).Insert();
                db.TestGeometries.Value(g => g.Id, 5).Value(p => p.Geometry, () => GeometryInput.STPointFromGeoHash(null)).Insert();

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

                var wkt5 = db.TestGeometries.Where(g => g.Id == 5).Select(g => g.Geometry.STAsText()).Single();
                Assert.IsNull(wkt5);
            }
        }
 public void Setup()
 {
     using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
     {
         db.TestGeometries.Delete();
     }
 }
Esempio n. 24
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);
            }
        }
Esempio 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);
            }
        }
        public void TestSTRotateOriginGeom()
        {
            var expected = new double[][]
            {
                new[] { 116.42245883568916, 130.67207346706593 },
                new[] { 21.15966441940092, 75.67207346706593 },
                new[] { 46.15966441940093, 32.370803277844 }
            };

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt = "LINESTRING (50 160, 50 50, 100 50)";
                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.STRotate(-1.0 * Math.PI / 3.0, g.Geometry.STCentroid()))
                             .Single() as NTSGS.LineString;

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

                var origin = db.TestGeometries
                             .Where(g => g.Id == 1)
                             .Select(g => g.Geometry.STCentroid())
                             .Single() as NTSGS.Point;

                var result2 = db
                              .Select(() => AffineTransformations.STRotate(Wkt, -1.0 * Math.PI / 3.0, origin)) as NTSGS.LineString;

                CheckLineEquals(expected, result2, 1.0E-8);
            }
        }
Esempio 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)));
            }
        }
        public void TestSTScaleXYZM()
        {
            var expected = new double[][]
            {
                new[] { 0.5, 1.5, 6.0, -4.0 },
                new[] { 0.5, 0.75, 2.0, -1.0 },
            };

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt = "LINESTRING(1 2 3 4, 1 1 1 1)";
                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.STScale(GeometryConstructors.STMakePoint(0.5, 0.75, 2, -1)))
                             .Single() as NTSGS.LineString;

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

                var result2 = db
                              .Select(() => AffineTransformations.STScale(Wkt, GeometryConstructors.STMakePoint(0.5, 0.75, 2, -1))) as NTSGS.LineString;

                CheckLineEquals(expected, result2, 1.0E-8);
            }
        }
Esempio 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);
                }
            }
        }
Esempio n. 30
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()));
            }
        }