I am trying to write a python code whose purpose is to open windows directories corresponding to the communes I select in a "common" Shape layer (with Qgis software).
I specify that the common layer contains a column X with the paths to the directories of the communes (example of the path: V: / 02_doc / commune1 /
)
Here is my current code. It does not work as intended (it opens ... the windows directory "'my documents"
import os
X = os.path.dirname( unicode( qgis.utils.iface.activeLayer().dataProvider().dataSourceUri() ) )
os.system("explorer " + "[%"X"%]")
layer = qgis.utils.iface.activeLayer()
qgis.utils.iface.setActiveLayer(layer)
This code is used to indicate a single path and point on when I click on the layer.
import subprocess
layer = iface.activeLayer()
x = layer.source()
subprocess.Popen(r'explorer /select,' + x)
That's not what I want.
`with this code:
import os
X = os.path.dirname( unicode( qgis.utils.iface.activeLayer().dataProvider().dataSourceUri() ) )
os.system("explorer "+posplu)
layer = qgis.utils.iface.activeLayer()
qgis.utils.iface.setActiveLayer(layer)
There is a change, when I click on my layer in Qgis, I point the directory where my layer is.
That's not what I want.
My layer contains an x column. The latter includes paths pointing repertory directories to cities. I would like to click on a city A and open the directory A, on a city B and open the directory B.
I found
import os layer = qgis.utils.iface.activeLayer() import subprocess subprocess.Popen(r'explorer /select r,"[% X %]"')
x is the column containing directory paths fcka