ie.geologyidea.com
More

Map on canvas renders after image saving

Map on canvas renders after image saving


We are searching data for your request:

Forums and discussions:
Manuals and reference books:
Data from registers:
Wait the end of the search in all databases.
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.



Comments:

  1. Akinosho

    Sorry for my intrusion… I understand this question. He is ready to help.

  2. Eadbert

    Let's know! Thank you for the news.

  3. Charro

    You commit an error. I can prove it. Write to me in PM, we will communicate.

  4. Julkree

    There is something in this. Thank you very much for your help with this issue.

  5. Hnedy

    Flat customer nothing.

  6. Karcsi

    Somewhere I have already seen this ... And if on the topic, thanks.

  7. Bakree

    Bravo, I think this is a different sentence



Write a message