Hi Andreas, I don't know if it is the best way for doing it, but I generally add the current feature and the current layer as input parameters of the custom function:
def my_function(layer_name, curr_feat, feature, parent): They are set as inputs in this way when calling the custom function: my_function(@layer_name, $currentfeature) Then, I can simply call the current layer and the current feature inside the function in this way: layer = QgsMapLayerRegistry.instance().mapLayersByName(layer_name)[0] geom = curr_feat.geometry() For a better understanding, you may also have a look to my recent answer on this question on GIS Stack Exchange [0]: [0] https://gis.stackexchange.com/questions/235014/increasing-marker-size-based-on-number-of-points-at-same-location-in-qgis I hope that helps. Best regards, Marco 2017-05-05 10:45 GMT+02:00 Neumann, Andreas <[email protected]>: > Hi, > > If one creates a custom python expression, one gets a reference to the > "feature" and the "parent". > > Question: what is "parent" referring to? What object type is it? > > Is it somehow possible in the Python script to get a reference to the > layer the feature is part of? Would there be some example Python code > around that shows how one can get access to the layer the feature belongs > to? > > Thank you for any hints, > > Andreas > > > _______________________________________________ > QGIS-Developer mailing list > [email protected] > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer >
_______________________________________________ QGIS-Developer mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
