Skip to content

Commit 976a705

Browse files
authored
ENH: Standardize 2.5D => Z in geometry type labels (#234)
1 parent 47e7866 commit 976a705

File tree

6 files changed

+45
-43
lines changed

6 files changed

+45
-43
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- Add "driver" property to `read_info` result (#224)
99
- Add support for dataset open options to `read`, `read_dataframe`, and
1010
`read_info` (#233)
11+
- Standardized 3-dimensional geometry type labels from "2.5D <type>" to
12+
"<type> Z" for consistency with well-known text (WKT) formats (#234)
1113

1214
## 0.5.1 (2023-01-26)
1315

docs/source/known_issues.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Measured geometry types are not supported for reading or writing. These are not
2323
supported by the GEOS library and cannot be converted to geometry objects in
2424
GeoDataFrames.
2525

26-
These are automatically downgraded to their 2.5D (x,y, single z) equivalent and
26+
These are automatically downgraded to their 3D (x,y,z) equivalent and
2727
a warning is raised.
2828

2929
To ignore this warning:
@@ -59,7 +59,7 @@ give at most millisecond resolution (`datetime64[ms]` data type), even though
5959
the data is cast `datetime64[ns]` data type when reading into a data frame
6060
using `pyogrio.read_dataframe()`. When writing, only precision up to ms is retained.
6161

62-
Not all file formats have dedicated support to store datetime data, like ESRI
62+
Not all file formats have dedicated support to store datetime data, like ESRI
6363
Shapefile. For such formats, or if you require precision > ms, a workaround is to
6464
convert the datetimes to string.
6565

pyogrio/_geometry.pyx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,37 @@ GEOMETRY_TYPES = {
3434
wkbMultiLineStringZM: 'Measured 3D MultiLineString',
3535
wkbMultiPolygonZM: 'Measured 3D MultiPolygon',
3636
wkbGeometryCollectionZM: 'Measured 3D GeometryCollection',
37-
wkbPoint25D: '2.5D Point',
38-
wkbLineString25D: '2.5D LineString',
39-
wkbPolygon25D: '2.5D Polygon',
40-
wkbMultiPoint25D: '2.5D MultiPoint',
41-
wkbMultiLineString25D: '2.5D MultiLineString',
42-
wkbMultiPolygon25D: '2.5D MultiPolygon',
43-
wkbGeometryCollection25D: '2.5D GeometryCollection',
37+
wkbPoint25D: 'Point Z',
38+
wkbLineString25D: 'LineString Z',
39+
wkbPolygon25D: 'Polygon Z',
40+
wkbMultiPoint25D: 'MultiPoint Z',
41+
wkbMultiLineString25D: 'MultiLineString Z',
42+
wkbMultiPolygon25D: 'MultiPolygon Z',
43+
wkbGeometryCollection25D: 'GeometryCollection Z',
4444
}
4545

4646
GEOMETRY_TYPE_CODES = {v:k for k, v in GEOMETRY_TYPES.items()}
4747

48-
# add additional aliases from Simple Features WKT types with Z
48+
# add additional aliases from 2.5D format
4949
GEOMETRY_TYPE_CODES.update({
50-
'Point Z': wkbPoint25D,
51-
'LineString Z': wkbLineString25D,
52-
'Polygon Z': wkbPolygon25D,
53-
'MultiPoint Z': wkbMultiPoint25D,
54-
'MultiLineString Z': wkbMultiLineString25D,
55-
'MultiPolygon Z': wkbMultiPolygon25D,
56-
'GeometryCollection Z': wkbGeometryCollection25D
50+
'2.5D Point': wkbPoint25D,
51+
'2.5D LineString': wkbLineString25D,
52+
'2.5D Polygon': wkbPolygon25D,
53+
'2.5D MultiPoint': wkbMultiPoint25D,
54+
'2.5D MultiLineString': wkbMultiLineString25D,
55+
'2.5D MultiPolygon': wkbMultiPolygon25D,
56+
'2.5D GeometryCollection': wkbGeometryCollection25D
5757
})
5858

5959
# 2.5D also represented using negative numbers not enumerated above
6060
GEOMETRY_TYPES.update({
61-
-2147483647: '2.5D Point',
62-
-2147483646: '2.5D LineString',
63-
-2147483645: '2.5D Polygon',
64-
-2147483644: '2.5D MultiPoint',
65-
-2147483643: '2.5D MultiLineString',
66-
-2147483642: '2.5D MultiPolygon',
67-
-2147483641: '2.5D GeometryCollection',
61+
-2147483647: 'Point Z',
62+
-2147483646: 'LineString Z',
63+
-2147483645: 'Polygon Z',
64+
-2147483644: 'MultiPoint Z',
65+
-2147483643: 'MultiLineString Z',
66+
-2147483642: 'MultiPolygon Z',
67+
-2147483641: 'GeometryCollection Z',
6868
})
6969

7070

pyogrio/geopandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def write_dataframe(
368368
if geometry_type is None:
369369
geometry_type = tmp_geometry_type
370370
if has_z and geometry_type != "Unknown":
371-
geometry_type = f"2.5D {geometry_type}"
371+
geometry_type = f"{geometry_type} Z"
372372

373373
crs = None
374374
if geometry.crs:

pyogrio/tests/test_core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_list_layers(naturalearth_lowres, naturalearth_lowres_vsi, test_fgdb_vsi
9999
list_layers(naturalearth_lowres_vsi[1]), [["naturalearth_lowres", "Polygon"]]
100100
)
101101

102-
# Measured 3D is downgraded to 2.5D during read
102+
# Measured 3D is downgraded to plain 3D during read
103103
# Make sure this warning is raised
104104
with pytest.warns(
105105
UserWarning, match=r"Measured \(M\) geometry types are not supported"
@@ -111,9 +111,9 @@ def test_list_layers(naturalearth_lowres, naturalearth_lowres_vsi, test_fgdb_vsi
111111
# Make sure that nonspatial layer has None for geometry
112112
assert array_equal(fgdb_layers[0], ["basetable_2", None])
113113

114-
# Confirm that measured 3D is downgraded to 2.5D during read
115-
assert array_equal(fgdb_layers[3], ["test_lines", "2.5D MultiLineString"])
116-
assert array_equal(fgdb_layers[6], ["test_areas", "2.5D MultiPolygon"])
114+
# Confirm that measured 3D is downgraded to plain 3D during read
115+
assert array_equal(fgdb_layers[3], ["test_lines", "MultiLineString Z"])
116+
assert array_equal(fgdb_layers[6], ["test_areas", "MultiPolygon Z"])
117117

118118

119119
def test_read_bounds(naturalearth_lowres):

pyogrio/tests/test_geopandas_io.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -868,37 +868,37 @@ def test_write_geometry_z_types(tmp_path, wkt, geom_types):
868868
@pytest.mark.parametrize(
869869
"test_descr, exp_geometry_type, mixed_dimensions, wkt",
870870
[
871-
("1 Point Z", "2.5D Point", False, ["Point Z (0 0 0)"]),
872-
("1 LineString Z", "2.5D LineString", False, ["LineString Z (0 0 0, 1 1 0)"]),
871+
("1 Point Z", "Point Z", False, ["Point Z (0 0 0)"]),
872+
("1 LineString Z", "LineString Z", False, ["LineString Z (0 0 0, 1 1 0)"]),
873873
(
874874
"1 Polygon Z",
875-
"2.5D Polygon",
875+
"Polygon Z",
876876
False,
877877
["Polygon Z ((0 0 0, 0 1 0, 1 1 0, 0 0 0))"],
878878
),
879-
("1 MultiPoint Z", "2.5D MultiPoint", False, ["MultiPoint Z (0 0 0, 1 1 0)"]),
879+
("1 MultiPoint Z", "MultiPoint Z", False, ["MultiPoint Z (0 0 0, 1 1 0)"]),
880880
(
881881
"1 MultiLineString Z",
882-
"2.5D MultiLineString",
882+
"MultiLineString Z",
883883
False,
884884
["MultiLineString Z ((0 0 0, 1 1 0), (2 2 2, 3 3 2))"],
885885
),
886886
(
887887
"1 MultiLinePolygon Z",
888-
"2.5D MultiPolygon",
888+
"MultiPolygon Z",
889889
False,
890890
[
891891
"MultiPolygon Z (((0 0 0, 0 1 0, 1 1 0, 0 0 0)), ((1 1 1, 1 2 1, 2 2 1, 1 1 1)))" # noqa: E501
892892
],
893893
),
894894
(
895895
"1 GeometryCollection Z",
896-
"2.5D GeometryCollection",
896+
"GeometryCollection Z",
897897
False,
898898
["GeometryCollection Z (Point Z (0 0 0))"],
899899
),
900-
("Point Z + Point", "2.5D Point", True, ["Point Z (0 0 0)", "Point (0 0)"]),
901-
("Point Z + None", "2.5D Point", False, ["Point Z (0 0 0)", None]),
900+
("Point Z + Point", "Point Z", True, ["Point Z (0 0 0)", "Point (0 0)"]),
901+
("Point Z + None", "Point Z", False, ["Point Z (0 0 0)", None]),
902902
(
903903
"Point Z + LineString Z",
904904
"Unknown",
@@ -918,12 +918,12 @@ def test_write_geometry_z_types_auto(
918918
):
919919
# Shapefile has some different behaviour that other file types
920920
if ext == ".shp":
921-
if exp_geometry_type in ("2.5D GeometryCollection", "Unknown"):
921+
if exp_geometry_type in ("GeometryCollection Z", "Unknown"):
922922
pytest.skip(f"ext {ext} doesn't support {exp_geometry_type}")
923-
elif exp_geometry_type == "2.5D MultiLineString":
924-
exp_geometry_type = "2.5D LineString"
925-
elif exp_geometry_type == "2.5D MultiPolygon":
926-
exp_geometry_type = "2.5D Polygon"
923+
elif exp_geometry_type == "MultiLineString Z":
924+
exp_geometry_type = "LineString Z"
925+
elif exp_geometry_type == "MultiPolygon Z":
926+
exp_geometry_type = "Polygon Z"
927927

928928
column_data = {}
929929
column_data["test_descr"] = [test_descr] * len(wkt)

0 commit comments

Comments
 (0)