Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use NtsGeometryServices instance for geometry creation #5048

Merged
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/GeoJsonResolvers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ public IReadOnlyCollection<double> GetBbox([Parent] Geometry geometry)
}

public int GetCrs([Parent] Geometry geometry) =>
geometry.SRID == 0 ? 4326 : geometry.SRID;
geometry.SRID is 0 or -1 ? 4326 : geometry.SRID;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ public override LineString CreateGeometry(
throw Serializer_Parse_CoordinatesIsInvalid(type);
}

if (crs is not null)
{
GeometryFactory factory =
NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return factory.CreateLineString(coords);
}
GeometryFactory factory = crs is null
? NtsGeometryServices.Instance.CreateGeometryFactory()
: NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return new LineString(coords);
return factory.CreateLineString(coords);
}

public override object CreateInstance(IType type, object?[] fieldValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,11 @@ public override MultiLineString CreateGeometry(
.CreateGeometry(type, parts[i], crs);
}

if (crs is not null)
{
GeometryFactory factory =
NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return factory.CreateMultiLineString(geometries);
}
GeometryFactory factory = crs is null
? NtsGeometryServices.Instance.CreateGeometryFactory()
: NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return new MultiLineString(geometries);
return factory.CreateMultiLineString(geometries);
}

public override object CreateInstance(IType type, object?[] fieldValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@ public override MultiPoint CreateGeometry(
goto Error;

Success:
if (crs is not null)
{
GeometryFactory factory =
NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);
return factory.CreateMultiPoint(geometries);
}

return new MultiPoint(geometries);
GeometryFactory factory = crs is null
? NtsGeometryServices.Instance.CreateGeometryFactory()
: NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return factory.CreateMultiPoint(geometries);

Error:
throw Serializer_Parse_CoordinatesIsInvalid(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ public override MultiPolygon CreateGeometry(
goto Error;

Success:
if (crs is not null)
{
GeometryFactory factory =
NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return factory.CreateMultiPolygon(geometries);
}
GeometryFactory factory = crs is null
? NtsGeometryServices.Instance.CreateGeometryFactory()
: NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return new MultiPolygon(geometries);
return factory.CreateMultiPolygon(geometries);

Error:
throw Serializer_Parse_CoordinatesIsInvalid(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ public override Point CreateGeometry(
throw Serializer_Parse_CoordinatesIsInvalid(type);
}

if (crs is not null)
{
GeometryFactory factory =
NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return factory.CreatePoint(coordinate);
}
GeometryFactory factory = crs is null
? NtsGeometryServices.Instance.CreateGeometryFactory()
: NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return new Point(coordinate);
return factory.CreatePoint(coordinate);
}

public override object CreateInstance(IType type, object?[] fieldValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,22 @@ public override Polygon CreateGeometry(
throw Serializer_Parse_CoordinatesIsInvalid(type);
}

if (crs is not null)
{
GeometryFactory factory =
NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

LinearRing ringSrid = factory.CreateLinearRing((Coordinate[])ringsCoordinates[0]);
LinearRing[] holes = Array.Empty<LinearRing>();
if (ringsCoordinates.Length > 1)
{
holes = new LinearRing[ringsCoordinates.Length - 1];
for (var i = 0; i < ringsCoordinates.Length - 1; i++)
{
holes[i] = factory.CreateLinearRing((Coordinate[])ringsCoordinates[i + 1]);
}
}
GeometryFactory factory = crs is null
? NtsGeometryServices.Instance.CreateGeometryFactory()
: NtsGeometryServices.Instance.CreateGeometryFactory(crs.Value);

return factory.CreatePolygon(ringSrid, holes);
}
else
LinearRing ringSrid = factory.CreateLinearRing((Coordinate[])ringsCoordinates[0]);
LinearRing[] holes = Array.Empty<LinearRing>();
if (ringsCoordinates.Length > 1)
{
var ring = new LinearRing((Coordinate[])ringsCoordinates[0]);
LinearRing[] holes = Array.Empty<LinearRing>();
if (ringsCoordinates.Length > 1)
holes = new LinearRing[ringsCoordinates.Length - 1];
for (var i = 0; i < ringsCoordinates.Length - 1; i++)
{
holes = new LinearRing[ringsCoordinates.Length - 1];
for (var i = 0; i < ringsCoordinates.Length - 1; i++)
{
holes[i] = new LinearRing((Coordinate[])ringsCoordinates[i + 1]);
}
holes[i] = factory.CreateLinearRing((Coordinate[])ringsCoordinates[i + 1]);
}

return new Polygon(ring, holes);
}

return factory.CreatePolygon(ringSrid, holes);
}

public override object CreateInstance(IType type, object?[] fieldValues)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Squadron;
using Xunit;

namespace HotChocolate.Data.Filters.Spatial;

[CollectionDefinition("Postgres")]
public class PostgreSqlFixture : ICollectionFixture<PostgreSqlResource<PostgisConfig>>
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace HotChocolate.Data.Filters.Spatial;

[Collection("Postgres")]
public class QueryableFilterVisitorContainsTests
: SchemaCache
, IClassFixture<PostgreSqlResource<PostgisConfig>>
{
private static readonly Polygon _truePolygon = new Polygon(
new LinearRing(new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace HotChocolate.Data.Filters.Spatial;

[Collection("Postgres")]
public class QueryableFilterVisitorDistanceTests
: SchemaCache
, IClassFixture<PostgreSqlResource<PostgisConfig>>
{
private static readonly Polygon _truePolygon = new Polygon(
new LinearRing(new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace HotChocolate.Data.Filters.Spatial;

[Collection("Postgres")]
public class QueryableFilterVisitorIntersectsTests
: SchemaCache
, IClassFixture<PostgreSqlResource<PostgisConfig>>
{
private static readonly Polygon _truePolygon =
new Polygon(new LinearRing(new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace HotChocolate.Data.Filters.Spatial;

[Collection("Postgres")]
public class QueryableFilterVisitorOverlapsTests
: SchemaCache
, IClassFixture<PostgreSqlResource<PostgisConfig>>
{
private static readonly Polygon _truePolygon =
new Polygon(new LinearRing(new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace HotChocolate.Data.Filters.Spatial;

[Collection("Postgres")]
public class QueryableFilterVisitorTouchesTests
: SchemaCache
, IClassFixture<PostgreSqlResource<PostgisConfig>>
{
private static readonly Polygon _truePolygon =
new Polygon(new LinearRing(new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace HotChocolate.Data.Filters.Spatial;

[Collection("Postgres")]
public class QueryableFilterVisitorWithinTests
: SchemaCache
, IClassFixture<PostgreSqlResource<PostgisConfig>>
{
private static readonly Polygon _truePolygon =
new Polygon(new LinearRing(new[]
Expand Down