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)'
1 Answer 1
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– deriham2014年09月15日 15:42:53 +00:00Commented Sep 15, 2014 at 15:42
-
@deriham you should ask a new questionuser2856– user28562014年09月16日 00:20:23 +00:00Commented Sep 16, 2014 at 0:20