geopandas.GeoDataFrame.to_crs#

GeoDataFrame.to_crs(crs=None, epsg=None, inplace=False)#

将几何图形变换到新的坐标参考系。

将激活的几何图形列中的所有几何图形转换到不同的坐标参考系。这个 crs 必须设置当前GeoSeries的属性。要么 crsepsg 可以为输出指定。

此方法将变换所有对象中的所有点。它没有概念,也没有投影整个几何图形。假定所有连接点的线段都是当前投影中的直线,而不是测地线。穿过日期线(或其他投影边界)的对象将具有不受欢迎的行为。

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

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

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

指定输出投影的EPSG代码。

inplace布尔值,可选,默认值:FALSE

是返回新的GeoDataFrame还是就地进行转换。

退货
GeoDataFrame

参见

GeoDataFrame.set_crs

无需重新投影即可指定CR

示例

>>> from shapely.geometry import Point
>>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
>>> gdf = geopandas.GeoDataFrame(d, crs=4326)
>>> gdf
    col1                 geometry
0  name1  POINT (1.00000 2.00000)
1  name2  POINT (2.00000 1.00000)
>>> gdf.crs  
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
>>> gdf = gdf.to_crs(3857)
>>> gdf
    col1                       geometry
0  name1  POINT (111319.491 222684.209)
1  name2  POINT (222638.982 111325.143)
>>> gdf.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