Skip to content

Commit fb76d44

Browse files
committed
Implemented most Geometry Input methods from Well-Known Binary format
1 parent c1590de commit fb76d44

File tree

3 files changed

+211
-3
lines changed

3 files changed

+211
-3
lines changed

LinqToDBPostGisNetTopologySuite.Tests/GeometryInputTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,52 @@ public void TestSTGeomFromText()
4747
}
4848
}
4949

50+
[Test]
51+
public void TestGeometryFromWKB()
52+
{
53+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
54+
{
55+
const string wkt1 = "POINT(2 5)";
56+
const string wkt2 = "LINESTRING(2 5,2 6)";
57+
var wkb1 = db.Select(() => GeometryInput.STGeomFromText(wkt1).STAsBinary());
58+
var wkb2 = db.Select(() => GeometryInput.STGeomFromText(wkt2).STAsBinary());
59+
60+
Assert.AreEqual(wkt1, db.Select(() => GeometryInput.STWKBToSQL(wkb1).STAsText()));
61+
Assert.AreEqual(wkt1, db.Select(() => GeometryInput.STGeomFromWKB(wkb1).STAsText()));
62+
Assert.AreEqual(wkt1, db.Select(() => GeometryInput.STPointFromWKB(wkb1).STAsText()));
63+
64+
Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STGeomFromWKB(wkb1, SRID3857).STSrId()));
65+
Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STPointFromWKB(wkb1, SRID3857).STSrId()));
66+
67+
Assert.AreEqual(wkt2, db.Select(() => GeometryInput.STGeomFromWKB(wkb2).STAsText()));
68+
Assert.AreEqual(wkt2, db.Select(() => GeometryInput.STLineFromWKB(wkb2).STAsText()));
69+
Assert.AreEqual(wkt2, db.Select(() => GeometryInput.STLinestringFromWKB(wkb2).STAsText()));
70+
71+
Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STGeomFromWKB(wkb2, SRID3857).STSrId()));
72+
Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STLineFromWKB(wkb2, SRID3857).STSrId()));
73+
Assert.AreEqual(SRID3857, db.Select(() => GeometryInput.STLinestringFromWKB(wkb2, SRID3857).STSrId()));
74+
75+
Assert.IsNull(db.Select(() => GeometryInput.STGeomFromEWKB(null)));
76+
}
77+
}
78+
79+
[Test]
80+
public void TestGeometryFromEWKB()
81+
{
82+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
83+
{
84+
const string ewkt1 = "SRID=4269;LINESTRING(-71.16028 42.258729,-71.160837 42.259112,-71.161143 42.25932)";
85+
var ewkb1 = db.Select(() => GeometryInput.STGeomFromEWKT(ewkt1).STAsEWKB());
86+
87+
var g = db.Select(() => GeometryInput.STGeomFromEWKB(ewkb1));
88+
89+
Assert.AreEqual(ewkt1, db.Select(() => GeometryInput.STGeomFromEWKB(ewkb1).STAsEWKT()));
90+
Assert.AreEqual(ewkt1, db.Select(() => GeometryInput.STGeomFromEWKB(ewkb1).STAsEWKT()));
91+
92+
Assert.IsNull(db.Select(() => GeometryInput.STGeomFromEWKB(null)));
93+
}
94+
}
95+
5096
[Test]
5197
public void TestSTGeomFromGeoHash()
5298
{

LinqToDBPostGisNetTopologySuite/GeometryInput.cs

Lines changed: 150 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,155 @@ public static NTSG STGeomFromText(string wkt, int srid)
5959
throw new InvalidOperationException();
6060
}
6161

