public void TestSTLineFromMultiPoint() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STLineFromMultiPoint(GeometryInput.STGeomFromText("MULTIPOINT(1 2 3, 4 5 6, 7 8 9)"))) .Insert(); Assert.AreEqual( "LINESTRING(1 2 3,4 5 6,7 8 9)", db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STAsEWKT()) .Single()); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STLineFromMultiPoint("MULTIPOINT(1 2 3, 4 5 6, 7 8 9)")) .Insert(); Assert.AreEqual( "LINESTRING(1 2 3,4 5 6,7 8 9)", db.TestGeometries .Where(g => g.Id == 2) .Select(g => g.Geometry.STAsEWKT()) .Single()); } }
public void TestSTMinimumBoundingCircle() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string wkt = "LINESTRING(55 75,125 150)"; db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STCollect( GeometryInput.STGeomFromText(wkt), GeometryConstructors.STPoint(20, 80))) .Insert(); var geometry = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STAsText()) .Single(); Assert.AreEqual("GEOMETRYCOLLECTION(LINESTRING(55 75,125 150),POINT(20 80))", geometry); // TODO: fix 'points must form a closed linestring' ////var circle = db.TestGeometries //// .Where(g => g.Id == 1) //// .Select(g => g.Geometry.STMinimumBoundingCircle(8)) //// .Single(); //Assert.AreEqual(135.59714732062, circle.InteriorRings[0].GetPointN(0).X, 1.0E-8); //Assert.AreEqual(115, circle.InteriorRings[0].GetPointN(0).Y, 1.0E-8); } }
public void TestSTOrientedEnvelope() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string wkt = "MULTIPOINT ((0 0), (-1 -1), (3 2))"; db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt)) .Insert(); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STCollect( GeometryInput.STGeomFromText("LINESTRING(55 75,125 150)"), GeometryConstructors.STPoint(20, 80))) .Insert(); var result1 = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STOrientedEnvelope().STAsText()) .Single(); Assert.AreEqual("POLYGON((3 2,2.88 2.16,-1.12 -0.84,-1 -1,3 2))", result1); var result2 = db.TestGeometries .Where(g => g.Id == 2) .Select(g => g.Geometry.STOrientedEnvelope()) .Single() as NTSGS.Polygon; Assert.AreEqual(20, result2.ExteriorRing.GetPointN(0).X, 1.0E-8); Assert.AreEqual(80, result2.ExteriorRing.GetPointN(0).Y, 1.0E-8); } }
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 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); } }
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 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 TestSTMakeEnvelope() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STMakeEnvelope(10, 10, 11, 11, SRID4326)) .Insert(); Assert.AreEqual( "SRID=4326;POLYGON((10 10,10 11,11 11,11 10,10 10))", db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STAsEWKT()) .Single()); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STMakeEnvelope(10, 10, 11, 11)) .Insert(); Assert.AreEqual( "POLYGON((10 10,10 11,11 11,11 10,10 10))", db.TestGeometries .Where(g => g.Id == 2) .Select(g => g.Geometry.STAsEWKT()) .Single()); } }
public void TestSTMakePoint() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STMakePoint(-71.1043443253471, 42.3150676015829)) .Insert(); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STMakePoint(1, 2, 1.5)) .Insert(); db.TestGeometries .Value(g => g.Id, 3) .Value(g => g.Geometry, () => GeometryConstructors.STMakePoint(10, 20, 30, -999)) .Insert(); var point1 = db.TestGeometries.Where(g => g.Id == 1); Assert.AreEqual(-71.1043443253471, point1.Select(g => g.Geometry.STX()).Single().Value, 0.0000000000001); Assert.AreEqual(42.3150676015829, point1.Select(g => g.Geometry.STY()).Single().Value, 0.0000000000001); var point2 = db.TestGeometries.Where(g => g.Id == 2); Assert.AreEqual(1, point2.Select(g => g.Geometry.STX()).Single().Value, 0.1); Assert.AreEqual(2, point2.Select(g => g.Geometry.STY()).Single().Value, 0.1); Assert.AreEqual(1.5, point2.Select(g => g.Geometry.STZ()).Single().Value, 0.1); var point3 = db.TestGeometries.Where(g => g.Id == 3); Assert.AreEqual(10, point3.Select(g => g.Geometry.STX()).Single().Value, 0.1); Assert.AreEqual(20, point3.Select(g => g.Geometry.STY()).Single().Value, 0.1); Assert.AreEqual(30, point3.Select(g => g.Geometry.STZ()).Single().Value, 0.1); Assert.AreEqual(-999, point3.Select(g => g.Geometry.STM()).Single().Value, 0.1); } }
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); } }
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); } }
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)"))); } }
public void TestSTTileEnvelope() { 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, () => GeometryConstructors.STTileEnvelope(2, 1, 1)) .Insert(); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STTileEnvelope(3, 1, 1, GeometryConstructors.STMakeEnvelope(-180, -90, 180, 90, SRID4326))) .Insert(); db.TestGeometries .Value(g => g.Id, 3) .Value(g => g.Geometry, () => GeometryConstructors.STTileEnvelope(2, 1, 1, "SRID=3857;LINESTRING(-20037508.342789 -20037508.342789,20037508.342789 20037508.342789)")) .Insert(); var result1 = db.TestGeometries.Where(g => g.Id == 1); var poly1 = result1.Select(g => g.Geometry).Single() as NTSGS.Polygon; Assert.AreEqual(-10018754.1713945, poly1.Coordinates[0].X, 1.0E-6); Assert.AreEqual(0, poly1.Coordinates[0].Y, 1.0E-6); Assert.AreEqual(-10018754.1713945, poly1.Coordinates[1].X, 1.0E-6); Assert.AreEqual(10018754.1713945, poly1.Coordinates[1].Y, 1.0E-6); Assert.AreEqual(0, poly1.Coordinates[2].X, 1.0E-6); Assert.AreEqual(10018754.1713945, poly1.Coordinates[2].Y, 1.0E-6); Assert.AreEqual(0, poly1.Coordinates[3].X, 1.0E-6); Assert.AreEqual(0, poly1.Coordinates[3].Y, 1.0E-6); Assert.AreEqual(-10018754.1713945, poly1.Coordinates[4].X, 1.0E-6); Assert.AreEqual(0, poly1.Coordinates[4].Y, 1.0E-6); Assert.AreEqual(SRID3857, poly1.SRID); var result2 = db.TestGeometries.Where(g => g.Id == 2); Assert.AreEqual("POLYGON((-135 45,-135 67.5,-90 67.5,-90 45,-135 45))", result2.Select(g => g.Geometry.STAsText()).Single()); Assert.AreEqual(SRID4326, result2.Select(g => g.Geometry.STSrId()).Single()); var result3 = db.TestGeometries.Where(g => g.Id == 3); var poly3 = result3.Select(g => g.Geometry).Single() as NTSGS.Polygon; Assert.AreEqual(-10018754.1713945, poly3.Coordinates[0].X, 1.0E-6); Assert.AreEqual(0, poly3.Coordinates[0].Y, 1.0E-6); Assert.AreEqual(-10018754.1713945, poly3.Coordinates[1].X, 1.0E-6); Assert.AreEqual(10018754.1713945, poly3.Coordinates[1].Y, 1.0E-6); Assert.AreEqual(0, poly3.Coordinates[2].X, 1.0E-6); Assert.AreEqual(10018754.1713945, poly3.Coordinates[2].Y, 1.0E-6); Assert.AreEqual(0, poly3.Coordinates[3].X, 1.0E-6); Assert.AreEqual(0, poly3.Coordinates[3].Y, 1.0E-6); Assert.AreEqual(-10018754.1713945, poly3.Coordinates[4].X, 1.0E-6); Assert.AreEqual(0, poly3.Coordinates[4].Y, 1.0E-6); Assert.AreEqual(SRID3857, poly3.SRID); } } }
public void TestSTCollect() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STCollect( GeometryInput.STGeomFromText("POINT(1 2)"), GeometryInput.STGeomFromText("POINT(-2 3)"))) .Insert(); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STCollect( GeometryInput.STGeomFromText("POINT(1 2)"), GeometryInput.STGeomFromText("LINESTRING(0 0, 0 1, 1 0, 1 1, 0 0)"))) .Insert(); db.TestGeometries .Value(g => g.Id, 3) .Value(g => g.Geometry, () => GeometryConstructors.STCollect( "POINT(1 2)", "POINT(-2 3)")) .Insert(); db.TestGeometries .Value(g => g.Id, 4) .Value(g => g.Geometry, () => GeometryConstructors.STCollect( "CIRCULARSTRING(220268 150415,220227 150505,220227 150406)", "CIRCULARSTRING(220227 150406,2220227 150407,220227 150406)")) .Insert(); var collected1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STAsText()).Single(); Assert.AreEqual("MULTIPOINT(1 2,-2 3)", collected1); var collected2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STAsText()).Single(); Assert.AreEqual("GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(0 0,0 1,1 0,1 1,0 0))", collected2); Assert.AreEqual( "MULTIPOINT(1 2,-2 3)", db.TestGeometries .Where(g => g.Id == 3) .Select(g => g.Geometry.STAsText()) .Single()); // Converting to WKT using STAsText to avoid 'Geometry type not recognized. GeometryCode: 11' error. Assert.AreEqual( "MULTICURVE(CIRCULARSTRING(220268 150415,220227 150505,220227 150406),CIRCULARSTRING(220227 150406,2220227 150407,220227 150406))", db.TestGeometries .Where(g => g.Id == 4) .Select(g => g.Geometry.STAsText()) .Single()); } }
public void TestSTMakePointM() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries.Value(g => g.Id, 1).Value(p => p.Geometry, () => GeometryConstructors.STMakePointM(10, 20, -999)).Insert(); var point1 = db.TestGeometries.Where(g => g.Id == 1); Assert.AreEqual(10, point1.Select(g => g.Geometry.STX()).Single(), 0.1); Assert.AreEqual(20, point1.Select(g => g.Geometry.STY()).Single(), 0.1); Assert.AreEqual(-999, point1.Select(g => g.Geometry.STM()).Single(), 0.1); } }
public void TestSTAsText() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var g1 = db.Select(() => GeometryConstructors.STMakePoint(-71.064544, 42.28787)); Assert.AreEqual("POINT(-71.064544 42.28787)", db.Select(() => GeometryOutput.STAsText(g1))); Assert.AreEqual("POINT(-71.065 42.288)", db.Select(() => GeometryOutput.STAsText(g1, 3))); Assert.AreEqual("POINT(-71 42)", db.Select(() => GeometryOutput.STAsText(g1, 0))); Assert.IsNull(db.Select(() => GeometryOutput.STAsText(null))); } }
public void TestSTClipByBox2D() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var geom1 = db.Select(() => GeometryInput.STGeomFromText("LINESTRING(0 0, 20 20)")); var box1 = db.Select(() => GeometryConstructors.STMakeEnvelope(0, 0, 10, 10)); var clipped1 = db.Select(() => GeometryProcessing.STClipByBox2D(geom1, box1).STAsText()); Assert.AreEqual("LINESTRING(0 0,10 10)", clipped1); Assert.IsNull(db.Select(() => GeometryProcessing.STClipByBox2D(null, null))); } }
public void TestSTPoint() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STPoint(-71.104, 42.315)) .Insert(); var point1 = db.TestGeometries.Where(g => g.Id == 1); Assert.AreEqual(-71.104, point1.Select(g => g.Geometry.STX()).Single().Value, 0.001); Assert.AreEqual(42.315, point1.Select(g => g.Geometry.STY()).Single().Value, 0.001); } }
public void TestSTPolygon() { const string Wkt1 = "LINESTRING(75 29, 77 29, 77 29, 75 29)"; const string Wkt2 = "LINESTRING(75 29 1, 77 29 2, 77 29 3, 75 29 1)"; using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STPolygon(GeometryInput.STGeomFromText(Wkt1), SRID4326)) .Insert(); Assert.AreEqual( "POLYGON((75 29,77 29,77 29,75 29))", db.TestGeometries.Where(g => g.Id == 1) .Select(g => g.Geometry.STAsText()) .Single()); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STPolygon(GeometryInput.STGeomFromText(Wkt2), SRID4326)) .Insert(); Assert.AreEqual( "SRID=4326;POLYGON((75 29 1,77 29 2,77 29 3,75 29 1))", db.TestGeometries .Where(g => g.Id == 2) .Select(g => g.Geometry.STAsEWKT()) .Single()); // TODO: ? reason of error? ST_Polygon(text) not works in 2.5 ? var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion())); if (version >= new Version("3.0.0")) { db.TestGeometries .Value(g => g.Id, 3) .Value(g => g.Geometry, () => GeometryConstructors.STPolygon(Wkt1, SRID4326)) .Insert(); Assert.AreEqual( "POLYGON((75 29,77 29,77 29,75 29))", db.TestGeometries.Where(g => g.Id == 3) .Select(g => g.Geometry.STAsText()) .Single()); } } }
public void TestSTAzimuth() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var p1 = db.Select(() => GeometryConstructors.STPoint(25, 45)); var p2 = db.Select(() => GeometryConstructors.STPoint(75, 100)); var a1 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAzimuth(p1, p2))); var a2 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAzimuth(p2, p1))); Assert.AreEqual(42.2736890060937, a1, 1.0E-8); Assert.AreEqual(222.273689006094, a2, 1.0E-8); Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(p1, p1))); Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(p1, null))); Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(null, p1))); } }
public void TestSTAngle() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var p1 = db.Select(() => GeometryConstructors.STPoint(0, 0)); var p2 = db.Select(() => GeometryConstructors.STPoint(100, 100)); var p3 = db.Select(() => GeometryConstructors.STPoint(0, 0)); var p4 = db.Select(() => GeometryConstructors.STPoint(100, 0)); var a1 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAngle(p1, p2, p3, p4))); Assert.AreEqual(45, a1.Value, 1.0E-8); var a2 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAngle(p2, p1, p4))); Assert.AreEqual(45, a2.Value, 1.0E-8); Assert.IsNull(db.Select(() => MeasurementFunctions.STAngle(p1, p1, p1, p1))); } }
public void TestSTSetSrId() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries.Value(g => g.Id, 1).Value(p => p.Geometry, () => GeometryConstructors.STMakePoint(-123.365556, 48.428611).STSetSrId(SRID4326)).Insert(); db.TestGeometries.Value(g => g.Id, 2).Value(p => p.Geometry, () => GeometryConstructors.STMakePoint(-123.365556, 48.428611).STSetSrId(SRID4326).STTransform(3785)).Insert(); var ewkt1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STAsEWKT()).Single(); Assert.AreEqual("SRID=4326;POINT(-123.365556 48.428611)", ewkt1); var srid1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STSrId()).Single(); Assert.AreEqual(SRID4326, srid1); var ewkt2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STAsEWKT()).Single(); Assert.AreEqual("SRID=3785;POINT(-13732990.8753491 6178458.96425423)", ewkt2); var srid2 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STSrId()).Single(); Assert.AreEqual(3785, srid2); } }
public void TestSTSquare() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion())); if (version >= new Version("3.1.0")) { var origin = db.Select(() => GeometryConstructors.STMakePoint(0, 0)); var square1 = db.Select(() => GeometryConstructors.STSquare(1.0, 0, 0, origin)) as NTSGS.Polygon; Assert.IsNotNull(square1); Assert.AreEqual(5, square1.Coordinates.Length); var square2 = db.Select(() => GeometryConstructors.STSquare(1.0, 0, 0)) as NTSGS.Polygon; Assert.IsNotNull(square2); Assert.AreEqual(5, square2.Coordinates.Length); } } }
public void TestSTIsValidTrajectory() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STMakeLine( GeometryConstructors.STMakePointM(0, 0, 1), GeometryConstructors.STMakePointM(0, 1, 2))) .Insert(); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STMakeLine( GeometryConstructors.STMakePointM(0, 0, 1), GeometryConstructors.STMakePointM(0, 1, 0))) .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.STIsValidTrajectory()).Single()); Assert.IsFalse(db.TestGeometries .Where(g => g.Id == 2) .Select(g => g.Geometry.STIsValidTrajectory()) .Single()); Assert.IsNull(db.TestGeometries .Where(g => g.Id == 3) .Select(g => g.Geometry.STIsValidTrajectory()) .Single()); Assert.IsTrue(db.Select(() => TrajectoryFunctions.STIsValidTrajectory("LINESTRING(0 0 0 1,0 1 0 2)"))); Assert.IsFalse(db.Select(() => TrajectoryFunctions.STIsValidTrajectory("POINT(0 0)"))); } }
public void TestSTGeoHash() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries.Value(g => g.Id, 1).Value(p => p.Geometry, () => GeometryConstructors.STMakePoint(-126, 48).STSetSrId(SRID4326)).Insert(); db.TestGeometries.Value(g => g.Id, 2).Value(p => p.Geometry, () => null).Insert(); var geohash1 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STGeoHash()).Single(); Assert.AreEqual("c0w3hf1s70w3hf1s70w3", geohash1); var geohash2 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STGeoHash(5)).Single(); Assert.AreEqual("c0w3h", geohash2); var srid2 = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STSrId()).Single(); Assert.AreEqual(SRID4326, srid2); var geohash3 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STGeoHash()).Single(); Assert.IsNull(geohash3); var srid3 = db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STSrId()).Single(); Assert.IsNull(srid3); } }
public void TestSTSplit() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STMakeLine(GeometryConstructors.STMakePoint(10, 10), GeometryConstructors.STMakePoint(190, 190))) .Insert(); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryInput.STGeomFromText("POINT(100 90)").STBuffer(50)) .Insert(); var result = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STSplit(db.TestGeometries.Where(g2 => g2.Id == 2).Single().Geometry)) .Single() as NTSGS.GeometryCollection; Assert.IsNotNull(result); } }
public void TestSTSetSrId() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STMakePoint(-123.365556, 48.428611).STSetSrId(SRID4326)) .Insert(); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STMakePoint(-123.365556, 48.428611).STSetSrId(SRID4326).STTransform(3785)) .Insert(); var ewkt1 = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STAsEWKT()) .Single(); StringAssert.StartsWith("SRID=4326;POINT", ewkt1); var srid1 = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STSrId()) .Single(); Assert.AreEqual(SRID4326, srid1); var point2 = db.TestGeometries .Where(g => g.Id == 2) .Select(g => g.Geometry) .Single() as NTSGS.Point; Assert.AreEqual(3785, point2.SRID); Assert.AreEqual(-13732990.8753491, point2.X, 1.0E-6); Assert.AreEqual(6178458.96425423, point2.Y, 1.0E-6); var srid2 = db.TestGeometries .Where(g => g.Id == 2) .Select(g => g.Geometry.STSrId()) .Single(); Assert.AreEqual(3785, srid2); } }
public void TestSTAzimuth() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var p1 = db.Select(() => GeometryConstructors.STPoint(25, 45)); var p2 = db.Select(() => GeometryConstructors.STPoint(75, 100)); var a1 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAzimuth(p1, p2))); var a2 = db.Select(() => MathematicalFunctions.Degrees(MeasurementFunctions.STAzimuth(p2, p1))); Assert.AreEqual(42.2736890060937, a1.Value, 1.0E-8); Assert.AreEqual(222.273689006094, a2.Value, 1.0E-8); Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(p1, p1))); Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(p1, null))); Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth(null, p1))); ////Assert.IsNull(db.Select(() => MeasurementFunctions.STAzimuth((NTSG)null, (NTSG)null))); var pointA = new NTSGS.Point(0, 0) { SRID = SRID4326 }; db.Insert(new TestGeographyEntity(1, pointA)); var pointB = new NTSGS.Point(15, 5) { SRID = SRID4326 }; db.Insert(new TestGeographyEntity(2, pointB)); var azimuth = db.TestGeographies .Where(g => g.Id == 1) .Select(g => g.Geography.STAzimuth(db.TestGeographies.Where(g0 => g0.Id == 2).Single().Geography)) .Single(); Assert.AreEqual(1.24683, azimuth.Value, 1.0E-5); } }
public void TestSTBoundingDiagonalWithFits() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STMakePoint(0, 0).STBuffer(10)) .Insert(); var bbBoxDiagonal1 = db.TestGeometries .Select(g => g.Geometry.STBoundingDiagonal(false).STAsText()) .Single(); Assert.AreEqual("LINESTRING(-10 -10,10 10)", bbBoxDiagonal1); var bbBoxDiagonal2 = db.TestGeometries .Select(g => GeometryAccessors.STBoundingDiagonal(g.Geometry.STAsText(), false).STAsText()) .Single(); Assert.AreEqual("LINESTRING(-10 -10,10 10)", bbBoxDiagonal2); Assert.IsNull(db.Select(() => GeometryAccessors.STBoundingDiagonal((NTSG)null, false))); } }
public void TestSTQuantizeCoordinates() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { Assert.AreEqual( "POINT(100.0625 0)", db.Select(() => GeometryEditors .STQuantizeCoordinates( GeometryConstructors.STMakePoint(100.123456, 0), 0, 0, 0, 0) .STAsText())); Assert.AreEqual( 100.123455047607, db.Select(() => GeometryEditors .STQuantizeCoordinates( GeometryConstructors.STMakePoint(100.123456, 0), 4) .STX()).Value, 1.0E-12); Assert.IsNull(db.Select(() => GeometryEditors.STQuantizeCoordinates((NTSG)null, 0, 0, 0, 0))); } }