I am trying to create a script that will take selected features from one layer and search for the specified attributes related to a column name. in my case 'id'. What I am having trouble doing right now is writing the script to tell qgis to take the selected 'id''s and write them to a new attribute table under a specified field. Below is my current script.
from qgis.gui import QgsMapTool print 'imported' iface.showAttributeTable(iface.activeLayer()) print 'Attribute table shown' # define variables layer = iface.activeLayer() feature = layer.getFeatures() selection = layer.selectedFeatures() # prints the number of attributes the user selected. print len(selection) # for loop to identify trail_stuctures from attribute table for feature in selection: print feature['id'] output_file = open('c:/Users/Pulse3/Desktop/plugin.txt', 'w') # Writing selection id's to a text file stored on the desktop for selection in layer.selectedFeatures(): line = '%s\n' % (selection['id']) unicode_line = line.encode('utf-8') output_file.write(unicode_line) output_file.close()
The above script is only one of the two scripts. Right now the user has to click on the layer through the layer panel. manually go into the attribute table, and use the select feature tool to select a series of lines. ( which are my spans.) Only the selected lines are used in this script.
Ultimatly id like the script to be able to look at seleced features in one layer and Write the 'id' into a standalone table. then switch to another layer and look at the user selected features of another layer and do the same thing.
Both layers will have a selection done based on a user selected features with the mouse.
Both layers will also need to be able to take the returned attribute values list and write it into two different field within a seperate stand alone table.
Essentially I am designing fiber internet drop maps and we may have service points which are houses. that each have a unique ID number and then the spans which are lines off the main backbone fiber line that also have unique id's. both of these features are in their own layers.
I am trying to write a script that allows me to extract just the Id from the service point and then the user selected spans and fills in new geometry attribute table with the same service point id for each of the spans that feed the service point and then the span id for each of the span ids that service the service points.
Is there a way to do this in QGIS?