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);
            }
        }
Exemple #2
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()));
            }
        }
Exemple #3
0
        public void TestSTCollectionHomogenize()
        {
            const string Wkt = "GEOMETRYCOLLECTION(POINT(0 0),POINT(1 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.STCollectionHomogenize())
                             .Single();

                Assert.IsInstanceOf <NTSGS.MultiPoint>(result);
                var multiPoint = result as NTSGS.MultiPoint;

                var point1 = multiPoint.GetGeometryN(0);
                Assert.AreEqual(0, point1.Coordinates[0].X);
                Assert.AreEqual(0, point1.Coordinates[0].Y);

                var point2 = multiPoint.GetGeometryN(1);
                Assert.AreEqual(1, point2.Coordinates[0].X);
                Assert.AreEqual(1, point2.Coordinates[0].Y);
            }
        }
Exemple #4
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);
            }
        }
Exemple #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 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);
            }
        }
Exemple #7
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());
            }
        }
Exemple #8
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);
            }
        }
        public void TestSTWithin()
        {
            const string Wkt1 = "POINT(1 1)";
            const string Wkt2 = "LINESTRING(1 5, 2 7, 1 9, 14 12)";

            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                Assert.IsFalse(db.Select(() => SpatialRelationships.STDFullyWithin(
                                             GeometryInput.STGeomFromEWKT(Wkt1),
                                             GeometryInput.STGeomFromEWKT(Wkt2),
                                             10)));

                Assert.IsTrue(db.Select(() => SpatialRelationships.STDFullyWithin(
                                            GeometryInput.STGeomFromEWKT(Wkt1),
                                            GeometryInput.STGeomFromEWKT(Wkt2),
                                            20)));

                Assert.IsTrue(db.Select(() => SpatialRelationships.STDWithin(
                                            GeometryInput.STGeomFromEWKT(Wkt1),
                                            GeometryInput.STGeomFromEWKT(Wkt2),
                                            10)));

                // TODO: need explicit cast text to geometry
                if (this.CurrentVersion >= new Version("3.0.0"))
                {
                    Assert.IsFalse(db.Select(() => SpatialRelationships.STDFullyWithin(Wkt1, Wkt2, 10)));
                    Assert.IsTrue(db.Select(() => SpatialRelationships.STDFullyWithin(Wkt1, Wkt2, 20)));
                    Assert.IsTrue(db.Select(() => SpatialRelationships.STDWithin(Wkt1, Wkt2, 10)));
                }
            }
        }
        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)));
            }
        }
        public void TestST3DDWithin()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "POINT(1 1 2)";
                const string Wkt2 = "LINESTRING(1 5 2, 2 7 20, 1 9 100, 14 12 3)";

                Assert.IsTrue(db.Select(() => SpatialRelationships.ST3DDWithin(
                                            GeometryInput.STGeomFromEWKT(Wkt1),
                                            GeometryInput.STGeomFromEWKT(Wkt2),
                                            10)));

                Assert.IsFalse(db.Select(() => SpatialRelationships.ST3DDFullyWithin(
                                             GeometryInput.STGeomFromEWKT(Wkt1),
                                             GeometryInput.STGeomFromEWKT(Wkt2),
                                             10)));

                Assert.IsTrue(db.Select(() => SpatialRelationships.ST3DDWithin(Wkt1, Wkt2, 10)));
                Assert.IsNull(db.Select(() => SpatialRelationships.ST3DDWithin((NTSG)null, (NTSG)null, 10)));
                Assert.IsNull(db.Select(() => SpatialRelationships.ST3DDWithin((string)null, (string)null, 10)));

                Assert.IsFalse(db.Select(() => SpatialRelationships.ST3DDFullyWithin(Wkt1, Wkt2, 10)));
                Assert.IsNull(db.Select(() => SpatialRelationships.ST3DDFullyWithin((NTSG)null, (NTSG)null, 10)));
                Assert.IsNull(db.Select(() => SpatialRelationships.ST3DDFullyWithin((string)null, (string)null, 10)));
            }
        }
