I have a point feature class with a Count field. I want to copy each feature in the feature class a number of times based on the number in the Count field. For example, if a feature has a Count value of 6, I want six new features created with all the same attributes as the original feature.
All the iteration model tools I can find want to group features based on an attribute value, but I want the number of iterations to be equal to the numeric value in my Count field.
Thanks
Solved! Go to Solution.
Hey Xander Bakker, This works like a charm as long as I don't have the workspace feature class open in the Table of Contents. Thank you so much! Python is our friend.
(This post is edited with a strikethrough of text as I was unable to replicate the error)
Hi Ethan Duke ,
Can you explain what you mean with that it doesn't work when have the featureclass open in the TOC? I suppose you mean the output featureclass and you want to overwrite it? I just did a test with the input featureclass in the TOC and it works without problems on my computer:
When running it just works (when a new output is created):
I'm unable to recreate the error. I had run the tool unsuccessfully with the original feature class open in the Table of Contents. I ran the tool again with the layer removed and it was successful. I must have been incorrect in assuming the error was caused by lock issue. It is working well. Mine works just as yours (above screenshots). I'm surprised at how quickly it runs.
Hi Xander,
I have run the code and the geoprocessing tool and I am having the following error message
Runtime error
Traceback (most recent call last):
File "<string>", line 24, in <module>
File "<string>", line 21, in main
TypeError: value #7 - unsupported type: tuple
Any ideas on how to solve this?
Thanks!
Hi Amelia7 ,
If you can share the code you used and (a sample of) the data used I can track where things are going wrong.
Hi Xander,
Thanks for your response.
The code that I am using is as follow:
>>> def main():
... import arcpy
... import os
... fc_in = r"F:\Code.gdb\Data2" # this one exists
... fld_count = "No_Adress"
... fc_out = r"F:\Code.gdb\Points_out" # this one will be created
... sr = arcpy.Describe(fc_in).spatialReference
...
... # create the empty output featureclass
... path, name = os.path.split(fc_out)
... arcpy.CreateFeatureclass_management(path, name, "POINT", fc_in, "SAME_AS_TEMPLATE", "SAME_AS_TEMPLATE", sr)
...
... # insert the features into the output fc
... with arcpy.da.SearchCursor(fc_in, '*') as curs_in:
... flds_in = curs_in.fields
... idx_cnt = flds_in.index(fld_count)
... with arcpy.da.InsertCursor(fc_out, '*') as curs_out:
... for row in curs_in:
... cnt = row[idx_cnt]
... for i in range(0, cnt):
... curs_out.insertRow(row)
...
... if __name__ == '__main__':
... main()
...
Runtime error
Traceback (most recent call last):
File "
Hi Amelia7 ,
Thanks for sharing your code, but can you also share (a sample of) your data?
Hi @SethPaine1
I am having the same issue with trying to duplicate polygons. Just wondering did you ever get the script to work or did you go with the access approach?
@XanderBakker the tool box to house the script is brilliant and make it so easy to use. It should be added to ArcGIS produce going forward as seen a lot of people doing the manual approach to this.
I am having the same issue as @SethPaine1 with polygons not plotting i.e. no "shape_area" or "shape length" (but appearing in attribute table correctly). I am running ArcGIS Pro version 3.3.0.
Is there something I need to change to allow the script to run polygon or change to allow run in ArcGIS Pro version 3.3.0?
Thanks in advance
I did develop a terribly tedious work around (I am not skilled in python). I first exported my points to a personal geodatabase. Then, using Access, I followed the process I found here within the personal geodatabase:
Creating duplicate rows - microsoft.public.access.queries
I created a table [tblNums] with a single numeric field [Num] and values from 1 to the maximum quantity (1-102 in my case).
Then I created a a make-table query of my current table and tblNums (do not link the two tables). I set the criteria
under the [Num] field to:
<=[Count]
This created a number of duplicate records for each original record equal to the number in my original Count field.
I then imported the table into ArcMap, and exported as a new table to give it an OID field. Then I took my original point feature class and populated two coordinate fields. Next I joined my original feature class point data table to my new table with replicas (based on a Unique ID). I then created two coordinate fields in my new table and copied the coordinates from the origin table. Then I removed the Join. Lastly, I projected my new table with duplicates based on the coordinate data.
It did work, and now I have my original point data with duplicate overlaying features based on the number in my count field. But I wouldn't want to incorporate this process into a regular work flow.
I guess the code I provided earlier represents a slightly simpler way to duplicate the points...