I have a cluster of points as seen below from a shapefile layer.
I need an automated procedure (in PyQGIS or any) of filtering out those points that are outside or further-away from the center of the clustered points, by creating a new attribute field for the shapefile layer.
The output would be the same shapefile but with an added field (named "Outlier"), where all the outliers points will be marked with a "1" and the rest with a "0".
That is the points in red circle will have value of "0" while those outside the red mark will have the value of "1".
from PyQt4.QtCore import QVariant point_layer = iface.activeLayer() data_provider = point_layer.dataProvider() count_ft = data_provider.featureCount() # Create Outlier attribute field data_provider.addAttributes([QgsField("Outliers", QVariant.Int)]) point_layer.updateFields() # Get points average coordinates features = point_layer.getFeatures() for f in features: #calculate average xy coordinate pass # Buffer from average xy coordinate to get outliers # update "outlier" attribute field ## if point in buffer, update with 0 else update 1