I have a set of data as polygons, each with a Number field with value X. Is there then a way to copy this into X number of polys at the same location? (ideally points distributed across the poly but that's a bonus).

In QGIS I have tried Random Points, but this doesn't inherit attributes, and Join Attributes by Location is useless if the parent polys overlap.

The reason behind this is for collating data easily with the GroupStats plugin.

  • I think it is answered at gis.stackexchange.com/questions/25709/…
    – SIslam
    Jul 27 '15 at 13:03
  • I looked at that and have tried split by attribute, but it's not what I require. I need each feature copied a number of times equal to a field value, not split into parts.
    – Koozer
    Jul 27 '15 at 14:17
  • Because the same problem, i digged into R to get a solution. I'm sure this can be done with Python as well, but I new R beforehand. This worked for me with modifications gis.stackexchange.com/a/108139/8202
    – Bernd V.
    Jul 27 '15 at 14:28

It's quite easy to do with a small python script. You can paste the following snippet to the python console. To initialize the layer variable you can select it in the TOC and run layer = iface.activeLayer() befor running the code.

for f in layer.getFeatures():
    # Create X-1 new features since we already have the original
    for i in range(f['X']-1):

Or to write it to another layer (make sure it has the same attributes and geometry type!):

for f in lsource.getFeatures():
    for i in range(f['X']):
  • Wow, nice and short. But wouldn't it be better to create a new layer instead of altering the original data. Things can always go wrong ...
    – Bernd V.
    Jul 27 '15 at 16:20
  • You are right of course, it's a minimal change. I tried to keep the manual steps (adding another layer) to a minimum. Jul 27 '15 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.