Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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.

share|improve this question
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 interface 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

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.