Using Point in Polygon in Modelbuilder

1019
2
02-16-2011 06:29 PM
MikeMacRae
Occasional Contributor III
Hello,

I have been researching ways to count points in polygons and the obvious answer is to use Hawthe's Tools. I have downloaded it, and it works perfectly. My new ambitious task is to create a simple model to calculate some fields in an attribute table. I also want to put this point in polygon geoprocessing task as part of my model. Is there any way to do this? i.e. add the Hawthe tool into the model or is there another geoprocessing task that can handle this?

Thanks,
Mike
0 Kudos
2 Replies
curtvprice
MVP Esteemed Contributor
Hello,

I have been researching ways to count points in polygons and the obvious answer is to use Hawthe's Tools. I have downloaded it, and it works perfectly. My new ambitious task is to create a simple model to calculate some fields in an attribute table. I also want to put this point in polygon geoprocessing task as part of my model. Is there any way to do this? i.e. add the Hawthe tool into the model or is there another geoprocessing task that can handle this?

Thanks,
Mike


I'm guess all of Hawth's tools are accessed from a point and click interface, not in a toolbox. In that case you're out of luck.

However, you can count points in polygons by running the Identity tool and piping its output into the Summary Stastistics tool. You can then use Add Field and Add Join and Calculate Field to copy the counts to your table.
0 Kudos
MikeMacRae
Occasional Contributor III
Thanks for the response. I came up with a python script to do this. For those who are interested, it goes something like this:

  

# Converts unselectable feature class into a selectable feature layer
gp.MakeFeatureLayer(POINT,"point")
gp.MakeFeatureLayer(POLYGON,"polygon")

rows = gp.SearchCursor("polygon")
row = rows.Next()

gp.AddMessage("Calculating Points in Polgons...")

# Loop through each row and count the points in each polygon record
while row:
       
        # Select each record inside of the polygon feature class    
        SelPoly = gp.SelectLayerByAttribute("polygon", "NEW_SELECTION", "\"OBJECTID\" =" + str(row.OBJECTID))
        #gp.AddMessage(row.OBJECTID)
            
        # Select all the point that are inside of the polygon record
        SelPts = gp.SelectLayerByLocation("point", "WITHIN", SelPoly, 0, "NEW_SELECTION")
        
        # Count the points that are in each polygon
        GetCount = gp.GetCount_management(SelPts)
        
        # Calculate the ASSOC_PTS field with the counted points
        gp.CalculateField_management("polygon", "ASSOC_PTS", GetCount, "VB", "")

        # Move to the next row   
        row = rows.Next()
0 Kudos