@@ -534,12 +534,14 @@ def test_getitem_geometry_collection(coordinates):
534534
535535def test_wkt_mixed_geometry_collection ():
536536 point = Point (type = "Point" , coordinates = (0.0 , 0.0 , 0.0 ))
537- line_string = LineString (type = "LineString" , coordinates = [(0.0 , 0.0 ), (1.0 , 1.0 )])
537+ line_string = LineString (
538+ type = "LineString" , coordinates = [(0.0 , 0.0 , 0.0 ), (1.0 , 1.0 , 1.0 )]
539+ )
538540 assert (
539541 GeometryCollection (
540542 type = "GeometryCollection" , geometries = [point , line_string ]
541543 ).wkt
542- == "GEOMETRYCOLLECTION Z (POINT Z (0.0 0.0 0.0), LINESTRING (0.0 0.0, 1.0 1.0))"
544+ == "GEOMETRYCOLLECTION Z (POINT Z (0.0 0.0 0.0), LINESTRING Z (0.0 0.0 0.0, 1.0 1.0 1.0))"
543545 )
544546
545547
@@ -552,6 +554,9 @@ def test_wkt_empty_geometry_collection():
552554
553555def test_geometry_collection_warnings ():
554556 point = Point (type = "Point" , coordinates = (0.0 , 0.0 , 0.0 ))
557+ line_string_z = LineString (
558+ type = "LineString" , coordinates = [(0.0 , 0.0 , 0.0 ), (1.0 , 1.0 , 1.0 )]
559+ )
555560 line_string = LineString (type = "LineString" , coordinates = [(0.0 , 0.0 ), (1.0 , 1.0 )])
556561
557562 # one geometry
@@ -575,18 +580,15 @@ def test_geometry_collection_warnings():
575580 type = "GeometryCollection" ,
576581 geometries = [
577582 GeometryCollection (
578- type = "GeometryCollection" , geometries = [point , line_string ]
583+ type = "GeometryCollection" , geometries = [point , line_string_z ]
579584 ),
580585 point ,
581586 ],
582587 )
583588
584- # homogeneous geometry
585- with pytest .warns (
586- UserWarning ,
587- match = "GeometryCollection should not be used for homogeneous collections." ,
588- ):
589- GeometryCollection (type = "GeometryCollection" , geometries = [point , point ])
589+ # homogeneous (Z) geometry
590+ with pytest .raises (ValidationError ):
591+ GeometryCollection (type = "GeometryCollection" , geometries = [point , line_string ])
590592
591593
592594def test_polygon_from_bounds ():
@@ -776,9 +778,9 @@ def test_wkt_empty_geometrycollection():
776778 "MULTIPOLYGON Z (((0.0 0.0 0.0, 1.0 1.0 0.0, 2.0 2.0 0.0, 3.0 3.0 0.0, 0.0 0.0 0.0)), ((1.0 1.0 0.0, 2.0 2.0 0.0, 3.0 3.0 0.0, 4.0 4.0 0.0, 1.0 1.0 0.0)))" ,
777779 "MULTIPOLYGON EMPTY" ,
778780 "GEOMETRYCOLLECTION (POINT (0.0 0.0))" ,
781+ "GEOMETRYCOLLECTION (POLYGON EMPTY, MULTIPOLYGON (((0.0 0.0, 1.0 1.0, 2.0 2.0, 3.0 3.0, 0.0 0.0))))" ,
779782 "GEOMETRYCOLLECTION (POINT (0.0 0.0), MULTIPOINT ((0.0 0.0), (1.0 1.0)))" ,
780- "GEOMETRYCOLLECTION Z (POLYGON EMPTY, MULTIPOLYGON Z (((0.0 0.0 0.0, 1.0 1.0 0.0, 2.0 2.0 0.0, 3.0 3.0 0.0, 0.0 0.0 0.0))))" ,
781- "GEOMETRYCOLLECTION Z (LINESTRING Z (0.0 0.0 0.0, 1.0 1.0 1.0, 2.0 2.0 2.0), MULTILINESTRING ((0.0 0.0, 1.0 1.0), (1.0 1.0, 2.0 2.0)))" ,
783+ "GEOMETRYCOLLECTION Z (POLYGON Z ((0.0 0.0 0.0, 1.0 1.0 0.0, 2.0 2.0 0.0, 3.0 3.0 0.0, 0.0 0.0 0.0)), MULTIPOLYGON Z (((0.0 0.0 0.0, 1.0 1.0 0.0, 2.0 2.0 0.0, 3.0 3.0 0.0, 0.0 0.0 0.0))))" ,
782784 "GEOMETRYCOLLECTION EMPTY" ,
783785 ),
784786)
@@ -843,10 +845,22 @@ def test_geometry_collection_serializer():
843845 LineString (type = "LineString" , coordinates = [(0.0 , 0.0 ), (1.0 , 1.0 )]),
844846 ],
845847 )
848+ assert not geom .has_z
846849 # bbox will be in the Dict
847850 assert "bbox" in geom .model_dump ()
848851 assert "bbox" in geom .model_dump ()["geometries" ][0 ]
849852
853+ geom = GeometryCollection (
854+ type = "GeometryCollection" ,
855+ geometries = [
856+ Point (type = "Point" , coordinates = [0 , 0 , 0 ]),
857+ LineString (
858+ type = "LineString" , coordinates = [(0.0 , 0.0 , 0.0 ), (1.0 , 1.0 , 1.0 )]
859+ ),
860+ ],
861+ )
862+ assert geom .has_z
863+
850864 # bbox should not be in any Geometry nor at the top level
851865 geom_ser = json .loads (geom .model_dump_json ())
852866 assert "bbox" not in geom_ser
0 commit comments