Skip to content

Commit

Permalink
Deserialize MultiPolygon Array of Empty Coordinates Array (#140)
Browse files Browse the repository at this point in the history
* Deserialize MultiPolygon Array of Empty Coordinates Array

* Change to MultiPolygon with empty Polygon

Part of #145
  • Loading branch information
dickinsonm authored May 1, 2024
1 parent 68b0bb1 commit 76cdb7d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public static StjParsedCoordinates Parse(ref Utf8JsonReader reader, GeometryFact
reader.AssertToken(JsonTokenType.StartArray);
reader.ReadOrThrow();

if (reader.TokenType == JsonTokenType.EndArray)
{
reader.ReadOrThrow();
if (reader.TokenType == JsonTokenType.EndArray)
{
return new StjParsedCoordinates(factory.CreateMultiPolygon(new Polygon[] { factory.CreatePolygon() }));
}
}

if (reader.TokenType == JsonTokenType.Number)
{
return new StjParsedCoordinates(ParseCoordinateSequence(ref reader, factory));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ public void TestReadWithEmptyCoordinatesArray(string type)
Assert.That(geom.IsEmpty);
}

[TestCase]
public void TestMultiPolygonReadWithArrayOfEmptyCoordinatesArray()
{
string geoJson = @"{ ""type"" : ""MultiPolygon"", ""coordinates"": [ [] ] }";
var options = DefaultOptions;
var geom = Deserialize(geoJson, options);

Assert.That(geom != null);
Assert.That(new MultiPolygon(new Polygon[] { new Polygon(null) }) == geom);
Assert.That(geom.IsEmpty);
}

[GeoJsonIssueNumber(57)]
[TestCase("{\"type\": \"Point\", \"coordinates\": [], \"bbox\": null}")]
[TestCase("{\"type\": \"LineString\", \"coordinates\": [], \"bbox\": null}")]
Expand Down

0 comments on commit 76cdb7d

Please sign in to comment.