I am building a plugin for QGIS and want to add a string to a created polygon. In my dialog I was able to create a ComboBox filled with 10 different strings which can be added while creating the polygon. But when I identify this object this information doesn't seem to be stored. Is there a way to connect this information to the layer? Here is what I created until now:

Objects = ['Trees on grass', 'Trees on avenue', 'Grass field', 'Green roofs', 'Cool roofs', 'Facade greening', 'Solar Panels', 'Pond/river', 'Fountain', 'Surface albedo change']

#insert this string in Combobox
self.ObjectType = QComboBox()
object = self.ObjectType.insertItems(0, Objects)

# Add this object feature to layer
for layer in QgsProject.instance().mapLayers().values():
   if 'field=' + self.tr('Drawings') + ':string(255,0)' in layer.dataProvider().dataSourceUri()[-28:]:  # must have its first field named Drawings, string type

Does anyone have a clue to enhance the last part?

  • look at this gis.stackexchange.com/q/223455/49538 – Fran Raga Jul 26 '19 at 8:26
  • 1
    Please clarify your problem or add additional details. As it's currently written, it’s hard to tell exactly what you're asking. What are layerBox and layer.object? A Layer doesn't have any method or property named object. And what do you mean by "connecting this information to the layer"? – Kadir Şahbaz Jul 26 '19 at 9:35
  • The last part needs enhancement. I took these layerBox information from another plugin which connects the name given to the polygon to the layer. I want to do something similar but with predefined strings. The object chosen in object = self.ObjectType.insertItems(0, Objects) should be appended to the active layer, but I don't really know how tbh – Lauzeruz Jul 26 '19 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.