Exemple #12
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 TestSTPerimeter()
        {
            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(p => p.Geometry, () => GeometryInput.STGeomFromEWKT(ewkt1)).Insert();

                const string ewkt2 = @"SRID=2249;
                    MULTIPOLYGON(((763104.471273676 2949418.44119003,
                        763104.477769673 2949418.42538203,
                        763104.189609677 2949418.22343004,763104.471273676 2949418.44119003)),
                        ((763104.471273676 2949418.44119003,763095.804579742 2949436.33850239,
                        763086.132105649 2949451.46730207,763078.452329651 2949462.11549407,
                        763075.354136904 2949466.17407812,763064.362142565 2949477.64291974,
                        763059.953961626 2949481.28983009,762994.637609571 2949532.04103014,
                        762990.568508415 2949535.06640477,762986.710889563 2949539.61421415,
                        763117.237897679 2949709.50493431,763235.236617789 2949617.95619822,
                        763287.718121842 2949562.20592617,763111.553321674 2949423.91664605,
                        763104.471273676 2949418.44119003)))";
                db.TestGeometries.Value(g => g.Id, 2).Value(p => p.Geometry, () => GeometryInput.STGeomFromEWKT(ewkt2)).Insert();

                const string ewkt3 = "SRID=2249;POINT(0 0)";
                db.TestGeometries.Value(g => g.Id, 3).Value(p => p.Geometry, () => GeometryInput.STGeomFromEWKT(ewkt3)).Insert();
                db.TestGeometries.Value(g => g.Id, 4).Value(p => p.Geometry, () => null).Insert();

                Assert.AreEqual(122.630744000095, db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STPerimeter()).Single(), 0.000000000001);
                Assert.AreEqual(122.630744000095, db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STPerimeter2D()).Single(), 0.000000000001);
                Assert.AreEqual(845.227713366825, db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STPerimeter()).Single(), 0.000000000001);
                Assert.AreEqual(845.227713366825, db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STPerimeter2D()).Single(), 0.000000000001);
                Assert.AreEqual(0.0, db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STPerimeter()).Single());
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 4).Select(g => g.Geometry.STPerimeter()).Single());
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 4).Select(g => g.Geometry.STPerimeter2D()).Single());
            }
        }
        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);
            }
        }
Exemple #15
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);
            }
        }
Exemple #16
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()));
            }
        }
Exemple #17
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)));
            }
        }
        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);
            }
        }
Exemple #19
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 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);
            }
        }
Exemple #21
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);
                }
            }
        }
