Skip to content

Commit 36bb127

Browse files
Added methods of PostGIS 3.2
1 parent 9e429ef commit 36bb127

File tree

4 files changed

+317
-0
lines changed

4 files changed

+317
-0
lines changed

LinqToDBPostGisNetTopologySuite.Tests/GeometryConstructorsTests.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,105 @@ public void TestSTPoint()
296296
}
297297
}
298298

299+
[Test]
300+
public void TestSTPointZ()
301+
{
302+
if (CurrentVersion < new Version("3.2.0")) return;
303+
304+
const double X = 1;
305+
const double Y = 2;
306+
const double Z = 3;
307+
const int Srid = 4326;
308+
309+
NTSG res1;
310+
NTSG res2;
311+
312+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
313+
{
314+
res1 = db.Select(() => GeometryConstructors.STPointZ(X, Y, Z, Srid));
315+
res2 = db.Select(() => GeometryConstructors.STPointZ(X, Y, Z));
316+
}
317+
318+
Assert.IsNotNull(res1);
319+
Assert.AreEqual(X, res1.Coordinates[0].X);
320+
Assert.AreEqual(Y, res1.Coordinates[0].Y);
321+
Assert.AreEqual(Z, res1.Coordinates[0].Z);
322+
Assert.AreEqual(Srid, res1.SRID);
323+
324+
Assert.IsNotNull(res2);
325+
Assert.AreEqual(X, res2.Coordinates[0].X);
326+
Assert.AreEqual(Y, res2.Coordinates[0].Y);
327+
Assert.AreEqual(Z, res2.Coordinates[0].Z);
328+
Assert.AreEqual(-1, res2.SRID);
329+
}
330+
331+
[Test]
332+
public void TestSTPointM()
333+
{
334+
if (CurrentVersion < Version320) return;
335+
336+
const double X = 4;
337+
const double Y = 5;
338+
const double M = 6;
339+
const int Srid = 4326;
340+
341+
NTSG res1;
342+
NTSG res2;
343+
344+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
345+
{
346+
res1 = db.Select(() => GeometryConstructors.STPointM(X, Y, M, Srid));
347+
res2 = db.Select(() => GeometryConstructors.STPointM(X, Y, M));
348+
}
349+
350+
Assert.IsNotNull(res1);
351+
Assert.AreEqual(X, res1.Coordinates[0].X);
352+
Assert.AreEqual(Y, res1.Coordinates[0].Y);
353+
Assert.AreEqual(M, res1.Coordinates[0].M);
354+
Assert.AreEqual(Srid, res1.SRID);
355+
356+
Assert.IsNotNull(res2);
357+
Assert.AreEqual(X, res2.Coordinates[0].X);
358+
Assert.AreEqual(Y, res2.Coordinates[0].Y);
359+
Assert.AreEqual(M, res2.Coordinates[0].M);
360+
Assert.AreEqual(-1, res2.SRID);
361+
}
362+
363+
[Test]
364+
public void TestSTPointZM()
365+
{
366+
if (CurrentVersion < Version320) return;
367+
368+
const double X = 23.0;
369+
const double Y = 41.1;
370+
const double Z = 2.1;
371+
const double M = 1;
372+
const int Srid = 4326;
373+
374+
NTSG res1;
375+
NTSG res2;
376+
377+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
378+
{
379+
res1 = db.Select(() => GeometryConstructors.STPointZM(X, Y, Z, M, Srid));
380+
res2 = db.Select(() => GeometryConstructors.STPointZM(X, Y, Z, M));
381+
}
382+
383+
Assert.IsNotNull(res1);
384+
Assert.AreEqual(X, res1.Coordinates[0].X);
385+
Assert.AreEqual(Y, res1.Coordinates[0].Y);
386+
Assert.AreEqual(Z, res1.Coordinates[0].Z);
387+
Assert.AreEqual(M, res1.Coordinates[0].M);
388+
Assert.AreEqual(Srid, res1.SRID);
389+
390+
Assert.IsNotNull(res2);
391+
Assert.AreEqual(X, res2.Coordinates[0].X);
392+
Assert.AreEqual(Y, res2.Coordinates[0].Y);
393+
Assert.AreEqual(Z, res2.Coordinates[0].Z);
394+
Assert.AreEqual(M, res2.Coordinates[0].M);
395+
Assert.AreEqual(-1, res2.SRID);
396+
}
397+
299398
[Test]
300399
public void TestSTPolygon()
301400
{

LinqToDBPostGisNetTopologySuite.Tests/GeometryEditorsTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ namespace LinqToDBPostGisNetTopologySuite.Tests
1212
[TestFixture]
1313
class GeometryEditorsTests : TestsBase
1414
{
15+
private Version CurrentVersion { get; set; }
16+
1517
[SetUp]
1618
public void Setup()
1719
{
1820
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
1921
{
2022
db.TestGeometries.Delete();
2123
db.TestGeographies.Delete();
24+
CurrentVersion = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
2225
}
2326
}
2427

@@ -191,6 +194,54 @@ public void TestSTCurveToLine()
191194
}
192195
}
193196

