Skip to content

Commit 3bf6af5

Browse files
committed
Overall code cleanup; Nuget package version is now 0.1
1 parent f794ac0 commit 3bf6af5

19 files changed

+773
-411
lines changed

LinqToDBPostGisNetTopologySuite.Tests/GeometryAccessorsTests.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using NTSGS = NetTopologySuite.Geometries;
77
using NTSG = NetTopologySuite.Geometries.Geometry;
8+
using System;
89

910
namespace LinqToDBPostGisNetTopologySuite.Tests
1011
{
@@ -560,19 +561,26 @@ public void TestSTIsEmpty()
560561
{
561562
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
562563
{
563-
const string wkt1 = "GEOMETRYCOLLECTION EMPTY";
564-
db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt1)).Insert();
565-
const string wkt2 = "POLYGON((1 2, 3 4, 5 6, 1 2))";
566-
db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt2)).Insert();
564+
const string Wkt1 = "GEOMETRYCOLLECTION EMPTY";
565+
db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();
566+
567+
const string Wkt2 = "POLYGON((1 2, 3 4, 5 6, 1 2))";
568+
db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)).Insert();
567569
db.TestGeometries.Value(g => g.Id, 3).Value(g => g.Geometry, () => null).Insert();
568570

569571
Assert.IsTrue(db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STIsEmpty()).Single());
570572
Assert.IsFalse(db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STIsEmpty()).Single());
571573
Assert.IsNull(db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STIsEmpty()).Single());
572574

573-
Assert.IsNull(db.Select(() => GeometryAccessors.STIsEmpty((NTSG)null)));
574-
Assert.IsTrue(db.Select(() => GeometryAccessors.STIsEmpty("CIRCULARSTRING EMPTY")));
575-
Assert.IsFalse(db.Select(() => GeometryAccessors.STIsEmpty("POINT(0 0)")));
575+
// TODO: Need some research for reason of error:
576+
// function st_isempty(unknown) is not unique. Could not choose a best candidate function. You might need to add explicit type casts.
577+
var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
578+
if (version > new Version("3.0.0"))
579+
{
580+
Assert.IsNull(db.Select(() => GeometryAccessors.STIsEmpty((NTSG)null)));
581+
Assert.IsTrue(db.Select(() => GeometryAccessors.STIsEmpty("CIRCULARSTRING EMPTY")));
582+
Assert.IsFalse(db.Select(() => GeometryAccessors.STIsEmpty("POINT(0 0)")));
583+
}
576584
}
577585
}
578586

LinqToDBPostGisNetTopologySuite.Tests/GeometryConstructorsTests.cs

Lines changed: 114 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23

34
using LinqToDB;
45
using NUnit.Framework;
@@ -304,34 +305,40 @@ public void TestSTPolygon()
304305
.Value(g => g.Geometry, () => GeometryConstructors.STPolygon(GeometryInput.STGeomFromText(Wkt1), SRID4326))
305306
.Insert();
306307

307-
db.TestGeometries
308-
.Value(g => g.Id, 2)
309-
.Value(g => g.Geometry, () => GeometryConstructors.STPolygon(GeometryInput.STGeomFromText(Wkt2), SRID4326))
310-
.Insert();
311-
312-
db.TestGeometries
313-
.Value(g => g.Id, 3)
314-
.Value(g => g.Geometry, () => GeometryConstructors.STPolygon(Wkt1, SRID4326))
315-
.Insert();
316-
317308
Assert.AreEqual(
318309
"POLYGON((75 29,77 29,77 29,75 29))",
319310
db.TestGeometries.Where(g => g.Id == 1)
320311
.Select(g => g.Geometry.STAsText())
321312
.Single());
322313