62-
// TODO: Implement 8.8.2. Well-Known Binary (WKB)
62+
#region 8.8.2. Well-Known Binary (WKB)
63+
64+
// TODO: geography ST_GeogFromWKB(bytea wkb);
65+
66+
/// <summary>
67+
/// Constructs geometry from Extended Well-Known Binary (EWKB) representation.
68+
/// </summary>
69+
/// <remarks>
70+
/// See https://postgis.net/docs/manual-3.0/ST_GeomFromEWKB.html
71+
/// </remarks>
72+
/// <param name="ewkb">Extended Well-Known Binary (EWKB)</param>
73+
/// <returns>Geometry</returns>
74+
[Sql.Function("ST_GeomFromEWKB", ServerSideOnly = true)]
75+
public static NTSG STGeomFromEWKB(byte[] ewkb)
76+
{
77+
throw new InvalidOperationException();
78+
}
79+
80+
/// <summary>
81+
/// Constructs geometry from Well-Known Binary (WKB) representation.
82+
/// </summary>
83+
/// <remarks>
84+
/// See https://postgis.net/docs/manual-3.0/ST_GeomFromWKB.html
85+
/// </remarks>
86+
/// <param name="wkb">Well-Known Binary (WKB)</param>
87+
/// <returns>Geometry</returns>
88+
[Sql.Function("ST_GeomFromWKB", ServerSideOnly = true)]
89+
public static NTSG STGeomFromWKB(byte[] wkb)
90+
{
91+
throw new InvalidOperationException();
92+
}
93+
94+
/// <summary>
95+
/// Constructs geometry from Well-Known Binary (WKB) representation with given SRID.
96+
/// </summary>
97+
/// <remarks>
98+
/// See https://postgis.net/docs/manual-3.0/ST_GeomFromWKB.html
99+
/// </remarks>
100+
/// <param name="wkb">Well-Known Binary (WKB)</param>
101+
/// <param name="srid">Spatial Reference System Identifier for geometry</param>
102+
/// <returns>Geometry</returns>
103+
[Sql.Function("ST_GeomFromWKB", ServerSideOnly = true)]
104+
public static NTSG STGeomFromWKB(byte[] wkb, int srid)
105+
{
106+
throw new InvalidOperationException();
107+
}
108+
109+
/// <summary>
110+
/// Constructs geometry (LINESTRING) from Well-Known Binary (WKB) representation.
111+
/// </summary>
112+
/// <remarks>
113+
/// See https://postgis.net/docs/manual-3.0/ST_LineFromWKB.html
114+
/// </remarks>
115+
/// <param name="wkb">Well-Known Binary (WKB)</param>
116+
/// <returns>Geometry (LINESTRING)</returns>
117+
[Sql.Function("ST_LineFromWKB", ServerSideOnly = true)]
118+
public static NTSG STLineFromWKB(byte[] wkb)
119+
{
120+
throw new InvalidOperationException();
121+
}
122+
123+
/// <summary>
124+
/// Constructs geometry (LINESTRING) from Well-Known Binary (WKB) representation with given SRID.
125+
/// </summary>
126+
/// <remarks>
127+
/// See https://postgis.net/docs/manual-3.0/ST_LineFromWKB.html
128+
/// </remarks>
129+
/// <param name="wkb">Well-Known Binary (WKB)</param>
130+
/// <param name="srid">Spatial Reference System Identifier for geometry</param>
131+
/// <returns>Geometry (LINESTRING)</returns>
132+
[Sql.Function("ST_LineFromWKB", ServerSideOnly = true)]
133+
public static NTSG STLineFromWKB(byte[] wkb, int srid)
134+
{
135+
throw new InvalidOperationException();
136+
}
137+
138+
/// <summary>
139+
/// Constructs geometry (LINESTRING) from Well-Known Binary (WKB) representation.
140+
/// </summary>
141+
/// <remarks>
142+
/// See https://postgis.net/docs/manual-3.0/ST_LinestringFromWKB.html
143+
/// </remarks>
144+
/// <param name="wkb">Well-Known Binary (WKB)</param>
145+
/// <returns>Geometry (LINESTRING)</returns>
146+
[Sql.Function("ST_LinestringFromWKB", ServerSideOnly = true)]
147+
public static NTSG STLinestringFromWKB(byte[] wkbd)
148+
{
149+
throw new InvalidOperationException();
150+
}
151+
152+
/// <summary>
153+
/// Constructs geometry (LINESTRING) from Well-Known Binary (WKB) representation with given SRID.
154+
/// </summary>
155+
/// <remarks>
156+
/// See https://postgis.net/docs/manual-3.0/ST_LinestringFromWKB.html
157+
/// </remarks>
158+
/// <param name="wkb">Well-Known Binary (WKB)</param>
159+
/// <param name="srid">Spatial Reference System Identifier for geometry</param>
160+
/// <returns>Geometry (LINESTRING)</returns>
161+
[Sql.Function("ST_LinestringFromWKB", ServerSideOnly = true)]
162+
public static NTSG STLinestringFromWKB(byte[] wkb, int srid)
163+
{
164+
throw new InvalidOperationException();
165+
}
166+
167+
/// <summary>
168+
/// Constructs geometry (POINT) from Well-Known Binary (WKB) representation.
169+
/// </summary>
170+
/// <remarks>
171+
/// See https://postgis.net/docs/manual-3.0/ST_PointFromWKB.html
172+
/// </remarks>
173+
/// <param name="wkb">Well-Known Binary (WKB)</param>
174+
/// <returns>Geometry (POINT)</returns>
175+
[Sql.Function("ST_PointFromWKB", ServerSideOnly = true)]
176+
public static NTSG STPointFromWKB(byte[] wkb)
177+
{
178+
throw new InvalidOperationException();
179+
}
180+
181+
/// <summary>
182+
/// Constructs geometry (POINT) from Well-Known Binary (WKB) representation with given SRID.
183+
/// </summary>
184+
/// <remarks>
185+
/// See https://postgis.net/docs/manual-3.0/ST_PointFromWKB.html
186+
/// </remarks>
187+
/// <param name="wkb">Well-Known Binary (WKB)</param>
188+
/// <param name="srid">Spatial Reference System Identifier for geometry</param>
189+
/// <returns>Geometry (POINT)</returns>
190+
[Sql.Function("ST_PointFromWKB", ServerSideOnly = true)]
191+
public static NTSG STPointFromWKB(byte[] wkb, int srid)
192+
{
193+
throw new InvalidOperationException();
194+
}
195+
196+
/// <summary>
197+
/// Constructs geometry from Well-Known Binary (WKB) representation.
198+
/// </summary>
199+
/// <remarks>
200+
/// See https://postgis.net/docs/manual-3.0/ST_WKBToSQL.html
201+
/// </remarks>
202+
/// <param name="wkb">Well-Known Binary (WKB)</param>
203+
/// <returns>Geometry</returns>
204+
[Sql.Function("ST_WKBToSQL", ServerSideOnly = true)]
205+
public static NTSG STWKBToSQL(byte[] wkb)
206+
{
207+
throw new InvalidOperationException();
208+
}
209+
210+
#endregion
63211

