mercredi 28 janvier 2015

How can I count point shp inside a polygon shp using Python?


This is my first time here, so I'll try to be as specific as I can.


What I'm trying to do is found out which polygon contains the most points and write the result in a text file.


Here is my script : (tab25Select are the polygons and chefLyr are the points)



chefLyr = arcpy.MakeFeatureLayer_management(cheflieuIN, "chefLyr")

with arcpy.da.SearchCursor(tab25Select, ["Numero", "Name"]) as rows:
for row in rows:
chefTab25Max = 0
chefTab25 = arcpy.GetCount_management(arcpy.SelectLayerByLocation_management(chefLyr, "WITHIN", tab25Select))
arcpy.AddMessage(cheflTab25)
for chf in cheflTab25:
if chf > chefTab25Max:
chefTab25Max = cheflTab25
a = row[0]
b = row[1]

ficTxt.write("\r\n The polygon containing the most point is :{0}".format(chefTab25Max))



ficTxt.close()


If anyone can help :)





Aucun commentaire:

Enregistrer un commentaire