314+
db.TestGeometries
315+
.Value(g => g.Id, 2)
316+
.Value(g => g.Geometry, () => GeometryConstructors.STPolygon(GeometryInput.STGeomFromText(Wkt2), SRID4326))
317+
.Insert();
318+
319+
323320
Assert.AreEqual(
324321
"SRID=4326;POLYGON((75 29 1,77 29 2,77 29 3,75 29 1))",
325322
db.TestGeometries
326323
.Where(g => g.Id == 2)
327324
.Select(g => g.Geometry.STAsEWKT())
328325
.Single());
329326

330-
Assert.AreEqual(
331-
"POLYGON((75 29,77 29,77 29,75 29))",
332-
db.TestGeometries.Where(g => g.Id == 3)
333-
.Select(g => g.Geometry.STAsText())
334-
.Single());
327+
// TODO: ? reason of error? ST_Polygon(text) not works in 2.5 ?
328+
var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
329+
if (version >= new Version("3.0.0"))
330+
{
331+
db.TestGeometries
332+
.Value(g => g.Id, 3)
333+
.Value(g => g.Geometry, () => GeometryConstructors.STPolygon(Wkt1, SRID4326))
334+
.Insert();
335+
336+
Assert.AreEqual(
337+
"POLYGON((75 29,77 29,77 29,75 29))",
338+
db.TestGeometries.Where(g => g.Id == 3)
339+
.Select(g => g.Geometry.STAsText())
340+
.Single());
341+
}
335342
}
336343
}
337344

@@ -340,54 +347,100 @@ public void TestSTTileEnvelope()
340347
{
341348
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
342349
{
343-
db.TestGeometries
344-
.Value(g => g.Id, 1)
345-
.Value(g => g.Geometry, () => GeometryConstructors.STTileEnvelope(2, 1, 1))
346-
.Insert();
350+
var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
351+
if (version >= new Version("3.0.0"))
352+
{
353+
db.TestGeometries
354+
.Value(g => g.Id, 1)
355+
.Value(g => g.Geometry, () => GeometryConstructors.STTileEnvelope(2, 1, 1))
356+
.Insert();
347357

348-
db.TestGeometries
349-
.Value(g => g.Id, 2)
350-
.Value(g => g.Geometry, () => GeometryConstructors.STTileEnvelope(3, 1, 1, GeometryConstructors.STMakeEnvelope(-180, -90, 180, 90, SRID4326)))
351-
.Insert();
358+
db.TestGeometries
359+
.Value(g => g.Id, 2)
360+
.Value(g => g.Geometry, () => GeometryConstructors.STTileEnvelope(3, 1, 1, GeometryConstructors.STMakeEnvelope(-180, -90, 180, 90, SRID4326)))
361+
.Insert();
352362

353-
db.TestGeometries
354-
.Value(g => g.Id, 3)
355-
.Value(g => g.Geometry, () => GeometryConstructors.STTileEnvelope(2, 1, 1, "SRID=3857;LINESTRING(-20037508.342789 -20037508.342789,20037508.342789 20037508.342789)"))
356-
.Insert();
363+
db.TestGeometries
364+
.Value(g => g.Id, 3)
365+
.Value(g => g.Geometry, () => GeometryConstructors.STTileEnvelope(2, 1, 1, "SRID=3857;LINESTRING(-20037508.342789 -20037508.342789,20037508.342789 20037508.342789)"))
366+
.Insert();
367+
368+
var result1 = db.TestGeometries.Where(g => g.Id == 1);
369+
var poly1 = result1.Select(g => g.Geometry).Single() as NTSGS.Polygon;
370+
Assert.AreEqual(-10018754.1713945, poly1.Coordinates[0].X, 1.0E-6);
371+
Assert.AreEqual(0, poly1.Coordinates[0].Y, 1.0E-6);
372+
Assert.AreEqual(-10018754.1713945, poly1.Coordinates[1].X, 1.0E-6);
373+
Assert.AreEqual(10018754.1713945, poly1.Coordinates[1].Y, 1.0E-6);
374+
Assert.AreEqual(0, poly1.Coordinates[2].X, 1.0E-6);
375+
Assert.AreEqual(10018754.1713945, poly1.Coordinates[2].Y, 1.0E-6);
376+
Assert.AreEqual(0, poly1.Coordinates[3].X, 1.0E-6);
377+
Assert.AreEqual(0, poly1.Coordinates[3].Y, 1.0E-6);
378+
Assert.AreEqual(-10018754.1713945, poly1.Coordinates[4].X, 1.0E-6);
379+
Assert.AreEqual(0, poly1.Coordinates[4].Y, 1.0E-6);
380+
Assert.AreEqual(SRID3857, poly1.SRID);
381+
382+
var result2 = db.TestGeometries.Where(g => g.Id == 2);
383+
Assert.AreEqual("POLYGON((-135 45,-135 67.5,-90 67.5,-90 45,-135 45))",
384+
result2.Select(g => g.Geometry.STAsText()).Single());
385+
Assert.AreEqual(SRID4326,
386+
result2.Select(g => g.Geometry.STSrId()).Single());
387+
388+
var result3 = db.TestGeometries.Where(g => g.Id == 3);
389+
var poly3 = result3.Select(g => g.Geometry).Single() as NTSGS.Polygon;
390+
Assert.AreEqual(-10018754.1713945, poly3.Coordinates[0].X, 1.0E-6);
391+
Assert.AreEqual(0, poly3.Coordinates[0].Y, 1.0E-6);
392+
Assert.AreEqual(-10018754.1713945, poly3.Coordinates[1].X, 1.0E-6);
393+
Assert.AreEqual(10018754.1713945, poly3.Coordinates[1].Y, 1.0E-6);
394+
Assert.AreEqual(0, poly3.Coordinates[2].X, 1.0E-6);
395+
Assert.AreEqual(10018754.1713945, poly3.Coordinates[2].Y, 1.0E-6);
396+
Assert.AreEqual(0, poly3.Coordinates[3].X, 1.0E-6);
397+
Assert.AreEqual(0, poly3.Coordinates[3].Y, 1.0E-6);
398+
Assert.AreEqual(-10018754.1713945, poly3.Coordinates[4].X, 1.0E-6);
399+
Assert.AreEqual(0, poly3.Coordinates[4].Y, 1.0E-6);
400+
Assert.AreEqual(SRID3857, poly3.SRID);
401+
}
402+
}
403+
}
357404

