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

spatial transformations #2904

Merged
merged 20 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: round results fo ci/di
  • Loading branch information
PascalSenn committed Jan 21, 2021
commit d215b5161d81455b42d3182cd22d8a310e5ee9b0
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using HotChocolate.Configuration;
using HotChocolate.Execution;
using HotChocolate.Types.Descriptors.Definitions;
using NetTopologySuite;
using NetTopologySuite.Geometries;
using Snapshooter.Xunit;
Expand All @@ -24,7 +27,7 @@ public void Execute_UnknownDefaultCRS()
.AddSpatialTypes(x => x
.DefaultSrid(4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.AddSpatialTypes();
.TryAddTypeInterceptor<RoundTypeIntercetor>();

// act
Exception? ex = Record.Exception(() => builder.Create());
Expand All @@ -42,7 +45,7 @@ public async Task Execute_InputUnknownCRS_RaiseException()
.AddSpatialTypes(x => x
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326))
.AddSpatialTypes()
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -90,8 +93,8 @@ type Query {
.AddSpatialTypes(x => x
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326))
.AddSpatialTypes()
.AddResolver("Query", "test", _ => lineString)
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -136,8 +139,8 @@ type Query {
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.AddSpatialTypes()
.AddResolver("Query", "test", _ => lineString)
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -182,8 +185,8 @@ type Query {
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.AddSpatialTypes()
.AddResolver("Query", "test", _ => lineString)
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -228,8 +231,8 @@ type Query {
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.AddSpatialTypes()
.AddResolver("Query", "test", _ => lineString)
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand All @@ -256,6 +259,7 @@ public async Task Execute_NoTransformer_NotTransformedInput()
ISchema schema = SchemaBuilder.New()
.AddQueryType<Query>()
.AddSpatialTypes()
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -290,6 +294,7 @@ public async Task Execute_CrsEqualToDefault_NotTransformArgument()
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -324,6 +329,7 @@ public async Task Execute_CrsEmpty_NotTransformArgument()
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -356,6 +362,7 @@ public async Task Execute_NoDefault_NotTransformation()
.AddSpatialTypes(x => x
.AddCoordinateSystemFromString(4326, WKT4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -385,12 +392,12 @@ public async Task Execute_CrsEmpty_TakeDefaultSrid()
{
// arrange
LineString lineString = new LineString(new[]
{
new Coordinate(30, 10),
new Coordinate(10, 30),
new CoordinateZ(10, 30, 12),
new Coordinate(40, 40)
});
{
new Coordinate(30, 10),
new Coordinate(10, 30),
new CoordinateZ(10, 30, 12),
new Coordinate(40, 40)
});

ISchema schema = SchemaBuilder.New()
.AddDocumentFromString(
Expand All @@ -403,8 +410,8 @@ type Query {
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.AddSpatialTypes()
.AddResolver("Query", "test", _ => lineString)
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -433,6 +440,7 @@ public async Task Execute_Transformer_TransformedArgument()
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -467,6 +475,7 @@ public async Task Execute_Transformer_TransformArgumentAndBack()
.DefaultSrid(4326)
.AddCoordinateSystemFromString(4326, WKT4326)
.AddCoordinateSystemFromString(26918, WKT26918))
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -516,8 +525,8 @@ type Query {
.DefaultSrid(4326)
.AddCoordinateSystemFromString(26918, WKT26918)
.AddCoordinateSystemFromString(4326, WKT4326))
.AddSpatialTypes()
.AddResolver("Query", "test", _ => lineString)
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -561,8 +570,8 @@ type Query {
.DefaultSrid(4326)
.AddCoordinateSystemFromString(26918, WKT26918)
.AddCoordinateSystemFromString(4326, WKT4326))
.AddSpatialTypes()
.AddResolver("Query", "test", _ => lineString)
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -592,6 +601,7 @@ public async Task Execute_Transformer_RegisterWithExtensions()
.DefaultSrid(4326)
.AddWebMercator()
.AddWGS84())
.TryAddTypeInterceptor<RoundTypeIntercetor>()
.Create();

IRequestExecutor executor = schema.MakeExecutable();
Expand Down Expand Up @@ -620,5 +630,47 @@ public class Query
{
public LineString Test(LineString arg) => arg;
}

/// <summary>
/// The transformation are different from system to system. We need to round the result
/// to make it consistent!
/// </summary>
public class RoundTypeIntercetor : TypeInterceptor
{
public override void OnBeforeCompleteType(
ITypeCompletionContext completionContext,
DefinitionBase? definition,
IDictionary<string, object?> contextData)
{
if (definition is ObjectTypeDefinition o)
{
foreach (var field in o.Fields)
{
if (field.Name is { Value: "test" })
{
field.MiddlewareComponents.Insert(0,
next => async context =>
{
await next(context);
if (context.Result is Geometry g)
{
foreach (var coordinate in g.Coordinates)
{
if (coordinate is CoordinateZ z)
{
z.Z = Math.Round(z.Z, 2);
}

coordinate.Y = Math.Round(coordinate.Y, 2);
coordinate.X = Math.Round(coordinate.X, 2);
}
}
}
);
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
"crs": 26918,
"coordinates": [
[
26351964.678446505,
12765790.89937976,
3.5686418414115906E-05
26351964.68,
12765790.9,
0
],
[
9465976.235150779,
9587069.633277256,
0.0017629992216825485
9465976.24,
9587069.63,
0
],
[
9465976.235151066,
9587069.633277215,
12.001762941479683
9465976.24,
9587069.63,
12
],
[
3311582.0166871673,
15982402.430081349,
0.003766885958611965
3311582.02,
15982402.43,
0
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
"crs": 26918,
"coordinates": [
[
26351964.678446505,
12765790.89937976,
3.5686418414115906E-05
26351964.68,
12765790.9,
0
],
[
9465976.235150779,
9587069.633277256,
0.0017629992216825485
9465976.24,
9587069.63,
0
],
[
9465976.235151066,
9587069.633277215,
12.001762941479683
9465976.24,
9587069.63,
12
],
[
3311582.0166871673,
15982402.430081349,
0.003766885958611965
3311582.02,
15982402.43,
0
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"crs": 26918,
"coordinates": [
[
26351964.678446505,
12765790.89937976
26351964.68,
12765790.9
],
[
9465976.235150779,
9587069.633277256
9465976.24,
9587069.63
],
[
3311582.0166871673,
15982402.430081349
3311582.02,
15982402.43
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"crs": 4326,
"coordinates": [
[
0.00026949458523585647,
8.983152840993817E-05
0,
0
],
[
8.983152841195215E-05,
0.00026949458522981454
0,
0
],
[
0.0003593261136478086,
0.0003593261136397527
0,
0
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"crs": 26918,
"coordinates": [
[
30.000111780129373,
9.999999999907894
30,
10
],
[
10.000111806148198,
29.999999999723588
10,
30
],
[
40.000111767381895,
39.999999999631605
40,
40
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"crs": 4326,
"coordinates": [
[
-79.4884751147621,
9.019379153235307E-05
-79.49,
0
],
[
-79.48865429478435,
0.0002705813077203874
-79.49,
0
],
[
-79.48838552483954,
0.000360775210712462
-79.49,
0
]
]
}
Expand Down