@@ -2239,7 +2239,7 @@ private void assertGeometryFromHadoopShape(String hadoopHex, String expectedWkt)
22392239 }
22402240
22412241 @ Test
2242- public void testGeometryJsonConversion ()
2242+ public void testSphericalGeographyJsonConversion ()
22432243 {
22442244 // empty geometries should return empty
22452245 // empty geometries are represented by an empty JSON array in GeoJSON
@@ -2326,6 +2326,52 @@ private void assertInvalidGeometryJson(String json, String message)
23262326 .hasMessage (message );
23272327 }
23282328
2329+ @ Test
2330+ public void testGeometryJsonConversion ()
2331+ {
2332+ // empty geometries should return empty
2333+ // empty geometries are represented by an empty JSON array in GeoJSON
2334+ assertGeometryToAndFromJson ("POINT EMPTY" );
2335+ assertGeometryToAndFromJson ("LINESTRING EMPTY" );
2336+ assertGeometryToAndFromJson ("POLYGON EMPTY" );
2337+ assertGeometryToAndFromJson ("MULTIPOINT EMPTY" );
2338+ assertGeometryToAndFromJson ("MULTILINESTRING EMPTY" );
2339+ assertGeometryToAndFromJson ("MULTIPOLYGON EMPTY" );
2340+ assertGeometryToAndFromJson ("GEOMETRYCOLLECTION EMPTY" );
2341+
2342+ // valid nonempty geometries should return as is.
2343+ assertGeometryToAndFromJson ("POINT (1 2)" );
2344+ assertGeometryToAndFromJson ("MULTIPOINT ((1 2), (3 4))" );
2345+ assertGeometryToAndFromJson ("LINESTRING (0 0, 1 2, 3 4)" );
2346+ assertGeometryToAndFromJson ("MULTILINESTRING (" +
2347+ "(1 1, 5 1), " +
2348+ "(2 4, 4 4))" );
2349+ assertGeometryToAndFromJson ("POLYGON (" +
2350+ "(0 0, 1 0, 1 1, 0 1, 0 0))" );
2351+ assertGeometryToAndFromJson ("POLYGON (" +
2352+ "(0 0, 3 0, 3 3, 0 3, 0 0), " +
2353+ "(1 1, 1 2, 2 2, 2 1, 1 1))" );
2354+ assertGeometryToAndFromJson ("MULTIPOLYGON (" +
2355+ "((1 1, 3 1, 3 3, 1 3, 1 1)), " +
2356+ "((2 4, 6 4, 6 6, 2 6, 2 4)))" );
2357+ assertGeometryToAndFromJson ("GEOMETRYCOLLECTION (" +
2358+ "POINT (1 2), " +
2359+ "LINESTRING (0 0, 1 2, 3 4), " +
2360+ "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)))" );
2361+
2362+ // invalid geometries should return as is.
2363+ assertGeometryToAndFromJson ("MULTIPOINT ((0 0), (0 1), (1 1), (0 1))" );
2364+ assertGeometryToAndFromJson ("LINESTRING (0 0, 0 1, 0 1, 1 1, 1 0, 0 0)" );
2365+ assertGeometryToAndFromJson ("LINESTRING (0 0, 1 1, 1 0, 0 1)" );
2366+ }
2367+
2368+ private void assertGeometryToAndFromJson (String wkt )
2369+ {
2370+ assertThat (assertions .function ("ST_AsText" , "to_geometry(from_geojson_geometry(to_geojson_geometry(ST_GeometryFromText('%s'))))" .formatted (wkt )))
2371+ .hasType (VARCHAR )
2372+ .isEqualTo (wkt );
2373+ }
2374+
23292375 @ Test
23302376 public void testSTGeomFromKML ()
23312377 {
0 commit comments