geopandas.GeoDataFrame.to_crs#

GeoDataFrame.to_crs(crs=None, epsg=None, inplace=False)[来源]#

将几何体转换为新的坐标参考系。

将活动几何列中的所有几何图形转换为不同的坐标参考系统。当前 GeoSeries上的 crs 属性必须设置。输出时可以指定 crsepsg

此方法将转换所有对象中的所有点。它并没有将整个几何形状投影的概念。所有连接点的线段都假定为当前投影下的直线,而不是测地线。跨越国际日期变更线(或其他投影边界)的对象将表现出不良行为。

Parameters:
crspyproj.CRS, optional if epsg is specified

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

epsgint, optional if crs is specified

指定输出投影的EPSG代码。

inplacebool, optional, default: False

是否返回一个新的GeoDataFrame或就地进行转换。

Returns:
GeoDataFrame

另请参阅

GeoDataFrame.set_crs

分配坐标参考系统而不重新投影

示例

>>> 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 2)
1  name2  POINT (2 1)
>>> 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