Geopandas:缓冲区操作似乎忽略了 CRS 的度量单位

问题描述

我的目标是从现有数据框中的几列坐标创建一个地理数据框,获取这 1677 个地理点并在每个点周围添加一个缓冲圈,然后将生成的多边形合并为一个多面体。我一直在绕轴的地方是 geopandas 的 .buffer() 部分似乎没有使用我选择的 CRS 的度量单位。

In  []: ven_coords

Out []:     VenLat      VenLon
       0    42.34768    -71.085359
       1    42.349014   -71.081096
       2    42.347627   -71.081685
       3    42.348718   -71.077984
       4    42.34896    -71.081467
     ...         ...           ...
    1672    42.308962   -71.073516
    1673    42.313169   -71.089027
    1674    42.309717   -71.08247
    1675    42.356336   -71.074386
    1676    42.313005   -71.089887
    1677 rows × 2 columns

In  []: ven_coords_gdf = geopandas.GeoDataFrame(ven_coords,geometry=geopandas.points_from_xy(ven_coords.VenLon,ven_coords.VenLat))
        ven_coords_gdf

Out []: VenLat  VenLon  geometry
       0    42.34768    -71.085359  POINT (-71.08536 42.34768)
       1    42.349014   -71.081096  POINT (-71.08110 42.34901)
       2    42.347627   -71.081685  POINT (-71.08168 42.34763)
       3    42.348718   -71.077984  POINT (-71.07798 42.34872)
       4    42.34896    -71.081467  POINT (-71.08147 42.34896)
     ...         ...           ...                        ...
    1672    42.308962   -71.073516  POINT (-71.07352 42.30896)
    1673    42.313169   -71.089027  POINT (-71.08903 42.31317)
    1674    42.309717   -71.08247   POINT (-71.08247 42.30972)
    1675    42.356336   -71.074386  POINT (-71.07439 42.35634)
    1676    42.313005   -71.089887  POINT (-71.08989 42.31300)
    1677 rows × 3 columns

到目前为止一切顺利,让我们看看我得到了什么样的东西:

In  []: print('Type:',type(ven_coords_gdf),"/ current CRS is:",ven_coords_gdf.crs)

Out []: Type: <class 'geopandas.geodataframe.GeoDataFrame'> / current CRS is: None

它没有 CRS,因此我将其分配给与我正在从事的工作相关的一项:

In  []: ven_coords_gdf.crs = ("epsg:2249")
        print('Type:',ven_coords_gdf.crs)

Out []: Type: <class 'geopandas.geodataframe.GeoDataFrame'> / current CRS is: epsg:2249

它似乎“占用”了我添加的 CRS,为了仔细检查,让我们来看看相关 CRS 的详细信息:

In  []: CRS.from_epsg(2249)

Out []: <Projected CRS: EPSG:2249>
        Name: NAD83 / Massachusetts Mainland (ftUS)
        Axis Info [cartesian]:
        - X[east]: Easting (US survey foot)
        - Y[north]: Northing (US survey foot)
        Area of Use:
        - name: United States (USA) - Massachusetts onshore - counties of Barnstable; Berkshire; Bristol; Essex; Franklin; Hampden; Hampshire; Middlesex; Norfolk; Plymouth; Suffolk; Worcester.
        - bounds: (-73.5,41.46,-69.86,42.89)
        Coordinate Operation:
        - name: SPCS83 Massachusetts Mainland zone (US Survey feet)
        - method: Lambert Conic Conformal (2SP)
        Datum: North American Datum 1983
        - Ellipsoid: GRS 1980
        - Prime Meridian: Greenwich

2249 使用美国测量英尺作为测量单位,因此我将缓冲区设置为 1000,以便从数据中的每个点获得 1000 英尺半径:

In  []: ven_coords_buffer = ven_coords_gdf.geometry.buffer(distance = 1000)
        ven_coords_buffer

Out []: 0       POLYGON ((928.915 42.348,924.099 -55.669,909...
        1       POLYGON ((928.919 42.349,924.104 -55.668,909...
        2       POLYGON ((928.918 42.348,924.103 -55.670,909...
        3       POLYGON ((928.922 42.349,924.107 -55.668,909...
        4       POLYGON ((928.919 42.349,924.103 -55.668,909...
                                     ...                        
        1672    POLYGON ((928.926 42.309,924.111 -55.708,909...
        1673    POLYGON ((928.911 42.313,924.096 -55.704,909...
        1674    POLYGON ((928.918 42.310,924.102 -55.707,909...
        1675    POLYGON ((928.926 42.356,924.110 -55.661,909...
        1676    POLYGON ((928.910 42.313,924.095 -55.704,909...
        Length: 1677,dtype: geometry

那些坐标差一点点。很明显,buffer 将自身应用为 1000°,而不是 1000 英尺,从而产生了覆盖整个地球的 1677 个巨大的重叠圆。不是完全我正在寻找的。显然我遗漏了什么,有什么建议吗?

对于任何有趣的代码问题,老实说,我发誓它更早地起作用。我摸索了一会儿,终于让它输出了正确的东西,然后我将它关闭,去吃晚饭,回来重新运行它,得到了上面的结果。明显的推论是,我在前面提到的 futzing 中所做的一些事情是让它工作的关键,一些重用的变量或其他什么,但我无法弄清楚上面的代码中缺少什么。

GeoPandas 0.9.0,pyproj 3.0.1

screenshot from happier times when it worked and I got it onto a map

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)