0

I need to do some spatial operations in geopandas. I created the new conda environment and installed geopandas conda install --channel conda-forge geopandas. When I run the following simple code:

import geopandas as gpd
from shapely.geometry import Point

gdf = gpd.GeoDataFrame([Point(1,1)])
gdf.set_geometry(0).set_crs(epsg=3857)

I get the following error message :

CRSError: Invalid projection: EPSG:3857: (Internal Proj Error: proj_create: no database context specified)

I tried to google the issue. There are several posts, yet I could not find the right solution. It seems that there is a problem with pyproj database. That's what I understood so far.

Any solutions?

Thanks in advance!

1 Answers1

0

The error is in the step gdf.set_geometry(0). Try this instead:

import geopandas as gpd
from shapely.geometry import Point
gdf = gpd.GeoDataFrame([Point(1,1)])

# Dont do this
# gdf.set_geometry(0).set_crs(epsg=3857)
# But do it in 2 steps
gdf.set_geometry(0, inplace=True)
gdf.set_crs(epsg=3857, inplace=True)

gdf.plot()

Without inplace=True in gdf.set_geometry(), gdf object is not ready to do .set_crs(), thus, causes the error.

output

swatchai
  • 17,400
  • 3
  • 39
  • 58
  • Hi, thanks a lot for your comment. Unfortunately, it does not work. When I run the code you suggested, it still delivers the same error. Also, when I try to open any shape file and change the CRS, it also yields the same error. Here with, when I import geopandas (after restarting the kernel) it gives the following warning: `UserWarning: pyproj unable to set database path. _pyproj_global_context_initialize()` – Avto Abashishvili Feb 21 '23 at 14:56
  • @AvtoAbashishvili The error is on your side, which relates to your `pyproj` installation. See the discussion here https://gis.stackexchange.com/questions/363743/initalize-pyproj-correctly . – swatchai Feb 26 '23 at 11:51
  • Yes, I also found it. They seem to provide the solution here: (https://pyproj4.github.io/pyproj/stable/gotchas.html#internal-proj-error-sqlite-error-on-select) But the solution is quite shady. I did not really get how to do it. – Avto Abashishvili Feb 28 '23 at 13:54