Exemple #22
0
        public void TestSTForceRHR()
        {
            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))";

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

                var rhrGeom = db.TestGeometries
                              .Where(g => g.Id == 1)
                              .Select(g => g.Geometry.STForceRHR())
                              .Single() as NTSGS.Polygon;

                var originGeom = db.TestGeometries
                                 .Where(g => g.Id == 1)
                                 .Select(g => g.Geometry)
                                 .Single() as NTSGS.Polygon;

                //Assertion about interior ring
                var originInteriorRing = originGeom.InteriorRings[0];
                var rrhInteriorRing    = rhrGeom.InteriorRings[0];

                //Cause that head point equals end point forever,so only check point at index 1,2
                Assert.AreEqual(originInteriorRing.Coordinates[1].Z, rrhInteriorRing.Coordinates[2].Z);
                Assert.AreEqual(originInteriorRing.Coordinates[1].X, rrhInteriorRing.Coordinates[2].X);
                Assert.AreEqual(originInteriorRing.Coordinates[1].Y, rrhInteriorRing.Coordinates[2].Y);

                Assert.AreEqual(originInteriorRing.Coordinates[2].Z, rrhInteriorRing.Coordinates[1].Z);
                Assert.AreEqual(originInteriorRing.Coordinates[2].X, rrhInteriorRing.Coordinates[1].X);
                Assert.AreEqual(originInteriorRing.Coordinates[2].Y, rrhInteriorRing.Coordinates[1].Y);

                //Assertion about exterior ring
                var originExteriorRing = originGeom.ExteriorRing;
                var rrhExteriorRing    = rhrGeom.ExteriorRing;

                //Cause that head point equals end point forever,so only check point at index 1,2
                Assert.AreEqual(originExteriorRing.Coordinates[1].Z, rrhExteriorRing.Coordinates[2].Z);
                Assert.AreEqual(originExteriorRing.Coordinates[1].X, rrhExteriorRing.Coordinates[2].X);
                Assert.AreEqual(originExteriorRing.Coordinates[1].Y, rrhExteriorRing.Coordinates[2].Y);

                //Cause that head point equals end point forever,so only check point at index 1,2
                Assert.AreEqual(originExteriorRing.Coordinates[2].Z, rrhExteriorRing.Coordinates[1].Z);
                Assert.AreEqual(originExteriorRing.Coordinates[2].X, rrhExteriorRing.Coordinates[1].X);
                Assert.AreEqual(originExteriorRing.Coordinates[2].Y, rrhExteriorRing.Coordinates[1].Y);

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

                Assert.AreEqual(
                    "POLYGON((0 0 2,0 5 2,5 0 2,0 0 2),(1 1 2,3 1 2,1 3 2,1 1 2))",
                    db.Select(() => GeometryEditors.STForceRHR("POLYGON((0 0 2, 5 0 2, 0 5 2, 0 0 2),(1 1 2, 1 3 2, 3 1 2, 1 1 2))").STAsEWKT()));
            }
        }
        public void TestST3DMaxDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var pt   = db.Select(() => GeometryInput.STGeomFromEWKT("SRID=4326;POINT(-72.1235 42.3521 10000)").STTransform(2163));
                var line = db.Select(() => GeometryInput.STGeomFromEWKT("SRID=4326;LINESTRING(-72.1260 42.45 15, -72.123 42.1546 20)").STTransform(2163));

                var maxDistance1 = db.Select(() => MeasurementFunctions.ST3DMaxDistance(pt, line));
                Assert.AreEqual(24383.7467488441, maxDistance1, 1.0E-9);
            }
        }
        public void TestST3DPerimeter()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var geometry1  = db.Select(() => GeometryInput.STGeomFromEWKT("SRID=2249;POLYGON((743238 2967416 2,743238 2967450 1,743265.625 2967416 1, 743238 2967416 2))"));
                var perimeter1 = db.Select(() => MeasurementFunctions.ST3DPerimeter(geometry1));
                Assert.AreEqual(105.465793597674, perimeter1, 1.0E-9);

                Assert.IsNull(db.Select(() => MeasurementFunctions.ST3DPerimeter(null)));
            }
        }
Exemple #25
0
        public void TestSTAsEncodedPolyline()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var g1 = db.Select(() => GeometryInput.STGeomFromEWKT("SRID=4326;LINESTRING(-120.2 38.5,-120.95 40.7,-126.453 43.252)"));

                var hexewkb = db.Select(() => GeometryOutput.STAsEncodedPolyline(g1));
                Assert.AreEqual("_p~iF~ps|U_ulLnnqC_mqNvxq`@", hexewkb);

                Assert.IsNull(db.Select(() => GeometryOutput.STAsEncodedPolyline(null)));
            }
        }
