geopandas.GeoSeries.get_coordinates#
- GeoSeries.get_coordinates(include_z=False, ignore_index=False, index_parts=False)[source]#
Gets coordinates from a
GeoSeries
as aDataFrame
of floats.The shape of the returned
DataFrame
is (N, 2), with N being the number of coordinate pairs. With the default ofinclude_z=False
, three-dimensional data is ignored. When specifyinginclude_z=True
, the shape of the returnedDataFrame
is (N, 3).- Parameters
- include_zbool, default False
Include Z coordinates
- ignore_indexbool, default False
If True, the resulting index will be labelled 0, 1, …, n - 1, ignoring
index_parts
.- index_partsbool, default False
If True, the resulting index will be a
MultiIndex
(original index with an additional level indicating the ordering of the coordinate pairs: a new zero-based index for each geometry in the original GeoSeries).
- Returns
- pandas.DataFrame
Examples
>>> from shapely.geometry import Point, LineString, Polygon >>> s = geopandas.GeoSeries( ... [ ... Point(1, 1), ... LineString([(1, -1), (1, 0)]), ... Polygon([(3, -1), (4, 0), (3, 1)]), ... ] ... ) >>> s 0 POINT (1.00000 1.00000) 1 LINESTRING (1.00000 -1.00000, 1.00000 0.00000) 2 POLYGON ((3.00000 -1.00000, 4.00000 0.00000, 3... dtype: geometry
>>> s.get_coordinates() x y 0 1.0 1.0 1 1.0 -1.0 1 1.0 0.0 2 3.0 -1.0 2 4.0 0.0 2 3.0 1.0 2 3.0 -1.0
>>> s.get_coordinates(ignore_index=True) x y 0 1.0 1.0 1 1.0 -1.0 2 1.0 0.0 3 3.0 -1.0 4 4.0 0.0 5 3.0 1.0 6 3.0 -1.0
>>> s.get_coordinates(index_parts=True) x y 0 0 1.0 1.0 1 0 1.0 -1.0 1 1.0 0.0 2 0 3.0 -1.0 1 4.0 0.0 2 3.0 1.0 3 3.0 -1.0