I need to calculate D-Infinity Flow Direction on my input raster (geotiff). I use pygeoprocessing for this. Since I uninstalled the version that I had (0.2.2) and installed a newer version of the python package (0.4.4), I've not been able to calculate flow direction using pygeoprocessing.routing.flow_direction_d_inf module. I get the error message "AttributeError: 'NoneType' object has no attribute 'GetProjection'" which I am assuming means that it wasn't able to load the input image to get it's attributes.

This is what I type in at the Python Idle GUI:

>>> import os
>>> import sys
>>> import pygeoprocessing
>>> import pygeoprocessing.routing
>>> from osgeo import gdal
>>> pygeoprocessing.routing.flow_direction_d_inf('C:\\Projects\\data\\work\\DemPrime.tif', 'C:\\Projects\\data\\work\\DIFD.tif')
  File "C:\Python27\ArcGISx6410.1\lib\site-packages\pygeoprocessing\routing\routing.py", line 331, in flow_direction_d_inf
    elevation_raster_path_band[0], target_flow_direction_path)
  File "src\pygeoprocessing\routing\routing_core.pyx", line 711, in pygeoprocessing.routing.routing_core.flow_direction_inf (src/pygeoprocessing/routing\routing_core.cpp:12951)
  File "C:\Python27\ArcGISx6410.1\lib\site-packages\pygeoprocessing\geoprocessing.py", line 979, in get_raster_info
    raster_properties['projection'] = raster.GetProjection()
AttributeError: 'NoneType' object has no attribute 'GetProjection'

Has anyone else run into problems when upgrading pygeoprocessing?


I did get a response from Richard Sharp (the creator of Pygeoprocessing) . . .

Hello! Yes, there has been a significant non-backwards compatible change to the PyGeoprocessing API. One aspect of that is to make PyGeoprocessing band-aware. In the previous version PGP assumed all raster paths were single band rasters. Now all raster inputs are specified as path/band tuples, where the band starts indexing from 1. (Except those we haven't refactored yet).

And sorry, in most cases in PGP we've added significant checking for that structure, but the routing package isn't one we've spent a lot of time with yet. It is scheduled for the 1.0 release.

In your case, can you try pygeoprocessing.routing.flow_direction_d_inf(('C:\Projects\data\work\DemPrime.tif', 1), 'C:\Projects\data\work\DIFD.tif') and see if that resolves your issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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