0

I am realatively new to Python programming and have an issue with pyproj mixing up the CRS database (this is what I gather from the web). I have a little script I've written to retrieve Sentinel images and get the following error:

~\anaconda3\envs\Raster\lib\site-packages\pyproj\crs\crs.py in init(self, projparams, **kwargs) 294 projstring = _prepare_from_string(" ".join((projstring, projkwargs))) 295 --> 296 super().init(projstring) 297 298 @staticmethod

pyproj/_crs.pyx in pyproj._crs._CRS.init()

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)

It all started after I had some problems with the environment this program was written in, and just created a new environment with all the modules installed, but now my once working program is not working. The error is a known issue as stated on the pyproj page, but I am at a loss on how to actually solve it.

I have tried pyproj.datadir.get_data_dir() in jupyter and I get the following read out:

C:\\Users\\Matthew\\anaconda3\\envs\\Raster\\lib\\site- 
packages\\pyproj\\proj_dir\\share\\proj'

This checks out. The virtual environment is Raster as stated.

I also did a pip uninstall in the Raster environment via CMD. Then I tried running it again and got the following:

~\anaconda3\envs\Raster\lib\site-packages\geopandas\_compat.py in <module>
    210 # -----------------------------------------------------------------------------
    211 
--> 212 PYPROJ_LT_3 = LooseVersion(pyproj.__version__) < LooseVersion("3")

AttributeError: module 'pyproj' has no attribute 'version'

The program code is below:

# -- Connect to the ESA Server via Sentinel Application Programming Interface (API) --
from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
from datetime import date
import geopandas as gpd
import matplotlib.pyplot as plt
import folium
import pandas as pd


# -- Username & Password Login Information --

user = 'xxxxxxx' 
password = 'xxxxxxxx' 
api = SentinelAPI(user, password, 'https://apihub.copernicus.eu/apihub')

# server locations
#https://scihub.copernicus.eu/dhu
#https://apihub.copernicus.eu/apihub


# Create footprint for search

aoi = geojson_to_wkt(read_geojson(r"C:\Users\Matthew\OneDrive \Land Suitability Model"
                                  r"\Layers\Sentinel\Sentinel RST\aoi.geojson"))

# Search query

products = api.query(aoi,
                     date = ('20210715', '20210814'),  # year (xxxx), month (xx), day (xx)
                     platformname = 'Sentinel-2', # Sentinel-2 (10,20m,60m MSI), Sentinel-1 (20m SAR)
                     processinglevel = 'Level-2A',  # can change to 2A or 1C processed image tiles
                     cloudcoverpercentage = (0,5)  # from % to % <=40
                     )

# Review available image tiles (sorted by cloud cover)
products_gdf = api.to_geodataframe(products)
products_gdf_sorted = products_gdf.sort_values(['cloudcoverpercentage'], ascending=[True])
products_df1 = pd.DataFrame(products_gdf_sorted) 
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)

# Display Sentinel Query Results
print('Number of Sentinel Products:',len(products))
display(products_df1[['title','uuid','generationdate','cloudcoverpercentage','size','processinglevel']])
query_footprints = api.to_geojson(products)
pd.set_option('display.max_columns', None) 
# -- Display AOI and Sentinel-2A query results --

# Use if your interested in a point
# AOI = 'POINT (xxx xxx)'

# Set style list for AOI
style = {'fillColor': '#ffff00', 'color': '#000000'}

# Read in AOI & Query footprints
AOI = gpd.read_file(r"C:\Users\Matthew\OneDrive\Land Suitability Model\Layers\Sentinel"
                    r"\Sentinel RST\aoi.geojson")
mainmap = folium.Map(
    location =[56.730259, -121.808989], zoom_start=7,
)
folium.GeoJson(query_footprints).add_to(mainmap)
folium.GeoJson(AOI,style_function = lambda x:style).add_to(mainmap)
mainmap

1 Answer 1

0

To resolve the issue I created a new virtual environment and reinstalled modules using the following command:

conda install geopandas --channel=conda-forge
pip install sentinelsat
conda install matplotlib --channel=conda-forge
conda install folium --channel=conda-forge

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.