Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to display a raster .tiff file on the map #125

Closed
12rambau opened this issue Jul 31, 2020 · 14 comments
Closed

Impossible to display a raster .tiff file on the map #125

12rambau opened this issue Jul 31, 2020 · 14 comments

Comments

@12rambau
Copy link
Member

12rambau commented Jul 31, 2020

setup

rasterio==1.1.5
python==3.6
geemap==0.7.9
gdal==3.0.4

description

I'm using geemap to display a raster on a created map.
It uses xarray_leaflet to display the raster and this lib will end up using rasterio to manipulate the .tif file.

When I launch my display :

m = geemap.Map()
m.add_raster(clip_map, colormap='terrain', layer_name='gfc')

I get the following error :

CRSError: Unable to open EPSG support file gcs.csv. Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.

This error is everywhere on SO so I tried to verify if my GDAL_DATA env variable was coorectly set :

import os
import stat
gdal_data = os.environ['GDAL_DATA']
print('is dir: ' + str(os.path.isdir(gdal_data)))
gcs_csv = os.path.join(gdal_data, 'gcs.csv')
print('is file: ' + str(os.path.isfile(gcs_csv)))
st = os.stat(gcs_csv)
print('is readable: ' + str(bool(st.st_mode & stat.S_IRGRP)))

# out 
# is dir: True
#is file: False
#FileNotFoundError: [Errno 2] No such file or directory: '/usr/share/gdal/gcs.csv'

going to the glad distrib inb the NEWS file, I read that they removed lots of file in 3.0 including gcs.csv. So it's no longer included in my folder.

It's the first time I'm having a compatibility problem between rasterio and gdal so I'm very surprised.

Having the feeling to be dum I try to reproduce your example. It raised the same error (I also verified the files that display perfectly in Qgis).

Is this function still working ? Did you see anything wrong in the way I'm using it ?

@giswqs
Copy link
Member

giswqs commented Jul 31, 2020

What operating system are you using? Have your tried creating a fresh conda env to install geemap and xarray_leaflet? I just tested this notebook example, and it works fine on my Linux machine.

conda create -n gee python
conda activate gee
conda install mamba -c conda-forge
mamba install geemap xarray_leaflet -c conda-forge

@12rambau
Copy link
Member Author

I'm working on the cloud env of my company I have very little control on it but if you think it's the problem I'll see with my colleagues to debug it. I'll tell here if we find a solution. Don't hesitate if you have any other idea until then

@giswqs
Copy link
Member

giswqs commented Jul 31, 2020

Some dependencies (e.g., gdal, rasterio) of the xarray_leaflet package can be challenging to install as they might conflict with other packages within an existing conda env, and that's why I have not made xarray_leaflet an official dependency of geemap. Creating a fresh conda env usually can solve the issue.

@12rambau
Copy link
Member Author

12rambau commented Aug 1, 2020

Can you just give me the version of both gdal and rasterio you get with your fresh install (if they are not the latest) ?

@giswqs
Copy link
Member

giswqs commented Aug 1, 2020

  • libgdal: 3.0.4
  • rasterio: 1.1.5

Here is the complete list of packages and versions with a fresh conda install using the following commands:

conda create -n gee python
conda activate gee
conda install mamba -c conda-forge
mamba install geemap xarray_leaflet -c conda-forge

@estaar
Copy link

estaar commented Aug 7, 2020

Due to GDAL errors I find it easy to decide on the packages you need to install for windows which raise errors like GDAL, Fiona, Rasterio and Geopandas. Then I download them from https://www.lfd.uci.edu/~gohlke/pythonlibs/ . I create a python virtual environment and install them using pip. Then I Install geemap. That way you have a virtual environment ready to go that is even not conda based.

@giswqs
Copy link
Member

giswqs commented Aug 7, 2020

@estaar Thanks for sharing your experience. GDAL is only needed to for this add_raster() function. The default geemap package installation does not install GDAL and rasterio. In this way, most users should be able to install geemap smoothly using either pip or conda.

@giswqs giswqs closed this as completed Aug 23, 2020
@12rambau
Copy link
Member Author

12rambau commented Sep 2, 2020

To keep you updated :
I cannot create virtual env as suggested by @estaar because I work on a cloud based env which has 0 flexibility. So every solution that starts like : "start from scratch" won't even be considered by my colleagues because lots of other app live in this very env.

On this environment, if me (or any other standard user) install a new package, it fallback to the --user installation. By doing so the rasterIo and the GDAL env variable GDAL_DATA were conflicting. I manage to convince my boss to do a normal instalation with a pip install array_leaflet. Now the CRS bug has gone but I still cannot see any image on my map.

Digging into the tmp folder I can see that some files are created in tmp/xarray_leaflet_[hash] they are pairs of .png and .done files but all the .png are empty is it normal ?

@giswqs
Copy link
Member

giswqs commented Sep 2, 2020

Can you try putting the notebook and GeoTIFFs under the same directory? For example, my notebook and datasets are all under the Downloads folder. It works fine. Have you tried your local computer? If it works on your local computer, but not on the cloud-based env, then the issue is probably caused by restrictions on the cloud env. There might be some dependency conflict within the env.

@12rambau
Copy link
Member Author

12rambau commented Sep 2, 2020

As you suggested I've put both the geoTiff (there are the same as yours as i'm only launching the 25th tutorial), unfortunately it didn't change the output.
I get an empty. I added a message because now I don't have any errors displaying in my notebook so catching the problem become ... tricky.

My question is : do you also create in your tmp repository a xarray-leaflet-[hash] folder with .png images and .done files and if you open one, are they the one display on the map ?

@giswqs
Copy link
Member

giswqs commented Sep 2, 2020

Yes, I can open the .png images from the tmp folder. Have your tried out the xarray_leaflet package directly without using geemap? See the examples. The geemap load raster function depends on xarray_leaflet. If xarray_leaflet does not work properly on your cloud env, the geemap load raster function won't work either. Open an issue on the xarray_leaflet repo if needed.

@12rambau
Copy link
Member Author

12rambau commented Sep 3, 2020

thank you. The xarray_leaflet examples raise an exception which will help me to narrow down the problem

@12rambau
Copy link
Member Author

12rambau commented Sep 9, 2020

Ok so after some digging into the rasterio functioning it appears that is not so compatible with gdal python binding :

How did you install rasterio? If you got it with pip install rasterio you will have installed a wheel file that includes GDAL 2.4.4 and data files and which will be incompatible with the GDAL 3.0.4 installed on your system. If that is the case, you should unset GDAL_DATA. Rasterio in the wheel will detect its own data files and does not need GDAL_DATA to be set

which means that every time I want to use xarray_leaflet (based on rasterio) I need to start with

import os 
del os.environ['GDAL_DATA']
import geemap

and there It works

So now everything is in my supervisor hands to make it work on our server

Thank you for your help

@giswqs
Copy link
Member

giswqs commented Sep 9, 2020

@12rambau Thank you very much for taking the time to debug this issue and sharing the fix. I probably would not be able to figure this out myself. I will see if I can improve the function to make it more robust. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants