I would like to split a shapefile made up of approximately 8200 elements into five having an equal number of elements. I don't want to base this division on an attribute. There is a simple way to do that in QGIS?
-
1What geometry type? What's the spatial distribution (clustering?) of the features? Can you add a screenshot?– BabelJun 2, 2021 at 17:13
-
Thank you for your attention. The records have a point geometry. I don't care about the geographic relations amonst them. For me it is ok just to select the first 8474/5 elements, then another group of equal number, ect.ect. I tried to do it manually, but it is very hard and not efficient. The problem is working with the "selection by expression" function, I think. I can select by field, but as I mention, existing fields do not help me.– Geo_itJun 2, 2021 at 17:21
-
Please use the edit button beneath your question to revise it with any requested clarifications.– PolyGeo ♦Jun 3, 2021 at 3:21
1 Answer
You can create a new attribute field which bins the 8474 elements into 5 bins:
bin_size = 8474/5, or approx. 1750 elements per bin.
Go to field calculator and generate a new integer field called 'bin' with this expression:
ceil(@row_number/1750)
If you want it to be more dynamic, you can do this, which uses the size of the table as a parameter for the number of elements per bin. Replace 'fid' with the name of a different field if your table doesn't have a field named fid.
ceil(@row_number/(count('fid')/5))
Then use bin as the field to split by in the Split tool.