Sonya Ridden
Sonya Ridden

Reputation: 1

rasterio ImportError when calling osmnx add_node_elevations_raster() function

I am trying to run the example given in Notebook 12 of the osmnx-examples GitHub repo.

I used the provided environment.yml with conda to set up my environment:

conda env create -f environment.yml 

When I try to run this code block:

raster_path = "./input_data/elevation1.tif"
G = ox.elevation.add_node_elevations_raster(G, raster_path, cpus=1)

I get the error

ImportError: rasterio must be installed as an optional dependency to query rasters.

I have tried including rasterio and gdal in the environment yaml, but it I still get the same error message. I have also tried much Googling for solutions but have not found any.

Upvotes: 0

Views: 28

Answers (1)

gboeing
gboeing

Reputation: 6442

There was a bug OSMnx fixed recently where you'd get that "rasterio must be installed" error message if the rio-vrt optional dependency was not installed but you were trying to work with raster files. The initial build of OSMnx 2.0.0 on conda-forge didn't automatically include rio-vrt, but that conda-forge build and the OSMnx ImportError bug itself have both been fixed.

So, any one of the following should fix your issue at this point:

  • install rio-vrt into your environment
  • re-create your conda env with: conda env create -f environment.yml
  • follow the OSMnx installation instructions to create a new environment with any packages you want in it

Upvotes: 0

Related Questions