Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am looking to add to my current action in QGIS so that a hyperlinked file will open in the current QGIS window, rather than in a new window. Here is what my action looks like:

"C:/Program Files (x86)/Quantum GIS Wroclaw/apps/qgis/bin/qgis.exe" "C:\Users\Ryan Garnett\Dropbox\SpatialData\Imagery\Landsat\%Image"

I am hoping I can use this as a means to share data so that users can load in satellite images basked on a click with the Hotlinks plugin.

Thanks, Ryan


Thanks Nathan, I tried this, but it did not load the file. It came back with the following error:

C:\Users\Ryan Garnett\Dropbox\SpatialData\Imagery\Landsat8020_nad83_utm_30m_123457.jp2 is not a valid or recognized raster data source

This is what I have written in the action:

qgis.utils.iface.addRasterLayer("C:\Users\Ryan Garnett\Dropbox\SpatialData\Imagery\Landsat\%Image")

With is set to Python. I have noticed in the error that there isn't a \ in between Landsat and the file name, plus the file name has been cut short, from 028020_nad83... to Landsat8020_nad83...

Any thoughts? My other way is still working to load it into a new

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

You can open a layer in the current instance with a bit of python code in the layer action.

qgis.utils.iface.addRasterLayer("C:\Users\Ryan Garnett\Dropbox\SpatialData\Imagery\Landsat\%Image")

switch the action type to Python

Reference for iface object http://qgis.org/api/classQgisInterface.html

share|improve this answer
    
I figured it out. You needed to change all the \ to \\ for Python. qgis.utils.iface.addRasterLayer("C:\\Users\\Ryan Garnett\\Dropbox\\SpatialData\\Imagery\\Landsat\\%Image") –  Ryan Garnett Apr 23 '12 at 17:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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