@@ -150,7 +150,61 @@ private Geometry normalize(Geometry geometry) {
150150 }
151151 }
152152
153- public void testFetchSourceValueDateLine () throws IOException {
153+ public void testFetchSourcePolygonDateLine () throws IOException {
154+ assertFetchSourceGeometry (
155+ "POLYGON((170 -10, -170 -10, -170 10, 170 10, 170 -10))" ,
156+ "MULTIPOLYGON (((180.0 -10.0, 180.0 10.0, 170.0 10.0, 170.0 -10.0, 180.0 -10.0)),"
157+ + "((-180.0 10.0, -180.0 -10.0, -170.0 -10.0, -170.0 10.0, -180.0 10.0)))" ,
158+ Map .of (
159+ "type" ,
160+ "MultiPolygon" ,
161+ "coordinates" ,
162+ List .of (
163+ List .of (
164+ List .of (
165+ List .of (180.0 , -10.0 ),
166+ List .of (180.0 , 10.0 ),
167+ List .of (170.0 , 10.0 ),
168+ List .of (170.0 , -10.0 ),
169+ List .of (180.0 , -10.0 )
170+ )
171+ ),
172+ List .of (
173+ List .of (
174+ List .of (-180.0 , 10.0 ),
175+ List .of (-180.0 , -10.0 ),
176+ List .of (-170.0 , -10.0 ),
177+ List .of (-170.0 , 10.0 ),
178+ List .of (-180.0 , 10.0 )
179+ )
180+ )
181+ )
182+ ),
183+ "MULTIPOLYGON (((180.0 -10.0, 180.0 10.0, 170.0 10.0, 170.0 -10.0, 180.0 -10.0)),"
184+ + "((-180.0 10.0, -180.0 -10.0, -170.0 -10.0, -170.0 10.0, -180.0 10.0)))"
185+ );
186+ }
187+
188+ public void testFetchSourceEnvelope () throws IOException {
189+ assertFetchSourceGeometry (
190+ "BBOX(-10, 10, 10, -10)" ,
191+ "BBOX (-10.0, 10.0, 10.0, -10.0)" ,
192+ Map .of ("type" , "Envelope" , "coordinates" , List .of (List .of (-10.0 , 10.0 ), List .of (10.0 , -10.0 ))),
193+ "POLYGON ((-10 -10, 10 -10, 10 10, -10 10, -10 -10)))"
194+ );
195+ }
196+
197+ public void testFetchSourceEnvelopeDateLine () throws IOException {
198+ assertFetchSourceGeometry (
199+ "BBOX(10, -10, 10, -10)" ,
200+ "BBOX (10.0, -10.0, 10.0, -10.0)" ,
201+ Map .of ("type" , "Envelope" , "coordinates" , List .of (List .of (10.0 , 10.0 ), List .of (-10.0 , -10.0 ))),
202+ "MULTIPOLYGON (((-180 -10, -10 -10, -10 10, -180 10, -180 -10)), ((10 -10, 180 -10, 180 10, 10 10, 10 -10)))"
203+ );
204+ }
205+
206+ private void assertFetchSourceGeometry (Object sourceValue , String wktValue , Map <String , Object > jsonValue , String mvtEquivalentAsWKT )
207+ throws IOException {
154208 final GeoFormatterFactory <Geometry > geoFormatterFactory = new GeoFormatterFactory <>(
155209 new SpatialGeometryFormatterExtension ().getGeometryFormatterFactories ()
156210 );
@@ -161,38 +215,13 @@ public void testFetchSourceValueDateLine() throws IOException {
161215 false ,
162216 geoFormatterFactory
163217 ).build (MapperBuilderContext .ROOT ).fieldType ();
164- // Test a polygon crossing the dateline
165- Object sourceValue = "POLYGON((170 -10, -170 -10, -170 10, 170 10, 170 -10))" ;
166- String polygonDateLine = "MULTIPOLYGON (((180.0 -10.0, 180.0 10.0, 170.0 10.0, 170.0 -10.0, 180.0 -10.0)),"
167- + "((-180.0 10.0, -180.0 -10.0, -170.0 -10.0, -170.0 10.0, -180.0 10.0)))" ;
168- Map <String , Object > jsonPolygonDateLine = Map .of (
169- "type" ,
170- "MultiPolygon" ,
171- "coordinates" ,
172- List .of (
173- List .of (
174- List .of (List .of (180.0 , -10.0 ), List .of (180.0 , 10.0 ), List .of (170.0 , 10.0 ), List .of (170.0 , -10.0 ), List .of (180.0 , -10.0 ))
175- ),
176- List .of (
177- List .of (
178- List .of (-180.0 , 10.0 ),
179- List .of (-180.0 , -10.0 ),
180- List .of (-170.0 , -10.0 ),
181- List .of (-170.0 , 10.0 ),
182- List .of (-180.0 , 10.0 )
183- )
184- )
185- )
186- );
187-
188- assertEquals (List .of (jsonPolygonDateLine ), fetchSourceValue (mapper , sourceValue , null ));
189- assertEquals (List .of (polygonDateLine ), fetchSourceValue (mapper , sourceValue , "wkt" ));
190218
191- String mvtPolygonDateLine = "MULTIPOLYGON (((180.0 -10.0, 180.0 10.0, 170.0 10.0, 170.0 -10.0, 180.0 -10.0)),"
192- + "((-180.0 10.0, -180.0 -10.0, -170.0 -10.0, -170.0 10.0, -180.0 10.0)))" ;
219+ assertEquals ( List . of ( jsonValue ), fetchSourceValue ( mapper , sourceValue , null ));
220+ assertEquals ( List . of ( wktValue ), fetchSourceValue ( mapper , sourceValue , "wkt" )) ;
193221
194- List <?> mvtExpected = fetchSourceValue (mapper , mvtPolygonDateLine , "mvt(0/0/0@256)" );
195- List <?> mvt = fetchSourceValue (mapper , sourceValue , "mvt(0/0/0@256)" );
222+ final int extent = randomIntBetween (256 , 4096 );
223+ List <?> mvtExpected = fetchSourceValue (mapper , mvtEquivalentAsWKT , "mvt(0/0/0@" + extent + ")" );
224+ List <?> mvt = fetchSourceValue (mapper , sourceValue , "mvt(0/0/0@" + extent + ")" );
196225 assertThat (mvt .size (), Matchers .equalTo (1 ));
197226 assertThat (mvt .size (), Matchers .equalTo (mvtExpected .size ()));
198227 assertThat (mvtExpected .get (0 ), Matchers .instanceOf (byte [].class ));
0 commit comments