Qgis layer renaming stays the same

المشرف العام

Administrator
طاقم الإدارة
I've been developing a plugin for Qgis, but something weird happend while renaming a layer, now whenever i add a layer using a button in my plugin, the layer is renamed with the last name I gave it. I'll explain it using an example.

The plugin creates a buffer around some points and creates a temporary layer to store these buffers. I programmed the buffer_layer to have the name 'buffer_{}'.format(current user) (where current_user is a variable which I tested to be right).When the layer is loaded however, it will have the name "Buffers". I remember changing the name once to Buffers, and it seems as if Qgis remembers this change and applies it to all layers created by the plugin. I can change the name of the layer using right mouse click > rename and rename it to 'testname' and delete it afterwards. If I then add a new buffer layer using the plugin, the layer will have the name 'testname'.

This keeps happening and is really annoying.It might not be the clearest explanation, any help would be really appreciated! If more information is required, tell me!

I'm on OS X El Capitan, using Qgis 2.12 Lyon.

Edit: Added code

def calculateBuffer(self): proj = QgsProject.instance() cur_user = self.SelectUserGroupCombo.currentText() # The current user is selected using a drop down menu. radius = proj.readNumEntry("SpatialDecisionDockWidget", "radius")[0] transittypes = proj.readEntry("SpatialDecisionDockWidget", "transittypes")[0] uf.selectFeaturesByExpression(self.getSelectedLayer(),"network in {}".format(transittypes)) origins = self.getSelectedLayer().selectedFeatures() layer = self.getSelectedLayer() if origins > 0: cutoff_distance = radius buffers = {} for point in origins: geom = point.geometry() buffers[point.id()] = geom.buffer(cutoff_distance,12) # store the buffer results in temporary layer called "Buffers_[cur_user]" buffer_layer = uf.getLegendLayerByName(self.iface, 'Buffers_{}'.format(cur_user)) # create one if it doesn't exist if not buffer_layer: attribs = ['id', 'distance', 'network'] types = [QtCore.QVariant.String, QtCore.QVariant.Double, QtCore.QVariant.String] buffer_layer = uf.createTempLayer('Buffers_{}'.format(cur_user),'POLYGON',layer.crs().postgisSrid(), attribs, types)The layer is renamed here!

buffer_layer.setLayerName('Buffers_{}'.format(cur_user)) uf.loadTempLayer(buffer_layer) # insert buffer polygons geoms = [] # geometries in a list values = [] #list of lists, consisting of 3 items. E.g. [[0L, 1200, 1],[... fld_values = uf.getFieldValues(layer, 'network', True,"network in {}".format(transittypes))[0] cnt = 0 for buffer in buffers.iteritems(): # each buffer has an id and a geometry geoms.append(buffer[1]) # in the case of values, it expects a list of multiple values in each item - list of lists values.append([buffer[0],cutoff_distance, fld_values[cnt]]) cnt += 1 uf.insertTempFeatures(buffer_layer, geoms, values) self.refreshCanvas(buffer_layer) layer.removeSelection()The code might be complicated, if any explanation is necessary, ask! :)



أكثر...
 
أعلى