geopandas.GeoSeries.set_crs#

GeoSeries.set_crs(crs=None, epsg=None, inplace=False, allow_override=False)#

设置的坐标系(CRS) GeoSeries

注意:底层几何图形不会转换为此CRS。若要将几何图形转换为新的CRS,请使用 to_crs 方法。

参数
crs :pyproj.crs,如果是可选的 epsg 是指定的Pyproj.crs,可选,如果

该值可以是接受的任何值 pyproj.CRS.from_user_input() 例如,授权字符串(例如“EPSG:4326”)或WKT字符串。

epsg :int,在以下情况下可选 crs 是指定的Int,如果是可选的

指定投影的EPSG代码。

inplace布尔值,默认为False

如果为True,则将就地更改GeoSeries的CRS(同时仍返回结果),而不是复制GeoSeries。

allow_override布尔值,默认为False

如果GeoSeries已有CRS,则允许替换现有CRS,即使两者不相等。

退货
GeoSeries

参见

GeoSeries.to_crs

重新投影到另一个CRS

示例

>>> from shapely.geometry import Point
>>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
>>> s
0    POINT (1.00000 1.00000)
1    POINT (2.00000 2.00000)
2    POINT (3.00000 3.00000)
dtype: geometry

将CRS设置为不带的GeoSeries:

>>> s.crs is None
True
>>> s = s.set_crs('epsg:3857')
>>> s.crs  
<Projected CRS: EPSG:3857>
Name: WGS 84 / Pseudo-Mercator
Axis Info [cartesian]:
- X[east]: Easting (metre)
- Y[north]: Northing (metre)
Area of Use:
- name: World - 85°S to 85°N
- bounds: (-180.0, -85.06, 180.0, 85.06)
Coordinate Operation:
- name: Popular Visualisation Pseudo-Mercator
- method: Popular Visualisation Pseudo Mercator
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich

覆盖现有的CR:

>>> s = s.set_crs(4326, allow_override=True)

没有 allow_override=Trueset_crs 如果尝试覆盖CRS,则返回错误。