Exemple #26
0
        public void TestSTForcePolygonCW()
        {
            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))";

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

                var cwGeometry = db.TestGeometries
                                 .Where(g => g.Id == 1)
                                 .Select(g => g.Geometry.STForcePolygonCW())
                                 .Single() as NTSGS.Polygon;

                var originalGeometry = db.TestGeometries
                                       .Where(g => g.Id == 1)
                                       .Select(g => g.Geometry)
                                       .Single() as NTSGS.Polygon;

                //Assertion about interior ring
                var originInteriorRing = originalGeometry.InteriorRings[0];
                var cwInteriorRing     = cwGeometry.InteriorRings[0];

                //Cause that head point equals end point forever,so only check point at index 1,2
                Assert.AreEqual(originInteriorRing.Coordinates[1].Z, cwInteriorRing.Coordinates[2].Z);
                Assert.AreEqual(originInteriorRing.Coordinates[1].X, cwInteriorRing.Coordinates[2].X);
                Assert.AreEqual(originInteriorRing.Coordinates[1].Y, cwInteriorRing.Coordinates[2].Y);

                Assert.AreEqual(originInteriorRing.Coordinates[2].Z, cwInteriorRing.Coordinates[1].Z);
                Assert.AreEqual(originInteriorRing.Coordinates[2].X, cwInteriorRing.Coordinates[1].X);
                Assert.AreEqual(originInteriorRing.Coordinates[2].Y, cwInteriorRing.Coordinates[1].Y);

                //Assertion about exterior ring
                var originExteriorRing = originalGeometry.ExteriorRing;
                var cwExteriorRing     = cwGeometry.ExteriorRing;

                //Cause that head point equals end point forever,so only check point at index 1,2
                Assert.AreEqual(originExteriorRing.Coordinates[1].Z, cwExteriorRing.Coordinates[2].Z);
                Assert.AreEqual(originExteriorRing.Coordinates[1].X, cwExteriorRing.Coordinates[2].X);
                Assert.AreEqual(originExteriorRing.Coordinates[1].Y, cwExteriorRing.Coordinates[2].Y);

                //Cause that head point equals end point forever,so only check point at index 1,2
                Assert.AreEqual(originExteriorRing.Coordinates[2].Z, cwExteriorRing.Coordinates[1].Z);
                Assert.AreEqual(originExteriorRing.Coordinates[2].X, cwExteriorRing.Coordinates[1].X);
                Assert.AreEqual(originExteriorRing.Coordinates[2].Y, cwExteriorRing.Coordinates[1].Y);
            }
        }
Exemple #27
0
        public void TestGeometryFromEWKB()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string ewkt1 = "SRID=4269;LINESTRING(-71.16028 42.258729,-71.160837 42.259112,-71.161143 42.25932)";
                var          ewkb1 = db.Select(() => GeometryInput.STGeomFromEWKT(ewkt1).STAsEWKB());

                var g = db.Select(() => GeometryInput.STGeomFromEWKB(ewkb1));

                Assert.AreEqual(ewkt1, db.Select(() => GeometryInput.STGeomFromEWKB(ewkb1).STAsEWKT()));
                Assert.AreEqual(ewkt1, db.Select(() => GeometryInput.STGeomFromEWKB(ewkb1).STAsEWKT()));

                Assert.IsNull(db.Select(() => GeometryInput.STGeomFromEWKB(null)));
            }
        }
Exemple #28
0
        public void TestSTPointOnSurface()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string ewkt = "LINESTRING(0 5 1, 0 0 1, 0 10 2)";
                db.TestGeometries
                .Value(g => g.Id, 1)
                .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(ewkt))
                .Insert();

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

                Assert.AreEqual("POINT(0 0 1)", result);
            }
        }
Exemple #29
0
        public void TestSTExteriorRing()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                Assert.AreEqual(
                    "LINESTRING(0 0 1,1 1 1,1 2 1,1 1 1,0 0 1)",
                    db.Select(() => GeometryInput
                              .STGeomFromEWKT("POLYGON((0 0 1, 1 1 1, 1 2 1, 1 1 1, 0 0 1))")
                              .STExteriorRing()
                              .STAsEWKT()));

                Assert.AreEqual(
                    "LINESTRING(0 0 1,1 1 1,1 2 1,1 1 1,0 0 1)",
                    db.Select(() => GeometryAccessors
                              .STExteriorRing("POLYGON((0 0 1, 1 1 1, 1 2 1, 1 1 1, 0 0 1))")
                              .STAsEWKT()));

                Assert.IsNull(db.Select(() => GeometryAccessors.STExteriorRing((NTSG)null)));
            }
        }
Exemple #30
0
        public void TestSTPatchN()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Ewkt = @"POLYHEDRALSURFACE( 
                                        ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
                                        ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
                                        ((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
                                        ((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Ewkt)).Insert();
                db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText("POINT(1 1)")).Insert();
                db.TestGeometries.Value(g => g.Id, 3).Value(g => g.Geometry, () => null).Insert();

                Assert.AreEqual("POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))", db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STPatchN(2).STAsEWKT()).Single());
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STPatchN(1)).Single());
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STPatchN(1)).Single());

                Assert.AreEqual("POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))", db.Select(() => GeometryAccessors.STPatchN(Ewkt, 2).STAsEWKT()));
            }
        }