Thursday 16 July 2015

python - Hyperlinking in QGIS - Add Data to current window


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.



Answer



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...