I have a plugin which finds buffer for list of cities, provided the distance. The state and city names are taken from the attribute table and gets filtered accordingly. What I want is My plugin should identify the layer name or order of the layer in canvas,irrespective of other layers present in the canvas and access the corresponding attributes from that layer.
I am also just curious whether pointing a specific layer name in code would cause any error in iteration though some other layers are present?
Below is my code please tell me where should I make changes and what would be the change?
if dist and centerCity: #QMessageBox.information(self.dlg, "info", "both True") st = '"name" = \'' + centerCity + '\'' exp = QgsExpression(st) else: QMessageBox.warning(self.dlg, "Enter the distance","Enter the distance and try again.") return #terminate the function layer = self.iface.activeLayer() it = layer.getFeatures(QgsFeatureRequest(exp)) feature = it.next() mbuf = feature.geometry().buffer(dist, 2) iterFeat = layer.getFeatures() for f in iterFeat: geom2 = f.geometry() valTest = QgsGeometry.within(geom2, mbuf)