64212
#region 8.8.3. Other Formats
65213

@@ -159,7 +307,7 @@ public static NTSG STGeomFromKML(string kml)
159307
/// <remarks>
160308
/// See https://postgis.net/docs/manual-3.0/ST_GeomFromTWKB.html
161309
/// </remarks>
162-
/// <param name="twkb">Tiny Well-Known Binary (TWKB)</param>
310+
/// <param name="ewkb">Tiny Well-Known Binary (TWKB)</param>
163311
/// <returns>Geometry</returns>
164312
[Sql.Function("ST_GeomFromTWKB", ServerSideOnly = true)]
165313
public static NTSG STGeomFromTWKB(byte[] twkb)

LinqToDBPostGisNetTopologySuite/GeometryOutput.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static string STAsText(this NTSG geometry)
4343
}
4444

4545
/// <summary>
46-
/// Returns the Well-Known Binary representation of the geometry.
46+
/// Returns the Well-Known Binary (WKB) representation of the geometry.
4747
/// </summary>
4848
/// <remarks>
4949
/// See https://postgis.net/docs/manual-3.0/ST_AsBinary.html
@@ -56,6 +56,20 @@ public static byte[] STAsBinary(this NTSG geometry) // TODO: NDR_or_XDR version
5656
throw new InvalidOperationException();
5757
}
5858

59+
/// <summary>
60+
/// Returns the Extended Well-Known Binary (EWKB) representation of the geometry.
61+
/// </summary>
62+
/// <remarks>
63+
/// See https://postgis.net/docs/manual-3.0/ST_AsEWKB.html
64+
/// </remarks>
65+
/// <param name="geometry">Input geometry</param>
66+
/// <returns>Extended Well-Known Binary</returns>
67+
[Sql.Function("ST_AsEWKB", ServerSideOnly = true)]
68+
public static byte[] STAsEWKB(this NTSG geometry) // TODO: NDR_or_XDR version
69+
{
70+
throw new InvalidOperationException();
71+
}
72+
5973
/// <summary>
6074
/// Returns geometry as GeoJSON "geometry" object.
6175
/// </summary>

0 commit comments

Comments
 (0)