drop_axis
- pyhelpers.geom.drop_axis(geom, axis='z', as_array=False)
Drop an axis from a given 3D geometry object.
- Parameters
geom (shapely.geometry object) – geometry object that has x, y and z coordinates
axis (str) – options include ‘x’, ‘y’ and ‘z’, defaults to
'z'
as_array (bool) – whether to return an array, defaults to
False
- Returns
geometry object (or an array) without the specified
axis
- Return type
shapely.geometry object or numpy.ndarray
Examples:
>>> from pyhelpers.geom import drop_axis >>> from shapely.geometry import Point, LineString, Polygon, MultiLineString >>> geom_1 = Point([1, 2, 3]) >>> geom_1.wkt 'POINT Z (1 2 3)' >>> geom_1_ = drop_axis(geom_1, 'x') >>> geom_1_.wkt 'POINT (2 3)' >>> geom_1_ = drop_axis(geom_1, 'x', as_array=True) >>> geom_1_ array([2., 3.]) >>> geom_2 = LineString([[1, 2, 3], [2, 3, 4], [3, 4, 5]]) >>> geom_2.wkt 'LINESTRING Z (1 2 3, 2 3 4, 3 4 5)' >>> geom_2_ = drop_axis(geom_2, 'y') >>> geom_2_.wkt 'LINESTRING (1 3, 2 4, 3 5)' >>> geom_2_ = drop_axis(geom_2, 'y', as_array=True) >>> geom_2_ array([[1., 3.], [2., 4.], [3., 5.]]) >>> geom_3 = Polygon([[6, 3, 5], [6, 3, 0], [6, 1, 0], [6, 1, 5], [6, 3, 5]]) >>> geom_3.wkt 'POLYGON Z ((6 3 5, 6 3 0, 6 1 0, 6 1 5, 6 3 5))' >>> geom_3_ = drop_axis(geom_3, 'z') >>> geom_3_.wkt 'POLYGON ((6 3, 6 3, 6 1, 6 1, 6 3))' >>> geom_3_ = drop_axis(geom_3, 'z', as_array=True) >>> geom_3_ array([[6., 3.], [6., 3.], [6., 1.], [6., 1.], [6., 3.]]) >>> ls1 = LineString([[1, 2, 3], [2, 3, 4], [3, 4, 5]]) >>> ls2 = LineString([[2, 3, 4], [1, 2, 3], [3, 4, 5]]) >>> geom_4 = MultiLineString([ls1, ls2]) >>> geom_4.wkt 'MULTILINESTRING Z ((1 2 3, 2 3 4, 3 4 5), (2 3 4, 1 2 3, 3 4 5))' >>> geom_4_ = drop_axis(geom_4, 'z') >>> geom_4_.wkt 'MULTILINESTRING ((1 2, 2 3, 3 4), (2 3, 1 2, 3 4))' >>> geom_4_ = drop_axis(geom_4, 'z', as_array=True) >>> geom_4_ array([[[1., 2.], [2., 3.], [3., 4.]], [[2., 3.], [1., 2.], [3., 4.]]])