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)'

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 14, 2014 at 16:56

1 Answer 1

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.

answered Sep 14, 2014 at 23:51
2
  • 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. Commented Sep 15, 2014 at 15:42
  • @deriham you should ask a new question Commented Sep 16, 2014 at 0:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.