197+
[Test]
198+
public void TestSTScroll()
199+
{
200+
if (CurrentVersion < Version320) return;
201+
202+
const string RingText = "SRID=4326;LINESTRING(0 1,2 3,4 5,6 7,0 1)";
203+
const string PointText = "SRID=4326;POINT(6 7)";
204+
205+
const double X = 6;
206+
const double Y = 7;
207+
208+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
209+
{
210+
var result1 = db.Select(() => GeometryEditors.STScroll(GeometryInput.STGeomFromEWKT(RingText),
211+
GeometryInput.STGeomFromEWKT(PointText)));
212+
var result2 = db.Select(() =>
213+
GeometryEditors.STScroll(GeometryInput.STGeomFromEWKT(RingText), PointText));
214+
var result3 = db.Select(() =>
215+
GeometryEditors.STScroll(RingText, GeometryInput.STGeomFromEWKT(PointText)));
216+
var result4 = db.Select(() => GeometryEditors.STScroll(RingText, PointText));
217+
218+
Assert.IsNotNull(result1);
219+
Assert.IsNotNull(result2);
220+
Assert.IsNotNull(result3);
221+
Assert.IsNotNull(result4);
222+
223+
var startPoint1 = result1.Coordinates[0];
224+
var startPoint2 = result2.Coordinates[0];
225+
var startPoint3 = result3.Coordinates[0];
226+
var startPoint4 = result4.Coordinates[0];
227+
228+
var endPoint1 = result1.Coordinates.Last();
229+
var endPoint2 = result2.Coordinates.Last();
230+
var endPoint3 = result3.Coordinates.Last();
231+
var endPoint4 = result4.Coordinates.Last();
232+
233+
Assert.AreEqual(X, startPoint1.X);
234+
Assert.AreEqual(X, startPoint2.X);
235+
Assert.AreEqual(X, startPoint3.X);
236+
Assert.AreEqual(X, startPoint4.X);
237+
238+
Assert.AreEqual(Y, endPoint1.Y);
239+
Assert.AreEqual(Y, endPoint2.Y);
240+
Assert.AreEqual(Y, endPoint3.Y);
241+
Assert.AreEqual(Y, endPoint4.Y);
242+
}
243+
}
244+
194245
[Test]
195246
public void TestSTFlipCoordinates()
196247
{

LinqToDBPostGisNetTopologySuite/GeometryConstructors.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,113 @@ public static class GeometryConstructors
202202
[Sql.Function("ST_Point", ServerSideOnly = true)]
203203
public static NTSG STPoint(double x, double y) => throw new InvalidOperationException();
204204

205+
/// <summary>
206+
/// Returns an Point with the given X, Y and Z coordinate values
207+
/// </summary>
208+
/// <remarks>
209+
/// See https://postgis.net/docs/ST_PointZ.html
210+
/// </remarks>
211+
/// <seealso cref="STMakePoint(double, double, double)" />
212+
/// <param name="x">X</param>
213+
/// <param name="y">Y</param>
214+
/// <param name="z">Z</param>
215+
/// <returns>Geometry (3D Point with z).</returns>
216+
[Sql.Function("ST_PointZ", ServerSideOnly = true)]
217+
public static NTSG STPointZ(double x, double y, double z)
218+
{
219+
throw new InvalidOperationException();
220+
}
221+
222+
/// <summary>
223+
/// Returns an Point with the given X, Y and Z coordinate values, and an SRID number.
224+
/// </summary>
225+
/// <remarks>
226+
/// See https://postgis.net/docs/ST_PointZ.html
227+
/// </remarks>
228+
/// <seealso cref="STMakePoint(double, double, double)" />
229+
/// <param name="x">X</param>
230+
/// <param name="y">Y</param>
231+
/// <param name="z">Z</param>
232+
/// <param name="srid">SRID</param>
233+
/// <returns>Geometry (3D Point with z).</returns>
234+
[Sql.Function("ST_PointZ", ServerSideOnly = true)]
235+
public static NTSG STPointZ(double x, double y, double z, int srid)
236+
{
237+
throw new InvalidOperationException();
238+
}
239+
240+
/// <summary>
241+
/// Returns an Point with the given X, Y and M coordinate values
242+
/// </summary>
243+
/// <remarks>
244+
/// See https://postgis.net/docs/ST_PointM.html
245+
/// </remarks>
246+
/// <seealso cref="STMakePointM(double, double, double)" />
247+
/// <param name="x">X</param>
248+
/// <param name="y">Y</param>
249+
/// <param name="m">M</param>
250+
/// <returns>Geometry (3D Point with m).</returns>
251+
[Sql.Function("ST_PointM", ServerSideOnly = true)]
252+
public static NTSG STPointM(double x, double y, double m)
253+
{
254+
throw new InvalidOperationException();
255+
}
256+
257+
/// <summary>
258+
/// Returns an Point with the given X, Y and M coordinate values, and an SRID number.
259+
/// </summary>
260+
/// <remarks>
261+
/// See https://postgis.net/docs/ST_PointM.html
262+
/// </remarks>
263+
/// <seealso cref="STMakePointM(double, double, double)" />
264+
/// <param name="x">X</param>
265+
/// <param name="y">Y</param>
266+
/// <param name="m">M</param>
267+
/// <param name="srid">SRID</param>
268+
/// <returns>Geometry (3D Point with m).</returns>
269+
[Sql.Function("ST_PointM", ServerSideOnly = true)]
270+
public static NTSG STPointM(double x, double y, double m, int srid)
271+
{
272+
throw new InvalidOperationException();
273+
}
274+
275+
/// <summary>
276+
/// Returns an Point with the given X, Y, Z and M coordinate values.
277+
/// </summary>
278+
/// <remarks>
279+
/// See https://postgis.net/docs/ST_PointZM.html
280+
/// </remarks>
281+
/// <see cref="STMakePoint(double, double, double, double)"/>
282+
/// <param name="x">X</param>
283+
/// <param name="y">Y</param>
284+
/// <param name="z">Z</param>
285+
/// <param name="m">M</param>
286+
/// <returns>Geometry (4D Point with z and m).</returns>
287+
[Sql.Function("ST_PointZM", ServerSideOnly = true)]
288+
public static NTSG STPointZM(double x, double y, double z, double m)
289+
{
290+
throw new InvalidOperationException();
291+
}
292+
293+
/// <summary>
294+
/// Returns an Point with the given X, Y, Z and M coordinate values, and optionally an SRID number.
295+
/// </summary>
296+
/// <remarks>
297+
/// See https://postgis.net/docs/ST_PointZM.html
298+
/// </remarks>
299+
/// <see cref="STMakePoint(double, double, double, double)"/>
300+
/// <param name="x">X</param>
301+
/// <param name="y">Y</param>
302+
/// <param name="z">Z</param>
303+
/// <param name="m">M</param>
304+
/// <param name="srid">SRID</param>
305+
/// <returns>Geometry (4D Point with z and m).</returns>
306+
[Sql.Function("ST_PointZM", ServerSideOnly = true)]
307+
public static NTSG STPointZM(double x, double y, double z, double m, int srid)
308+
{
309+
throw new InvalidOperationException();
310+
}
311+
205312
/// <summary>
206313
/// Creates a Polygon geometry from input LineString geometry.
207314
/// </summary>

LinqToDBPostGisNetTopologySuite/GeometryEditors.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,66 @@ public static class GeometryEditors
8989
[Sql.Function("ST_CurveToLine", ServerSideOnly = true)]
9090
public static NTSG STCurveToLine(this NTSG geometry, double tolerance, int toleranceType, int flags) => throw new InvalidOperationException();// TODO: enums for arguments
9191

92+
/// <summary>
93+
/// Changes the start/end point of a closed LineString to the given vertex point.
94+
/// </summary>
95+
/// <remarks>
96+
/// See https://postgis.net/docs/ST_Scroll.html
97+
/// </remarks>
98+
/// <param name="geometry">Input geometry.</param>
99+
/// <param name="point">Input given vertex point.</param>
100+
/// <returns>Geometry</returns>
101+
[Sql.Function("ST_Scroll", ServerSideOnly = true)]
102+
public static NTSG STScroll(this NTSG geometry, NTSG point)
103+
{
104+
throw new InvalidOperationException();
105+
}
106+
107+
/// <summary>
108+
/// Changes the start/end point of a closed LineString to the given vertex point.
109+
/// </summary>
110+
/// <remarks>
111+
/// See https://postgis.net/docs/ST_Scroll.html
112+
/// </remarks>
113+
/// <param name="geometry">Input geometry.</param>
114+
/// <param name="point">Input given vertex point.</param>
115+
/// <returns>Geometry</returns>
116+
[Sql.Function("ST_Scroll", ServerSideOnly = true)]
117+
public static NTSG STScroll(this NTSG geometry, string point)
118+
{
119+
throw new InvalidOperationException();
120+
}
121+
122+
/// <summary>
123+
/// Changes the start/end point of a closed LineString to the given vertex point.
124+
/// </summary>
125+
/// <remarks>
126+
/// See https://postgis.net/docs/ST_Scroll.html
127+
/// </remarks>
128+
/// <param name="geometry">Input geometry.</param>
129+
/// <param name="point">Input given vertex point.</param>
130+
/// <returns>Geometry</returns>
131+
[Sql.Function("ST_Scroll", ServerSideOnly = true)]
132+
public static NTSG STScroll(string geometry, NTSG point)
133+
{
134+
throw new InvalidOperationException();
135+
}
136+
137+
/// <summary>
138+
/// Changes the start/end point of a closed LineString to the given vertex point.
139+
/// </summary>
140+
/// <remarks>
141+
/// See https://postgis.net/docs/ST_Scroll.html
142+
/// </remarks>
143+
/// <param name="geometry">Input geometry.</param>
144+
/// <param name="point">Input given vertex point.</param>
145+
/// <returns>Geometry</returns>
146+
[Sql.Function("ST_Scroll", ServerSideOnly = true)]
147+
public static NTSG STScroll(string geometry, string point)
148+
{
149+
throw new InvalidOperationException();
150+
}
151+
92152
/// <summary>
93153
/// Returns geometry with with flipped X and Y axis of input <paramref name="geometry"/>.
94154
/// </summary>

0 commit comments

Comments
 (0)