diff --git a/src/HotChocolate/Spatial/src/Types/GeoJsonPolygonType.cs b/src/HotChocolate/Spatial/src/Types/GeoJsonPolygonType.cs index b6821ce16bc..c40fe49c5f7 100644 --- a/src/HotChocolate/Spatial/src/Types/GeoJsonPolygonType.cs +++ b/src/HotChocolate/Spatial/src/Types/GeoJsonPolygonType.cs @@ -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; diff --git a/src/HotChocolate/Spatial/test/Types.Tests/GeoJsonPolygonTypeTests.cs b/src/HotChocolate/Spatial/test/Types.Tests/GeoJsonPolygonTypeTests.cs index 4b153ece511..9c907ff5fc3 100644 --- a/src/HotChocolate/Spatial/test/Types.Tests/GeoJsonPolygonTypeTests.cs +++ b/src/HotChocolate/Spatial/test/Types.Tests/GeoJsonPolygonTypeTests.cs @@ -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() + .BindRuntimeType() + .AddType() + .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() { diff --git a/src/HotChocolate/Spatial/test/Types.Tests/__snapshots__/GeoJsonPolygonTypeTests.GetCoordinates_Should_ReturnExteriorRingFirst_When_PolygonHasHoles.snap b/src/HotChocolate/Spatial/test/Types.Tests/__snapshots__/GeoJsonPolygonTypeTests.GetCoordinates_Should_ReturnExteriorRingFirst_When_PolygonHasHoles.snap new file mode 100644 index 00000000000..9c66f67df04 --- /dev/null +++ b/src/HotChocolate/Spatial/test/Types.Tests/__snapshots__/GeoJsonPolygonTypeTests.GetCoordinates_Should_ReturnExteriorRingFirst_When_PolygonHasHoles.snap @@ -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 + } + } +}