0

Im attempting to plot, cell tower data (lat,long) from a CSV file onto a map using Python.

Im getting this exceptions:

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 script:

#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()

I used this tutorial:

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

The link to actual map:

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

You can get the shape file exported via the online tool:

https://extract.bbbike.org/

How can I resolve this error & just plot the simple lat & lon coordinates on my map at (https://www.openstreetmap.org/#map=16/34.0646/-118.4104) and save that on disk?

Appreciated.

cyber101
  • 2,822
  • 14
  • 50
  • 93
  • 4
    `crs = {'init':'espc:4326'}` Is this correct? Isn't this it? `{'init': 'epsg:4326'}` – r-beginners Apr 01 '21 at 04:42
  • @r-beginners, after that change, I got this Error: TypeError: Input must be valid geometry objects: ('ec_no', 'arfcn') – cyber101 Apr 01 '21 at 17:33
  • change from `crs = {'init':'espc:4326'}` to `{'init': 'epsg:4326'}` throws this error: `raise TypeError("Input must be valid geometry objects: {0}".format(geom)) TypeError: Input must be valid geometry objects: ('ec_no', 'arfcn')` – cyber101 Apr 01 '21 at 17:35
  • 2
    Based on the [docs](https://geopandas.org/reference/geopandas.GeoDataFrame.html), it looks like designating your coordinate system as `crs="EPSG:4326"` (instead of `crs = {'init':'espc:4326'}`) should work. I think the syntax you are using is from an older version of pyproj. – a11 Apr 03 '21 at 02:56
  • @a11 broken link - try https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.html – Medulla Oblongata Jan 13 '22 at 00:38

0 Answers0