Map on canvas renders after image saving

We are searching data for your request:
Upon completion, a link will appear to access the found materials.
I'm a beginner to Qgis and Python; i need a script (don't need it to be a plugin) to get maps of selected features from a layer satisfying certain conditions; Here is my code:
from qgis.gui import * from PyQt4.QtCore import * from PyQt4.QtGui import * import time fnam ='C:/Users/User/.qgis2/Test/Output/' canvas = qgis.utils.iface.mapCanvas() #print canvas.size() Nom =QInputDialog.getText(None,"Value", "Enter text",0) fnam2 = fnam + Nom[0] + '.txt' #print fnam2 outfile = open (fnam2, 'w') layer = iface.activeLayer() layer.setSelectedFeatures([]) #provider =layer.dataProvider() selection=[] for f in layer.getFeatures(): n1 = f['Comune_1'] n2 = f['Comune_2'] n3 = f['Comune_3'] n4 = f['Comune_4'] n5 = f['Comune_5'] if (n1 == Nom[0]) or (n2 == Nom[0]) or (n3 == Nom[0]) or (n4 == Nom[0]) or (n5 == Nom[0]) : selection.append(f.id()) line = '%s
' % (f['link']) unicode_line = line.encode('utf-8') outfile.write(unicode_line) layer.setSelectedFeatures(selection) #provider.select() outfile.close() mnam ='C:/Users/User/.qgis2/Test/Output/' + Nom[0] + '.tif' mnam2 ='C:/Users/User/.qgis2/Test/Output/' + Nom[0] + '.png">
now professionals or village administrators may ask for orthophotos of a specific village; running my script i wish:
- have a list of orthophotos of that specific village (this works fine with txt file i create);
- give a map showing the arrangement of requested orthophotos as a complementary aid.
Now, if i run the script selecting, say, "Potenza", i eventually can see in Qgis the updated map with desired selection, but saved images show the whole region:(I mean "Potenza.png">
(tif images are identical to png);
(When i'll have a working script selected "rectangles" will show image name, and i won't use inputdialog but i'll get village names from the first shapefile and run it only once for all villages).
I don't understand your problem.
1) You create a text file with the selected features id
layer = iface.activeLayer() # you select all the features with nom in one of the 5 fields selection = [f.id() for f in layer.getFeatures() if nom in [f['Comune_1'],f['Comune_2'],f['Comune_3'],f['Comune_4'],f['Comune_5']]] # then you write in a text file the link field of the selected features with open(newfile, 'w') as outfile: for f in layer.getFeatures(): if f.id() in selection: # the default format is unicode outfile.write('%s
' % (f['link']))
2) After you save the canvas showing the selected features
# select the features layer.setSelectedFeatures(selection) canvas.zoomToSelected() # save the files canvas.saveAsImage(mnam,None,'TIF') canvas.saveAsImage(mnam2,None,"PNG")
And it works without problem.
Sorry for my intrusion… I understand this question. He is ready to help.
Let's know! Thank you for the news.
You commit an error. I can prove it. Write to me in PM, we will communicate.
There is something in this. Thank you very much for your help with this issue.
Flat customer nothing.
Somewhere I have already seen this ... And if on the topic, thanks.
Bravo, I think this is a different sentence