5

I am trying to add a base map to my plot through Contextily, but am getting this error when trying to see the plot.

Traceback (most recent call last):
  File "rasterio/_crs.pyx", line 322, in rasterio._crs._CRS.from_epsg
  File "rasterio/_err.pyx", line 192, in rasterio._err.exc_wrap_int
rasterio._err.CPLE_AppDefinedError: PROJ: proj_create_from_database: /opt/anaconda3/share/proj/proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 196, in process
    func(*args, **kwargs)
  File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/widgets.py", line 1051, in _clicked
    self.set_active(closest)
  File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/widgets.py", line 1077, in set_active
    func(self.labels[index].get_text())
  File "vis.py", line 1109, in draw_basemap
    ctx.add_basemap(ax, crs=properties_geo.crs.to_string())
  File "/opt/anaconda3/lib/python3.8/site-packages/contextily/plotting.py", line 139, in add_basemap
    left, right, bottom, top = _reproj_bb(
  File "/opt/anaconda3/lib/python3.8/site-packages/contextily/plotting.py", line 229, in _reproj_bb
    n_l, n_b, n_r, n_t = transform_bounds(s_crs, t_crs, left, bottom, right, top)
  File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/warp.py", line 180, in transform_bounds
    xs, ys = transform(src_crs, dst_crs, in_xs, in_ys)
  File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/env.py", line 387, in wrapper
    return f(*args, **kwds)
  File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/warp.py", line 65, in transform
    return _transform(src_crs, dst_crs, xs, ys, zs)
  File "rasterio/_base.pyx", line 1398, in rasterio._base._transform
  File "rasterio/_base.pyx", line 1444, in rasterio._base._osr_from_crs
  File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/crs.py", line 496, in from_user_input
    return cls.from_string(value, morph_from_esri_dialect=morph_from_esri_dialect)
  File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/crs.py", line 384, in from_string
    return cls.from_epsg(val)
  File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/crs.py", line 333, in from_epsg
    obj._crs = _CRS.from_epsg(code)
  File "rasterio/_crs.pyx", line 324, in rasterio._crs._CRS.from_epsg
rasterio.errors.CRSError: The EPSG code is unknown. PROJ: proj_create_from_database: /opt/anaconda3/share/proj/proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.

Here is what I am doing in my code:

route = pd.read_excel("0002_D1_0_fixed_out_points_15ft.xls")

        geometry = [Point(xy) for xy in zip(route.x_dd, route.y_dd)]
        gdf = GeoDataFrame(route, geometry=geometry, crs='EPSG:3857')

        fig,ax = plt.subplots()
        ax.plot(route['x_dd'], route['y_dd'], 'o', markersize=1)
        ctx.add_basemap(ax, crs=gdf.crs.to_string())
        plt.show()

I'm assuming this is an issue with how my installations are set up and not the code itself. I've tried doing conda activate base which is the environment I'm in but am still getting the same error. I am on macOS as well

excel file

  • 1
    EPSG:3857 is in meters, not decimal degrees. `x_dd` & `y_dd` implies decimal degree. Can you show a couple rows of your Excel file? If you replace your gdf CRS parameter with `crs='EPSG:4326'`, then your code should work – a11 Sep 30 '21 at 20:37
  • Thanks for the reply! Sorry for the late response, I've just added a picture of what my excel file looks like. I am still getting the same error when using code 4326, should I be using x_ft and y_ft with EPSG 3857? – pumpkinchugger Oct 04 '21 at 18:11
  • The screen grab is helpful, but you should put your data in a [MRE format](https://stackoverflow.com/help/minimal-reproducible-example) if you want quick and correct help. So for example, you should take the first few rows you show in the screen grab and give us what we need to build a minimum DataFrame on our end. Something like `fid = [0, 1, ...]` and `x_dd = [-83.8256, -83.8255, ...]` and then `route = pd.DataFrame(data=zip(fid, x_dd, ...), columns=["fid", "x_dd", ...])`. – a11 Oct 04 '21 at 19:00
  • 2
    Also, can you add some versioning info? Python version, geopandas version, shapely version, contextily version? – a11 Oct 04 '21 at 19:03
  • 2
    With the info you gave, I get points plotted in the Gulf of Guinea. With EPSG:3857 in meters and bounds that go up to 20026376.39 m it is not strange. In summary, **you need to know the EPSG of the data, or we need more info.** *1.* Try figuring out the EPSG from the source of the data. *2.* Edit your question with the versions of relevant libs (python, geopandas, pyproj, contextily, etc). The way it is now, I can only guess and can't really help much (but would like to). – Magnus Persson Feb 18 '22 at 09:13

0 Answers0