public void TestST3DIntersects() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string Line1 = "LINESTRING(0 0 1, 0 0 2, 0 0 3)"; const string Line2 = "LINESTRING(0 0 1, 0 0 4, 0 0 5)"; const string Line3 = "LINESTRING(0 0 1, 0 0 2, 0 0 3)"; const string Line4 = "LINESTRING(9 9 0, 9 9 1, 9 9 2)"; var result1 = db.Select(() => GeometryInput.STGeomFromText(Line1).ST3DIntersects(GeometryInput.STGeomFromText(Line2))); var result2 = db.Select(() => GeometryInput.STGeomFromText(Line3).ST3DIntersects(GeometryInput.STGeomFromText(Line4))); var result3 = db.Select(() => SpatialRelationships.ST3DIntersects((NTSG)null, (NTSG)null)); Assert.IsNotNull(result1); Assert.IsNotNull(result2); Assert.IsNull(result3); Assert.IsTrue(result1); Assert.IsFalse(result2); var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion())); if (version >= new Version("3.0.0")) { Assert.IsTrue( db.Select(() => SpatialRelationships.ST3DIntersects( "TIN(((0 0 0,1 0 0,0 1 0,0 0 0)))", "POINT(.1 .1 0)"))); } } }
public void TestST3DLineInterpolatePoint() { const string Wkt = "LINESTRING(25 50 70, 100 125 90, 150 190 200)"; 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, () => GeometryInput.STGeomFromEWKT(Wkt)) .Insert(); var result = db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.ST3DLineInterpolatePoint(0.20)) .Single() as NTSGS.Point; Assert.AreEqual(59.0675892910822, result.X, 1.0E-8); Assert.AreEqual(84.0675892910822, result.Y, 1.0E-8); Assert.AreEqual(79.0846904776219, result.Z, 1.0E-8); Assert.IsNull(db.Select(() => LinearReferencing.ST3DLineInterpolatePoint((NTSG)null, 0.5))); var result2 = db.Select(() => LinearReferencing.ST3DLineInterpolatePoint(Wkt, 0.20)) as NTSGS.Point; Assert.AreEqual(59.0675892910822, result2.X, 1.0E-8); Assert.AreEqual(84.0675892910822, result2.Y, 1.0E-8); Assert.AreEqual(79.0846904776219, result2.Z, 1.0E-8); } } }
public void TestSTGeneratePoints() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion())); if (version >= new Version("3.0.0")) { // TODO: Test for 2.3.0 var geom1 = db.Select(() => GeometryInput.STGeomFromText("POLYGON((175 150, 20 40, 50 60, 125 100, 175 150))")); var result1 = db.Select(() => GeometryProcessing.STGeneratePoints(geom1, 5, 1)) as NTSGS.MultiPoint; var expected = new double[][] { new[] { 139.29283354478, 118.602516148805 }, new[] { 131.832615216622, 108.222468996999 }, new[] { 114.403606086077, 103.400350731553 }, new[] { 61.1688280123262, 67.8262881638229 }, new[] { 136.491955979797, 111.749696268158 }, }; Assert.AreEqual(expected.Length, result1.Coordinates.Length); for (var i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i][0], result1.Coordinates[i].X, 1.0E-9); Assert.AreEqual(expected[i][1], result1.Coordinates[i].Y, 1.0E-9); } Assert.IsNull(db.Select(() => GeometryProcessing.STGeneratePoints(null, 1))); } } }
/// <summary> /// Routine which checks if the compiler is supported by NAnt. /// </summary> /// <returns> /// <see langword="true" /> if the version of the compiler is at /// least <c>13.xx.xxxx</c>; otherwise, <see langword="false" />. /// </returns> private static bool CheckSupportedCompiler() { StringCollection compilers = GetCompilersOnPath(); foreach (string compiler in compilers) { // get major version of compiler int majorVersion = VersionFunctions.GetMajor( FileVersionInfoFunctions.GetProductVersion( FileVersionInfo.GetVersionInfo(compiler))); // the MS compiler supports Managed Extensions starting from // product version 7 (VS.NET 2002) if (majorVersion < 7) { // stop at first compiler that does not meet the required // version, as we're not sure which entry in the PATH the // <cl> task will use return(false); } } // if we made it here, and at least one compiler was on the PATH // then we know its a supported compiler return(compilers.Count > 0); }
public void TestSTIsEmpty() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string Wkt1 = "GEOMETRYCOLLECTION EMPTY"; db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert(); const string Wkt2 = "POLYGON((1 2, 3 4, 5 6, 1 2))"; db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)).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.STIsEmpty()).Single()); Assert.IsFalse(db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STIsEmpty()).Single()); Assert.IsNull(db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STIsEmpty()).Single()); // TODO: Need some research for reason of error: // function st_isempty(unknown) is not unique. Could not choose a best candidate function. You might need to add explicit type casts. var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion())); if (version > new Version("3.0.0")) { Assert.IsNull(db.Select(() => GeometryAccessors.STIsEmpty((NTSG)null))); Assert.IsTrue(db.Select(() => GeometryAccessors.STIsEmpty("CIRCULARSTRING EMPTY"))); Assert.IsFalse(db.Select(() => GeometryAccessors.STIsEmpty("POINT(0 0)"))); } } }
public void TryParseVersionInText_ValidMarker() { var success = VersionFunctions.TryParseVersionInText("foo 1.0", @"(?<marker>foo) (?<version>1.0)", out var _, out var marker); Assert.IsTrue(success); Assert.AreEqual("foo", marker); }
public void TryParseVersionInText_InvalidRegexWithoutNamedGroup() { var success = VersionFunctions.TryParseVersionInText("100", @"\d", out var version, out var marker); Assert.IsFalse(success); Assert.IsNull(version); Assert.IsTrue(string.IsNullOrEmpty(marker)); }
public void TryParseVersionInText_Found() { var success = VersionFunctions.TryParseVersionInText("a1.2a", @"a(?<version>\d\.\d)a", out var version, out var marker); Assert.IsTrue(success); Assert.AreEqual("1.2", version.ToString()); Assert.IsTrue(string.IsNullOrEmpty(marker)); }
public void Increment_IncrementDifferentPositions(int position, string originalVersionText, string expectedVersionText, bool cascade) { var version = VersionFunctions.ParseVersion(originalVersionText); var newVersion = VersionFunctions.Increment(version, position, cascade); Assert.AreEqual(expectedVersionText, newVersion.ToString()); }
public void TryParseVersionInText_ValidRegexButTextIsNoVersion() { var success = VersionFunctions.TryParseVersionInText("something", @"a(?<version>\d\.\d)a", out var version, out var marker); Assert.IsFalse(success); Assert.IsNull(version); Assert.IsTrue(string.IsNullOrEmpty(marker)); }
public void Assign_AssignPositions(int position, string originalVersionText, string expectedVersionText, string formattedNumber) { var version = VersionFunctions.ParseVersion(originalVersionText); var newVersion = VersionFunctions.Assign(version, position, formattedNumber); Assert.AreEqual(expectedVersionText, newVersion.ToString()); }
public void Label_ChangeLabel(string originalVersionText, string expectedVersionText, string versionLabel) { var version = VersionFunctions.ParseVersion(originalVersionText); var newVersion = VersionFunctions.Label(version, versionLabel); Assert.AreEqual(expectedVersionText, newVersion.ToString()); }
public void Assign_InvalidArgument() { var version = VersionFunctions.ParseVersion("2.2.2"); Assert.ThrowsException <ArgumentOutOfRangeException>(() => VersionFunctions.Assign(version, 0, "-1")); Assert.ThrowsException <ArgumentOutOfRangeException>(() => VersionFunctions.Assign(version, -1, "0")); Assert.ThrowsException <ArgumentException>(() => VersionFunctions.Assign(version, 1, "not a number")); }
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 Equals_SameState(string versionText) { var version = VersionFunctions.ParseVersion(versionText); var otherVersion = VersionFunctions.ParseVersion(versionText); Assert.IsTrue(version.Equals(otherVersion)); Assert.IsTrue(otherVersion.Equals(version)); Assert.AreEqual(version.GetHashCode(), otherVersion.GetHashCode()); }
public void Equals_DifferentState(string versionText) { var version = VersionFunctions.ParseVersion("1.1.1"); var otherVersion = VersionFunctions.ParseVersion(versionText); Assert.IsFalse(version.Equals(otherVersion)); Assert.IsFalse(otherVersion.Equals(version)); Assert.AreNotEqual(version.GetHashCode(), otherVersion.GetHashCode()); }
public void EnsureExpectedVersion_Ok() { var expectedText = "a1.2a"; var version = VersionFunctions.ParseVersion("1.2"); var actualText = VersionFunctions.EnsureExpectedVersion(expectedText, @"a(?<version>\d\.\d)a", version); Assert.AreEqual(expectedText, actualText); }
public void Setup() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { this.CurrentVersion = new Version(db.Select(() => VersionFunctions.PostGISLibVersion())); db.TestGeometries.Delete(); db.TestGeographies.Delete(); } }
public void TestPostGISFullVersion() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var fullVersion = db.Select(() => VersionFunctions.PostGISFullVersion()); Assert.IsNotNull(fullVersion); // Just to see in test runner output Console.WriteLine(new String('-', 40)); Console.WriteLine(fullVersion); Console.WriteLine(new String('-', 40)); var geosVersion = db.Select(() => VersionFunctions.PostGISGEOSVersion()); Console.WriteLine($"GEOS={geosVersion}"); var liblwgeomVersion = db.Select(() => VersionFunctions.PostGISLiblwgeomVersion()); Console.WriteLine($"liblwgeom={liblwgeomVersion}"); var libXmlVersion = db.Select(() => VersionFunctions.PostGISLibXMLVersion()); Console.WriteLine($"LibXML={libXmlVersion}"); var libBuildDate = db.Select(() => VersionFunctions.PostGISLibBuildDate()); Console.WriteLine($"PostGIS lib build date={libBuildDate}"); var libVersion = db.Select(() => VersionFunctions.PostGISLibVersion()); Console.WriteLine($"PostGIS lib version={libVersion}"); var projVersion = db.Select(() => VersionFunctions.PostGISPROJVersion()); Console.WriteLine($"PROJ4={projVersion}"); var currentVersion = new Version(db.Select(() => VersionFunctions.PostGISLibVersion())); if (currentVersion >= new Version("3.0")) { var wagyuVersion = db.Select(() => VersionFunctions.PostGISWagyuVersion()); Console.WriteLine($"Wagyu={wagyuVersion}"); } var scriptsBuildDate = db.Select(() => VersionFunctions.PostGISScriptsBuildDate()); Console.WriteLine($"PostGIS scripts build date={scriptsBuildDate}"); var scripts = db.Select(() => VersionFunctions.PostGISScriptsInstalled()); Console.WriteLine($"PostGIS scripts={scripts}"); var postGisVersion = db.Select(() => VersionFunctions.PostGISVersion()); Console.WriteLine($"PostGIS version={postGisVersion}"); Console.WriteLine(new String('-', 40)); } }
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 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 TestSTReducePrecision() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { // TODO: ? Some helper version classes / attributes for methods? var version = new Version(db.Select(() => VersionFunctions.PostGISLibVersion())); var geos = db.Select(() => VersionFunctions.PostGISGEOSVersion()); var geosVersion = geos != null ? new Version(geos.Substring(0, geos.IndexOf('-'))) : null; if ((version >= new Version("3.1.0")) && (geosVersion != null) && (geosVersion >= new Version("3.9"))) // TODO: ? const { const string Wkt = "POINT(1.412 19.323)"; Assert.AreEqual( "POINT(1.4 19.3)", db.Select(() => GeometryInput .STGeomFromText(Wkt) .STReducePrecision(0.1) .STAsText())); Assert.AreEqual( "POINT(1 19)", db.Select(() => GeometryInput .STGeomFromText(Wkt) .STReducePrecision(1.0) .STAsText())); Assert.AreEqual( "POINT(0 20)", db.Select(() => GeometryInput .STGeomFromText(Wkt) .STReducePrecision(10.0) .STAsText())); } } }
public void ParseVersionFromText_ValidText(string versionText) { var version = VersionFunctions.ParseVersion(versionText); Assert.AreEqual(versionText, version.ToString()); }
public void Equals_WrongType() { var version = VersionFunctions.ParseVersion("1.1.1"); Assert.IsFalse(version.Equals(null)); }
public void ParseVersionFromText_InvalidText() { Assert.ThrowsException <ArgumentException>(() => VersionFunctions.ParseVersion("invalid.input")); }
public void Increment_InvalidArgument() { var version = VersionFunctions.ParseVersion("2.2.2.2"); Assert.ThrowsException <ArgumentOutOfRangeException>(() => VersionFunctions.Increment(version, -1, true)); }
public void TryParseVersionInText_InvalidRegexWithNamedGroup() { Assert.ThrowsException <ArgumentException>(() => VersionFunctions.TryParseVersionInText("1.0//", @"(?<version>1.0//)", out _, out _)); }
public void EnsureExpectedVersion_WrongRegex() { var version = VersionFunctions.ParseVersion("1.2"); Assert.ThrowsException <InvalidOperationException>(() => VersionFunctions.EnsureExpectedVersion("1.2", "wrong regex", version)); }
public void EnsureExpectedVersion_WrongText() { var version = VersionFunctions.ParseVersion("1.2"); Assert.ThrowsException <InvalidOperationException>(() => VersionFunctions.EnsureExpectedVersion("not a number", @"(?<version>\d\.\d)", version)); }
public void ToString_ReturnsVersionString(string versionText) { var version = VersionFunctions.ParseVersion(versionText); Assert.AreEqual(versionText, version.ToString()); }