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 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())); } }
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())); } }
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); } }
public void TestSTCurveToLine() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string Wkt = "CIRCULARSTRING(0 0,100 -100,200 0)"; db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt)) .Insert(); var result1 = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STCurveToLine(20, 1, 1)) .Single() as NTSGS.LineString; Assert.AreEqual(0, result1.Coordinates[0].X); Assert.AreEqual(0, result1.Coordinates[0].Y); Assert.AreEqual(50, result1.Coordinates[1].X, 1.0E-9); Assert.AreEqual(-86.6025403784438, result1.Coordinates[1].Y, 1.0E-9); Assert.AreEqual(150, result1.Coordinates[2].X, 1.0E-9); Assert.AreEqual(-86.6025403784439, result1.Coordinates[2].Y, 1.0E-9); Assert.AreEqual(200, result1.Coordinates[3].X, 1.0E-9); Assert.AreEqual(0, result1.Coordinates[3].Y, 1.0E-9); Assert.IsNull(db.Select(() => GeometryEditors.STCurveToLine(null, 20, 1, 1))); } }
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))); } }
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 TestSTFlipCoordinates() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var geom1 = db.Select(() => GeometryInput.STGeomFromText("POINT(1 2)")); var result1 = db.Select(() => GeometryEditors.STFlipCoordinates(geom1).STAsText()); Assert.AreEqual("POINT(2 1)", result1); Assert.IsNull(db.Select(() => GeometryEditors.STFlipCoordinates(null))); } }
public void TestGeometryConstructors() { using (var db = GetDbConnection()) { var point1 = db.PostgisGeometries.Select(g => GeometryEditors.STSetSrid(GeometryConstructors.STPoint(-71.064544, 42.28787), SRID_WGS_84)); // Execute on DB context, not specific table (exclude FROM <table> from generated SQL statement) var point2 = db.STGeomFromText("POINT(-71.064544 42.28787)", SRID_WGS_84); var point3 = db.STGeomFromEWKT("SRID=" + SRID_WGS_84.ToString() + ";POINT(-71.064544 42.28787)"); Assert.IsTrue(point1.Select(g => g.STEquals(point2)).First()); Assert.IsTrue(point1.Select(g => g.STEquals(point3)).First()); var pointNoSrId = db.STGeomFromText("POINT(-71.064544 42.28787)"); Assert.AreEqual(0, pointNoSrId.SRID); } }
public void TestSTSegmentize() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string InputWkt = "LINESTRING(0 0, 100 0)"; const string Expected = "LINESTRING(0 0,50 0,100 0)"; Assert.AreEqual( Expected, db.Select(() => GeometryEditors.STSegmentize(GeometryInput.STGeomFromText(InputWkt), 50).STAsText())); Assert.AreEqual( Expected, db.Select(() => GeometryEditors.STSegmentize(InputWkt, 50).STAsText())); Assert.IsNull(db.Select(() => GeometryEditors.STSegmentize((NTSG)null, 0))); } }
public void TestSTRemoveRepeatedPoints() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string Wkt = "LINESTRING(0 5, 0 0, 0 0, 0 10)"; db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt)) .Insert(); var result = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STRemoveRepeatedPoints(1).AsText()) .Single(); Assert.AreEqual("LINESTRING (0 5, 0 0, 0 10)", result); Assert.IsNull(db.Select(() => GeometryEditors.STRemoveRepeatedPoints((NTSG)null, 0))); } }
public void TestSTMulti() { 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 multiGeom = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STMulti()) .Single(); Assert.IsInstanceOf <NTSGS.MultiLineString>(multiGeom); var multiLine = multiGeom as NTSGS.MultiLineString; Assert.AreEqual(1, multiLine.NumGeometries); var line = multiLine.GetGeometryN(0); Assert.AreEqual(25, line.Coordinates[0].X); Assert.AreEqual(50, line.Coordinates[0].Y); Assert.AreEqual(100, line.Coordinates[1].X); Assert.AreEqual(125, line.Coordinates[1].Y); Assert.AreEqual(150, line.Coordinates[2].X); Assert.AreEqual(190, line.Coordinates[2].Y); Assert.IsNull(db.Select(() => GeometryEditors.STMulti((NTSG)null))); Assert.AreEqual( "MULTIPOLYGON(((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416)))", db.Select(() => GeometryEditors.STMulti("POLYGON((743238 2967416,743238 2967450,743265 2967450, 743265.625 2967416, 743238 2967416))").STAsText())); } }
public void TestSTLineMerge() { const string Wkt = "MULTILINESTRING M ((1 2 3, 9 4 3),(9 4 3, 5 4 5))"; using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Wkt)) .Insert(); var mergedGeom = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STLineMerge()) .Single(); Assert.IsInstanceOf <NTSGS.LineString>(mergedGeom); Assert.AreEqual(3, mergedGeom.NumPoints); var mergedLine = mergedGeom as NTSGS.LineString; Assert.AreEqual(1, mergedLine.GetCoordinateN(0).X); Assert.AreEqual(2, mergedLine.GetCoordinateN(0).Y); Assert.AreEqual(double.NaN, mergedLine.GetCoordinateN(0).M); Assert.AreEqual(9, mergedLine.GetCoordinateN(1).X); Assert.AreEqual(4, mergedLine.GetCoordinateN(1).Y); Assert.AreEqual(double.NaN, mergedLine.GetCoordinateN(1).M); Assert.AreEqual(5, mergedLine.GetCoordinateN(2).X); Assert.AreEqual(4, mergedLine.GetCoordinateN(2).Y); Assert.AreEqual(double.NaN, mergedLine.GetCoordinateN(2).M); Assert.IsNull(db.Select(() => GeometryEditors.STLineMerge((NTSG)null))); Assert.AreEqual( "LINESTRING(-29 -27,-30 -29.7,-36 -31,-45 -33,-46 -32)", db.Select(() => GeometryEditors.STLineMerge("MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))").STAsText())); } }
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))); } }
public void TestSTLineToCurve() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string Wkt = "POINT(1 3)"; db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt).STBuffer(3.0)) .Insert(); // NTS error: 'Geometry type not recognized. GeometryCode: 10' var curvePolygon = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STLineToCurve().STAsText()) .Single(); Assert.AreEqual("CURVEPOLYGON(CIRCULARSTRING(4 3,-2 2.99999999999999,4 3))", curvePolygon); Assert.IsNull(db.Select(() => GeometryEditors.STLineToCurve((NTSG)null))); } }
public void TestSTSetPoint() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryInput.STGeomFromText("LINESTRING(-1 2,-1 3)")) .Insert(); db.TestGeometries .Where(g => g.Id == 1) .Set(g => g.Geometry, g => g.Geometry.STSetPoint(0, GeometryInput.STGeomFromText("POINT(-1 1)"))) .Update(); var result = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STAsText()) .Single(); Assert.AreEqual("LINESTRING(-1 1,-1 3)", result); Assert.IsNull(db.Select(() => GeometryEditors.STSetPoint((NTSG)null, 0, null))); } }
public void TestSTAddPointWithPosition() { const string Wkt = "LINESTRING(0 0 1, 0 0 3)"; 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.STAddPoint(GeometryConstructors.STMakePoint(0, 0, 2), 1)) .Single() as NTSGS.LineString; Assert.AreEqual(3, result.NumPoints); var point1 = result.Coordinates[0]; Assert.AreEqual(0, point1.X); Assert.AreEqual(0, point1.Y); Assert.AreEqual(1, point1.Z); var point2 = result.Coordinates[1]; Assert.AreEqual(0, point2.X); Assert.AreEqual(0, point2.Y); Assert.AreEqual(2, point2.Z); var point3 = result.Coordinates[2]; Assert.AreEqual(0, point3.X); Assert.AreEqual(0, point3.Y); Assert.AreEqual(3, point3.Z); Assert.IsNull(db.Select(() => GeometryEditors.STAddPoint(null, null, 0))); } }