Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/HotChocolate/Spatial/src/Types/GeoJsonPolygonType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Coordinate[][] GetCoordinates([Parent] Polygon polygon)

for (var i = 0; i < polygon.InteriorRings.Length; i++)
{
coordinates[i] = polygon.InteriorRings[i].Coordinates;
coordinates[i + 1] = polygon.InteriorRings[i].Coordinates;
}

return coordinates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,60 @@ public class GeoJsonPolygonTypeTests
new Coordinate(30, 10)
]));

[Fact]
public async Task GetCoordinates_Should_ReturnExteriorRingFirst_When_PolygonHasHoles()
{
// arrange
var polygon = new Polygon(
new LinearRing(
[
new Coordinate(0, 0),
new Coordinate(40, 0),
new Coordinate(40, 40),
new Coordinate(0, 40),
new Coordinate(0, 0)
]),
[
new LinearRing(
[
new Coordinate(5, 5),
new Coordinate(15, 5),
new Coordinate(15, 15),
new Coordinate(5, 15),
new Coordinate(5, 5)
]),
new LinearRing(
[
new Coordinate(20, 20),
new Coordinate(30, 20),
new Coordinate(30, 30),
new Coordinate(20, 30),
new Coordinate(20, 20)
])
]);

var schema = SchemaBuilder.New()
.AddConvention<INamingConventions, MockNamingConvention>()
.BindRuntimeType<Coordinate, GeoJsonPositionType>()
.AddType<GeoJsonPolygonType>()
.AddQueryType(
d => d
.Name("Query")
.Field("test")
.Resolve(polygon))
.Create();

var executor = schema.MakeExecutable();

// act
var result = await executor.ExecuteAsync(
"{ test { type coordinates bbox crs }}",
TestContext.Current.CancellationToken);

// assert
result.MatchSnapshot();
}

[Fact]
public async Task Polygon_Execution_Output()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"data": {
"test": {
"type": "Polygon",
"coordinates": [
[
[
0,
0
],
[
40,
0
],
[
40,
40
],
[
0,
40
],
[
0,
0
]
],
[
[
5,
5
],
[
15,
5
],
[
15,
15
],
[
5,
15
],
[
5,
5
]
],
[
[
20,
20
],
[
30,
20
],
[
30,
30
],
[
20,
30
],
[
20,
20
]
]
],
"bbox": [
0,
0,
40,
40
],
"crs": 4326
}
}
}
Loading