代码之家  ›  专栏  ›  技术社区  ›  cyber101

Python使用geopandas绘制纬度和经度。Pryproj例外

  •  0
  • cyber101  · 技术社区  · 4 年前

    我试图用Python将CSV文件中的细胞塔数据(lat,long)绘制到地图上。

    我得到了以下例外:

    Traceback (most recent call last):
      File "plotCellTowers.py", line 22, in <module>
        geo_df = gpd.GeoDataFrame(df,
      File "/usr/local/lib/python3.8/dist-packages/geopandas/geodataframe.py", line 109, in __init__
        self._crs = CRS.from_user_input(crs) if crs else None
      File "/usr/local/lib/python3.8/dist-packages/pyproj/crs/crs.py", line 440, in from_user_input
        return CRS(value, **kwargs)
      File "/usr/local/lib/python3.8/dist-packages/pyproj/crs/crs.py", line 296, in __init__
        super().__init__(projstring)
      File "pyproj/_crs.pyx", line 2309, in pyproj._crs._CRS.__init__
    pyproj.exceptions.CRSError: Invalid projection: +init=espc:4326 +type=crs: (Internal Proj Error: proj_create: cannot expand +init=espc:4326 +type=crs)
    

    Python脚本:

    #References: //medium.com/@ianforrest11/graphing-latitudes-and-longitudes-on-a-map-bf64d5fca391
    #Export map via https://extract.bbbike.org/
    #Actual OSM map: https://www.openstreetmap.org/#map=16/34.0646/-118.4104
    import pandas as pd
    import geopandas as gpd
    from shapely.geometry import Point, Polygon
    import matplotlib.pyplot as plt
    data_path = "cell_tower_west_la.csv"
    df = pd.read_csv(data_path, names=['lan', 'lon'], sep=',')
    
    print(df)
    
    # import street map
    street_map = gpd.read_file("/root/planet/planet/shape/roads.shp")
    
    
    # designate coordinate system
    crs = {'init':'espc:4326'}
    # zip x and y coordinates into single feature
    geometry = [(xy) for xy in zip(df['lan'], df['lon'])]
    # create GeoPandas dataframe. NOTE THE EXCEPTION HAPPENS HERE
    geo_df = gpd.GeoDataFrame(df,
     crs = crs,
     geometry = geometry)
    
     # create figure and axes, assign to subplot
    fig, ax = plt.subplots(figsize=(15,15))
    # add .shp mapfile to axes
    street_map.plot(ax=ax, alpha=0.4,color='grey')
    # add geodataframe to axes
    # assign ‘price’ variable to represent coordinates on graph
    # add legend
    # make datapoints transparent using alpha
    # assign size of points using markersize
    geo_df.plot(column='Cell Tower',ax=ax,alpha=0.5, legend=True,markersize=10)
    # add title to graph
    plt.title('Cell Towers Plotted', fontsize=15,fontweight='bold')
    # set latitiude and longitude boundaries for map display
    plt.xlim(34.0589,34.0700)
    plt.ylim(-118.4193, -118.3960)
    # show map
    plt.show()
    

    我用了这个教程:

    https://medium.com/@ianforrest11/graphing-latitudes-and-longitudes-on-a-map-bf64d5fca391

    实际地图的链接:

    https://www.openstreetmap.org/#map=16/34.0646/-118.4104

    可以通过联机工具导出形状文件:

    https://extract.bbbike.org/

    如何解决此错误&只需绘制简单的lat&我地图上的坐标是( https://www.openstreetmap.org/#map=16/34.0646/-118.4104 )然后保存到磁盘上?

    谢谢。

    0 回复  |  直到 4 年前
    推荐文章