|
8 | 8 |
|
9 | 9 | namespace Nest.Resolvers.Converters.Filters |
10 | 10 | { |
11 | | - public class GeoShapeFilterJsonReader : JsonConverter |
| 11 | + public class GeoShapeFilterJsonReader : GeoShapeConverterBase |
12 | 12 | { |
13 | 13 | public override bool CanRead { get { return true; } } |
14 | 14 | public override bool CanWrite { get { return false; } } |
@@ -57,82 +57,66 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist |
57 | 57 | { |
58 | 58 | IGeoShapeCircleFilter f = new GeoShapeCircleFilterDescriptor(); |
59 | 59 | f.Shape = new CircleGeoShape(); |
| 60 | + f.Shape.Coordinates = GetCoordinates<IEnumerable<double>>(shape); |
60 | 61 | var radius = shape["radius"]; |
61 | 62 | if (radius != null) |
62 | 63 | f.Shape.Radius = radius.Value<string>(); |
63 | | - var coordinates = shape["coordinates"]; |
64 | | - if (coordinates != null) |
65 | | - f.Shape.Coordinates = coordinates.Values<double>(); |
66 | 64 | filter = f; |
67 | 65 | break; |
68 | 66 | } |
69 | 67 | else if (typeName == "envelope") |
70 | 68 | { |
71 | 69 | IGeoShapeEnvelopeFilter f = new GeoShapeEnvelopeFilterDescriptor(); |
72 | 70 | f.Shape = new EnvelopeGeoShape(); |
73 | | - var coordinates = shape["coordinates"]; |
74 | | - if (coordinates != null) |
75 | | - f.Shape.Coordinates = coordinates.Values<double[]>(); |
| 71 | + f.Shape.Coordinates = GetCoordinates<IEnumerable<IEnumerable<double>>>(shape); |
76 | 72 | filter = f; |
77 | 73 | break; |
78 | 74 | } |
79 | 75 | else if (typeName == "linestring") |
80 | 76 | { |
81 | 77 | IGeoShapeLineStringFilter f = new GeoShapeLineStringFilterDescriptor(); |
82 | 78 | f.Shape = new LineStringGeoShape(); |
83 | | - var coordinates = shape["coordinates"]; |
84 | | - if (coordinates != null) |
85 | | - f.Shape.Coordinates = coordinates.Values<double[]>(); |
| 79 | + f.Shape.Coordinates = GetCoordinates<IEnumerable<IEnumerable<double>>>(shape); |
86 | 80 | filter = f; |
87 | 81 | break; |
88 | 82 | } |
89 | 83 | else if (typeName == "multilinestring") |
90 | 84 | { |
91 | 85 | IGeoShapeMultiLineStringFilter f = new GeoShapeMultiLineStringFilterDescriptor(); |
92 | 86 | f.Shape = new MultiLineStringGeoShape(); |
93 | | - var coordinates = shape["coordinates"]; |
94 | | - if (coordinates != null) |
95 | | - f.Shape.Coordinates = coordinates.Values<double[][]>(); |
| 87 | + f.Shape.Coordinates = GetCoordinates<IEnumerable<IEnumerable<IEnumerable<double>>>>(shape); |
96 | 88 | filter = f; |
97 | 89 | break; |
98 | 90 | } |
99 | 91 | else if (typeName == "point") |
100 | 92 | { |
101 | 93 | IGeoShapePointFilter f = new GeoShapePointFilterDescriptor(); |
102 | 94 | f.Shape = new PointGeoShape(); |
103 | | - var coordinates = shape["coordinates"]; |
104 | | - if (coordinates != null) |
105 | | - f.Shape.Coordinates = coordinates.Values<double>(); |
| 95 | + f.Shape.Coordinates = GetCoordinates<IEnumerable<double>>(shape); |
106 | 96 | filter = f; |
107 | 97 | break; |
108 | 98 | } |
109 | 99 | else if (typeName == "multipoint") |
110 | 100 | { |
111 | 101 | IGeoShapeMultiPointFilter f = new GeoShapeMultiPointFilterDescriptor(); |
112 | 102 | f.Shape = new MultiPointGeoShape(); |
113 | | - var coordinates = shape["coordinates"]; |
114 | | - if (coordinates != null) |
115 | | - f.Shape.Coordinates = coordinates.Values<double[]>(); |
| 103 | + f.Shape.Coordinates = GetCoordinates<IEnumerable<IEnumerable<double>>>(shape); |
116 | 104 | filter = f; |
117 | 105 | break; |
118 | 106 | } |
119 | 107 | else if (typeName == "polygon") |
120 | 108 | { |
121 | 109 | IGeoShapePolygonFilter f = new GeoShapePolygonFilterDescriptor(); |
122 | 110 | f.Shape = new PolygonGeoShape(); |
123 | | - var coordinates = shape["coordinates"]; |
124 | | - if (coordinates != null) |
125 | | - f.Shape.Coordinates = coordinates.Values<double[][]>(); |
| 111 | + f.Shape.Coordinates = GetCoordinates<IEnumerable<IEnumerable<IEnumerable<double>>>>(shape); |
126 | 112 | filter = f; |
127 | 113 | break; |
128 | 114 | } |
129 | 115 | else if (typeName == "multipolygon") |
130 | 116 | { |
131 | 117 | IGeoShapeMultiPolygonFilter f = new GeoShapeMultiPolygonFilterDescriptor(); |
132 | 118 | f.Shape = new MultiPolygonGeoShape(); |
133 | | - var coordinates = shape["coordinates"]; |
134 | | - if (coordinates != null) |
135 | | - f.Shape.Coordinates = coordinates.Values<double[][][]>(); |
| 119 | + f.Shape.Coordinates = GetCoordinates<IEnumerable<IEnumerable<IEnumerable<IEnumerable<double>>>>>(shape); |
136 | 120 | filter = f; |
137 | 121 | break; |
138 | 122 | } |
|
0 commit comments