public void TestSTMakeEnvelope() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STMakeEnvelope(10, 10, 11, 11, SRID4326)) .Insert(); Assert.AreEqual( "SRID=4326;POLYGON((10 10,10 11,11 11,11 10,10 10))", db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STAsEWKT()) .Single()); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STMakeEnvelope(10, 10, 11, 11)) .Insert(); Assert.AreEqual( "POLYGON((10 10,10 11,11 11,11 10,10 10))", db.TestGeometries .Where(g => g.Id == 2) .Select(g => g.Geometry.STAsEWKT()) .Single()); } }
public void TestSTClipByBox2D() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { var geom1 = db.Select(() => GeometryInput.STGeomFromText("LINESTRING(0 0, 20 20)")); var box1 = db.Select(() => GeometryConstructors.STMakeEnvelope(0, 0, 10, 10)); var clipped1 = db.Select(() => GeometryProcessing.STClipByBox2D(geom1, box1).STAsText()); Assert.AreEqual("LINESTRING(0 0,10 10)", clipped1); Assert.IsNull(db.Select(() => GeometryProcessing.STClipByBox2D(null, null))); } }
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); } } }