|
2 | 2 | using System.Linq; |
3 | 3 |
|
4 | 4 | using LinqToDB; |
| 5 | +using LinqToDB.Data; |
5 | 6 | using NUnit.Framework; |
6 | 7 |
|
7 | 8 | using NTSGS = NetTopologySuite.Geometries; |
@@ -72,47 +73,35 @@ public void TestSTBoundary() |
72 | 73 | { |
73 | 74 | using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) |
74 | 75 | { |
75 | | - const string wkt1 = "LINESTRING(100 150,50 60, 70 80, 160 170)"; |
76 | | - db.TestGeometries |
77 | | - .Value(g => g.Id, 1) |
78 | | - .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt1)) |
79 | | - .Insert(); |
80 | | - |
81 | | - const string wkt2 = "POLYGON ((10 130, 50 190, 110 190, 140 150, 150 80, 100 10, 20 40, 10 130), (70 40, 100 50, 120 80, 80 110, 50 90, 70 40))"; |
82 | | - db.TestGeometries |
83 | | - .Value(g => g.Id, 2) |
84 | | - .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt2)) |
85 | | - .Insert(); |
86 | | - |
87 | | - const string wkt3 = "MULTILINESTRING((1 1 1,0 0 0.5, -1 1 1),(1 1 0.5,0 0 0.5, -1 1 0.5, 1 1 0.5) )"; |
88 | | - db.TestGeometries |
89 | | - .Value(g => g.Id, 3) |
90 | | - .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt3)) |
91 | | - .Insert(); |
92 | | - |
93 | | - Assert.AreEqual( |
94 | | - "MULTIPOINT(100 150,160 170)", |
95 | | - db.TestGeometries |
96 | | - .Where(g => g.Id == 1) |
97 | | - .Select(g => g.Geometry.STBoundary().STAsText()) |
98 | | - .Single()); |
99 | | - |
100 | | - Assert.AreEqual( |
101 | | - "MULTILINESTRING((10 130,50 190,110 190,140 150,150 80,100 10,20 40,10 130),(70 40,100 50,120 80,80 110,50 90,70 40))", |
102 | | - db.TestGeometries |
103 | | - .Where(g => g.Id == 2) |
104 | | - .Select(g => g.Geometry.STBoundary().STAsText()) |
105 | | - .Single()); |
106 | | - |
107 | | - Assert.AreEqual( |
108 | | - "MULTIPOINT Z (-1 1 1,1 1 0.75)", |
109 | | - db.TestGeometries |
110 | | - .Where(g => g.Id == 3) |
111 | | - .Select(g => g.Geometry.STBoundary().STAsText()) |
112 | | - .Single()); |
| 76 | + const string Wkt1 = "LINESTRING(100 150,50 60, 70 80, 160 170)"; |
| 77 | + const string Wkt2 = |
| 78 | + "POLYGON ((10 130, 50 190, 110 190, 140 150, 150 80, 100 10, 20 40, 10 130), (70 40, 100 50, 120 80, 80 110, 50 90, 70 40))"; |
| 79 | + const string Wkt3 = "MULTILINESTRING((1 1 1,0 0 0.5, -1 1 1),(1 1 0.5,0 0 0.5, -1 1 0.5, 1 1 0.5) )"; |
| 80 | + |
| 81 | + const string Expected1 = "MULTIPOINT(100 150,160 170)"; |
| 82 | + const string Expected2 = |
| 83 | + "MULTILINESTRING((10 130,50 190,110 190,140 150,150 80,100 10,20 40,10 130),(70 40,100 50,120 80,80 110,50 90,70 40))"; |
| 84 | + const string Expected3V1 = "MULTIPOINT Z (-1 1 1,1 1 0.75)"; |
| 85 | + const string Expected3V2 = "MULTIPOINT Z (1 1 1,-1 1 1)"; |
| 86 | + |
| 87 | + var result1 = db.Select(() => GeometryInput.STGeomFromEWKT(Wkt1).STBoundary().STAsText()); |
| 88 | + var result2 = db.Select(() => GeometryInput.STGeomFromEWKT(Wkt2).STBoundary().STAsText()); |
| 89 | + var result3 = db.Select(() => GeometryInput.STGeomFromEWKT(Wkt3).STBoundary().STAsText()); |
| 90 | + |
| 91 | + Assert.AreEqual(Expected1, result1); |
| 92 | + Assert.AreEqual(Expected2, result2); |
| 93 | + if (CurrentVersion < |
| 94 | + new Version( |
| 95 | + "3.2.0")) //See https://postgis.net/docs/ST_Boundary.html. Result is different based on postgis version |
| 96 | + { |
| 97 | + Assert.AreEqual(Expected3V1, result3); |
| 98 | + } |
| 99 | + else |
| 100 | + { |
| 101 | + Assert.AreEqual(Expected3V2, result3); |
| 102 | + } |
113 | 103 |
|
114 | 104 | Assert.IsNull(db.Select(() => GeometryAccessors.STBoundary((NTSG)null))); |
115 | | - Assert.AreEqual("MULTIPOINT(100 150,160 170)", db.Select(() => GeometryAccessors.STBoundary(wkt1).STAsText())); |
116 | 105 | } |
117 | 106 | } |
118 | 107 |
|
@@ -355,16 +344,9 @@ public void TestSTGeometryType() |
355 | 344 | db.Select(() => GeometryInput.STGeomFromText(Wkt) |
356 | 345 | .STGeometryType())); |
357 | 346 |
|
358 | | - // TODO: Need some research for reason of error: |
359 | | - // function st_geometrytype(unknown) is not unique. Could not choose a best candidate function. You might need to add explicit type casts. |
360 | | - if (this.CurrentVersion >= new Version("3.0.0")) |
361 | | - { |
362 | | - Assert.AreEqual( |
363 | | - "ST_LineString", |
364 | | - db.Select(() => GeometryAccessors.STGeometryType(Wkt))); |
365 | | - |
366 | | - Assert.IsNull(db.Select(() => GeometryAccessors.STGeometryType((NTSG)null))); |
367 | | - } |
| 347 | + Assert.AreEqual( |
| 348 | + "ST_LineString", |
| 349 | + db.Select(() => GeometryAccessors.STGeometryType(Wkt))); |
368 | 350 | } |
369 | 351 | } |
370 | 352 |
|
@@ -923,26 +905,40 @@ public void TestSTStartPoint() |
923 | 905 | using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) |
924 | 906 | { |
925 | 907 | const string Wkt1 = "LINESTRING(0 1, 0 2)"; |
926 | | - db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert(); |
927 | | - |
928 | 908 | const string Wkt2 = "POINT(0 1)"; |
929 | | - db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)).Insert(); |
930 | 909 |
|
931 | | - Assert.AreEqual( |
932 | | - "POINT(0 1)", |
933 | | - db.TestGeometries |
934 | | - .Where(g => g.Id == 1) |
935 | | - .Select(g => g.Geometry.STStartPoint().STAsText()) |
936 | | - .Single()); |
| 910 | + const double ExpectedX = 0; |
| 911 | + const double ExpectedY = 1; |
937 | 912 |
|
938 | | - Assert.IsNull(db.TestGeometries |
939 | | - .Where(g => g.Id == 2) |
940 | | - .Select(g => g.Geometry.STStartPoint()) |
941 | | - .Single()); |
| 913 | + var actual11 = db.Select(() => GeometryInput.STGeomFromText(Wkt1).STStartPoint()); |
| 914 | + var actual12 = db.Select(() => GeometryAccessors.STStartPoint(Wkt1)); |
| 915 | + |
| 916 | + var actual2 = db.Select(() => GeometryAccessors.STStartPoint((NTSG)null)); |
| 917 | + |
| 918 | + var actual31 = db.Select(() => GeometryInput.STGeomFromText(Wkt2).STStartPoint()); |
| 919 | + var actual32 = db.Select(() => GeometryAccessors.STStartPoint(Wkt2)); |
| 920 | + |
| 921 | + |
| 922 | + Assert.AreEqual(ExpectedX, actual11.Coordinates[0].X); |
| 923 | + Assert.AreEqual(ExpectedY, actual11.Coordinates[0].Y); |
942 | 924 |
|
943 | | - Assert.AreEqual("POINT(0 1)", db.Select(() => GeometryAccessors.STStartPoint(Wkt1).STAsText())); |
944 | | - Assert.IsNull(db.Select(() => GeometryAccessors.STStartPoint(Wkt2))); |
945 | | - Assert.IsNull(db.Select(() => GeometryAccessors.STStartPoint((NTSG)null))); |
| 925 | + Assert.AreEqual(ExpectedX, actual12.Coordinates[0].X); |
| 926 | + Assert.AreEqual(ExpectedY, actual12.Coordinates[0].Y); |
| 927 | + |
| 928 | + Assert.IsNull(actual2); |
| 929 | + |
| 930 | + if (CurrentVersion < new Version("3.2.0")) |
| 931 | + { |
| 932 | + Assert.IsNull(actual31); |
| 933 | + Assert.IsNull(actual32); |
| 934 | + } |
| 935 | + else |
| 936 | + { |
| 937 | + Assert.AreEqual(ExpectedX, actual31.Coordinates[0].X); |
| 938 | + Assert.AreEqual(ExpectedY, actual31.Coordinates[0].Y); |
| 939 | + Assert.AreEqual(ExpectedX, actual32.Coordinates[0].X); |
| 940 | + Assert.AreEqual(ExpectedY, actual32.Coordinates[0].Y); |
| 941 | + } |
946 | 942 | } |
947 | 943 | } |
948 | 944 |
|
|
0 commit comments