358-
var result1 = db.TestGeometries.Where(g => g.Id == 1);
359-
var poly1 = result1.Select(g => g.Geometry).Single() as NTSGS.Polygon;
360-
Assert.AreEqual(-10018754.1713945, poly1.Coordinates[0].X, 1.0E-6);
361-
Assert.AreEqual(0, poly1.Coordinates[0].Y, 1.0E-6);
362-
Assert.AreEqual(-10018754.1713945, poly1.Coordinates[1].X, 1.0E-6);
363-
Assert.AreEqual(10018754.1713945, poly1.Coordinates[1].Y, 1.0E-6);
364-
Assert.AreEqual(0, poly1.Coordinates[2].X, 1.0E-6);
365-
Assert.AreEqual(10018754.1713945, poly1.Coordinates[2].Y, 1.0E-6);
366-
Assert.AreEqual(0, poly1.Coordinates[3].X, 1.0E-6);
367-
Assert.AreEqual(0, poly1.Coordinates[3].Y, 1.0E-6);
368-
Assert.AreEqual(-10018754.1713945, poly1.Coordinates[4].X, 1.0E-6);
369-
Assert.AreEqual(0, poly1.Coordinates[4].Y, 1.0E-6);
370-
Assert.AreEqual(SRID3857, poly1.SRID);
371-
372-
var result2 = db.TestGeometries.Where(g => g.Id == 2);
373-
Assert.AreEqual("POLYGON((-135 45,-135 67.5,-90 67.5,-90 45,-135 45))",
374-
result2.Select(g => g.Geometry.STAsText()).Single());
375-
Assert.AreEqual(SRID4326,
376-
result2.Select(g => g.Geometry.STSrId()).Single());
377-
378-
var result3 = db.TestGeometries.Where(g => g.Id == 3);
379-
var poly3 = result3.Select(g => g.Geometry).Single() as NTSGS.Polygon;
380-
Assert.AreEqual(-10018754.1713945, poly3.Coordinates[0].X, 1.0E-6);
381-
Assert.AreEqual(0, poly3.Coordinates[0].Y, 1.0E-6);
382-
Assert.AreEqual(-10018754.1713945, poly3.Coordinates[1].X, 1.0E-6);
383-
Assert.AreEqual(10018754.1713945, poly3.Coordinates[1].Y, 1.0E-6);
384-
Assert.AreEqual(0, poly3.Coordinates[2].X, 1.0E-6);
385-
Assert.AreEqual(10018754.1713945, poly3.Coordinates[2].Y, 1.0E-6);
386-
Assert.AreEqual(0, poly3.Coordinates[3].X, 1.0E-6);
387-
Assert.AreEqual(0, poly3.Coordinates[3].Y, 1.0E-6);
388-
Assert.AreEqual(-10018754.1713945, poly3.Coordinates[4].X, 1.0E-6);
389-
Assert.AreEqual(0, poly3.Coordinates[4].Y, 1.0E-6);
390-
Assert.AreEqual(SRID3857, poly3.SRID);
405+
[Test]
406+
public void TestSTHexagon()
407+
{
408+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
409+
{
410+
var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
411+
if (version >= new Version("3.1.0"))
412+
{
413+
var origin = db.Select(() => GeometryConstructors.STMakePoint(0, 0));
414+
415+
var hexagon1 = db.Select(() => GeometryConstructors.STHexagon(1.0, 0, 0, origin)) as NTSGS.Polygon;
416+
Assert.IsNotNull(hexagon1);
417+
Assert.AreEqual(7, hexagon1.Coordinates.Length);
418+
419+
var hexagon2 = db.Select(() => GeometryConstructors.STHexagon(1.0, 0, 0)) as NTSGS.Polygon;
420+
Assert.IsNotNull(hexagon2);
421+
Assert.AreEqual(7, hexagon2.Coordinates.Length);
422+
}
423+
}
424+
}
425+
426+
[Test]
427+
public void TestSTSquare()
428+
{
429+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
430+
{
431+
var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
432+
if (version >= new Version("3.1.0"))
433+
{
434+
var origin = db.Select(() => GeometryConstructors.STMakePoint(0, 0));
435+
436+
var square1 = db.Select(() => GeometryConstructors.STSquare(1.0, 0, 0, origin)) as NTSGS.Polygon;
437+
Assert.IsNotNull(square1);
438+
Assert.AreEqual(5, square1.Coordinates.Length);
439+
440+
var square2 = db.Select(() => GeometryConstructors.STSquare(1.0, 0, 0)) as NTSGS.Polygon;
441+
Assert.IsNotNull(square2);
442+
Assert.AreEqual(5, square2.Coordinates.Length);
443+
}
391444
}
392445
}
393446
}

LinqToDBPostGisNetTopologySuite.Tests/GeometryEditorsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,11 +887,11 @@ public void TestSTShiftLongitude()
887887
const string Ewkt2 = "SRID=4326;POINT(241.42 38.38 10)";
888888
db.TestGeometries
889889
.Value(g => g.Id, 1)
890-
.Value(p => p.Geometry, () => GeometryInput.STGeomFromEWKT(Ewkt1))
890+
.Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Ewkt1))
891891
.Insert();
892892
db.TestGeometries
893893
.Value(g => g.Id, 2)
894-
.Value(p => p.Geometry, () => GeometryInput.STGeomFromEWKT(Ewkt2))
894+
.Value(g => g.Geometry, () => GeometryInput.STGeomFromEWKT(Ewkt2))
895895
.Insert();
896896

897897
var result1 = db.TestGeometries

0 commit comments

Comments
 (0)