GeoPandas Anaconda – Fixing CRSError: Invalid Projection

anacondageopandas

I cant get GeoPandas to work properly on my new laptop, with windows 10.

Installation:

  1. https://repo.anaconda.com/archive/Anaconda3-2022.10-Windows-x86_64.exe, executed as admin
  2. Anaconda prompt (as admin) and conda install geopandas

I can import geopandas fine but:

import geopandas as gpd
from shapely.geometry import Point

coords = [[15.97, 57.9], [15.92, 57.87], [15.96, 57.87], [15.99, 57.89], [15.95, 57.86], [15.92, 57.87], [15.91, 57.89], [15.96, 57.89], [15.95, 57.87], [15.96, 57.89], [15.97, 57.87], [15.93, 57.9], [15.99, 57.9], [15.92, 57.89], [15.96, 57.89], [15.94, 57.88], [15.95, 57.88], [15.92, 57.88], [15.99, 57.88], [15.96, 57.88], [15.92, 57.89], [15.99, 57.87], [15.94, 57.86], [15.98, 57.87], [15.97, 57.88], [15.97, 57.9], [15.93, 57.9], [15.94, 57.86], [16.0, 57.88], [15.93, 57.9], [15.96, 57.89], [15.99, 57.88]]
points = [Point(c) for c in coords]

df = gpd.GeoDataFrame(geometry=points, crs="epsg:4326")

CRSError: Invalid projection: epsg:4326: (Internal Proj Error:
proj_create: SQLite error on SELECT name, type,
coordinate_system_auth_name, coordinate_system_code, datum_auth_name,
datum_code, area_of_use_auth_name, area_of_use_code, text_definition,
deprecated FROM geodetic_crs WHERE auth_name = ? AND code = ?: no such
column: area_of_use_auth_name)

Without crs="epsg:4326" it is working.

I've read:

But they do not help me.
It seems anaconda is using PostGIS:s pyproj, I dont know if that can be an issue?

import pyproj
pyproj.datadir.get_data_dir()
'C:\\Program Files\\PostgreSQL\\15\\share\\contrib\\postgis-3.3\\proj'

Update:
I have multiple proj.db's

C:/OSGeo4W\share\proj\proj.db
C:/Program Files\PostgreSQL\15\share\contrib\postgis-3.3\proj\proj.db
C:/ProgramData\Anaconda3\Library\share\proj\proj.db
C:/ProgramData\Anaconda3\pkgs\proj-6.2.1-h3758d61_0\Library\share\proj\proj.db

Update 2:

I tried uninstalling Anaconda, OSGeo4W and PostgreSQL+PostGIS. And reinstalled Anaconda. And the code works. Installed OSGeo4W and the code works. After installing PostgreSQL 15.2 and PostGIS 3.3 Bundle 3.3.2 the error comes back.

So it seems that it is PostgreSQL and PostGIS that cause geopandas to break.

Best Answer

Sounds like you mixed conda channels in your environment. The best way to get the GIS stack working on any platform with conda is to create a new environment and be sure that every single package in that environment comes from the same channel. In my experience over the past 7-ish of using conda, the conda-forge channel is the better choice over the defaults channel.

So, outside of your python session:

conda create --name=gis python=3.10 geopandas rasterio --channel=conda-forge --yes
conda activate gis
python gis-script.py

Where gis-script.py is something like:

import geopandas as gpd
from shapely.geometry import Point

coords = [
    [15.97, 57.9], [15.92, 57.87], [15.96, 57.87], [15.99, 57.89], 
    [15.95, 57.86], [15.92, 57.87], [15.91, 57.89], [15.96, 57.89], 
    [15.95, 57.87], [15.96, 57.89], [15.97, 57.87], [15.93, 57.9]
]
df = gpd.GeoDataFrame(geometry=[Point(c) for c in coords], crs="epsg:4326")
Related Question