Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a point feature class with a count field associated with each of the points.

I would like to create a new feature class where each of the points are duplicated by the value of the count field, so that rather than being an aggregate count, they represent individual events (I need to run a Monte Carlo on them so individual events are required).

Does anyone have any idea how to do this in ArcGIS for Desktop?

share|improve this question
    
Easy as! Is the count 1 based i.e. count=1 is 1 point, count=2 is 2 points? What happens to count=0 (or are you positive there are no count=0) –  Michael Miles-Stimson Sep 3 at 0:15
    
Yes - it's all integer based, ranging from 1 to a few hundred! I'm trying to find an easy way to simply explode the points out –  Xavier Goldie Sep 3 at 0:17
    
Thank you, any assistance would be greatly appreciated! I've been puzzling over it for a while now... –  Xavier Goldie Sep 3 at 0:33

1 Answer 1

up vote 2 down vote accepted

I'm using the old (not da) cursors. I'm sure there are quicker ways using the arcpy.da cursors but I'm more familiar with the old style..

import sys, arcpy

InFeatClass = sys.argv[1]
OutFeatClass = sys.argv[2]

# overwriting output is ok.
arcpy.env.overwriteOutput = True

# copy the count = 1 features to create a new feature class, saves having to do
# new feature class, copy spatial reference and fields..

arcpy.Select_analysis(InFeatClass,OutFeatClass,"count = 1")

# setup cursor objects - search the source, isert the destination
InsCur = arcpy.InsertCursor(OutFeatClass)
SrchCur = arcpy.SearchCursor(InFeatClass,"Count > 1")

# get the list of fields to copy
FieldList = arcpy.ListFields(InFeatClass,"*")
NoCalcFields = ["FID","OBJECTID","SHAPE"]

for InRow in SrchCur:
    # create a range and then iterate over it
    # inserting a new row for each count
    CountRange = range(InRow.count)
    for indx in CountRange:
        newRow = InsCur.newRow() # create a new (empty) feature

        # copy values from the source to the destination
        for ThisField in FieldList:
            if ThisField.name.upper() not in NoCalcFields:
                newRow.setValue(ThisField.name,InRow.getValue(ThisField.name))

        # copy the shape
        newRow.setValue("SHAPE",InRow.getValue("SHAPE"))

        # Store it
        InsCur.insertRow(newRow)

Have a read of http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00150000001r000000.htm if you have trouble making this a tool. I ran it on command line and it worked just fine!

share|improve this answer
    
Thank you so much this worked absolutely perfectly! –  Xavier Goldie Sep 3 at 4:17
    
You're welcome. Hopefully there are some gems in there that you can refer to later in future scripts. –  Michael Miles-Stimson Sep 3 at 4:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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