Skip to content

Commit 3fa2162

Browse files
Handle ordinates for empty IGeometryCollection (npgsql#2258)
See: npgsql/efcore.pg/pull/732
1 parent 4080780 commit 3fa2162

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Npgsql.NetTopologySuite/NpgsqlPostGisWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ private static Ordinates CheckOrdinates(IGeometry geometry)
508508
return CheckOrdinates(((ILineString)geometry).CoordinateSequence);
509509
if (geometry is IPolygon)
510510
return CheckOrdinates((((IPolygon)geometry).ExteriorRing).CoordinateSequence);
511-
if (geometry is IGeometryCollection)
512-
return CheckOrdinates(geometry.GetGeometryN(0));
511+
if (geometry is IGeometryCollection collection)
512+
return collection.Count == 0 ? Ordinates.None : CheckOrdinates(collection.GetGeometryN(0));
513513

514514
Assert.ShouldNeverReachHere();
515515
return Ordinates.None;

test/Npgsql.PluginTests/NetTopologySuiteTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ public static IEnumerable TestCases {
149149
"st_multi(st_makepolygon(st_makeline(ARRAY[st_makepoint(1,1),st_makepoint(2,2),st_makepoint(3,3),st_makepoint(1,1)])))"
150150
);
151151

152+
yield return new TestCaseData(
153+
Ordinates.None,
154+
GeometryCollection.Empty,
155+
"st_geomfromtext('GEOMETRYCOLLECTION EMPTY')"
156+
);
157+
152158
yield return new TestCaseData(
153159
Ordinates.None,
154160
new GeometryCollection(new IGeometry[]

0 commit comments

Comments
 (0)