1

I would like to extract raster values at some locations (point shapefile) in 'csv' format. I use 'Point Sampling Tool' and it works well for a raster file. However, I have hundred of raster files (rainfalls) which need batch process to work on extracting the raster values.

I have tried 'Extract raster values (CSV)' in the processing tool but the error message pops up (Error executing algorithm 1 'Dataset' object has no attribute 'mapToPixel' See log for more details). Both vector and raster files have the same projection (WGS84). I already add 'mapToPixel' attribute in the point shapefile but the error still exists.

Error message from 'Extract raster values (CSV)'

0

It's a bug in the script.

To workaround, edit [qgis install dir]/python/plugins/processing/script/scripts/Extract_raster_values_to_CSV.py (not sure of exact path, I run QGIS on Linux) and replace line 88:

        (rX, rY) = raster.mapToPixel(x, y, geoTransform)

With:

        (rX, rY) = mapToPixel(x, y, geoTransform)

The problem:

The mapToPixel function is defined in the processing.tools.raster module which is imported into the local namespace by the Extract_raster_values_to_CSV.py i.e from processing.tools.raster import *

The script then tries to use the function, but it prefixes the raster module namespace, but the raster module wasn't imported, only the functions defined in the module were. Additionally, a raster variable was set to a gdal.Dataset object on line 14 of the script.

Edit: issue reported at the QGIS Bug Tracker.

  • I try to run batch process to extract raster to CSV once I corrected the bug. But it always stops at the 13th iteration (no matter I change the different raster input). Many thanks. – deriham Sep 15 '14 at 15:42
  • @deriham you should ask a new question – user2856 Sep 16 '14 at 0:20

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.