1

This question already has an answer here:

I’m new to ArcMap and was wondering if anybody could help me out. I have a shapefile with counties and wells in that county. In the table I’m trying edit it so that for each county calculate the total numbers of wells that fall into that county, and update the county table with the total count. I also want to calculate how many wells there are per area unit, and update the table with that value as well.

import arcpy
featureClass = "C:/Lesson5_Data/Colorado_cities.shp" fieldList = "*"

with arcpy.da.SearchCursor(featureClass, fieldList) as cursor:
for row in cursor:
print row[4

population = 10000

whereClause = '"POP2007" >= ' + str(population

marked as duplicate by PolyGeo Jul 14 '16 at 2:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    re-edit your code. indent 4 spaces before you type out your code – ziggy Apr 21 '16 at 18:23
  • What happens when you run the code snippet that you have presented? It looks like a copy/paste of something you found somewhere else rather than something that you have written to try and solve your own problem. – PolyGeo Jul 11 '16 at 4:32
  • 1
    @ziggy Highlighting code and then clicking the format button {} is much easier. – PolyGeo Jul 11 '16 at 5:26
  • Brett did you solve this assignment? I am having the same issue with it and I need to get some help. Thanks – goyo Jul 13 '16 at 17:37
  • 1
    This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review – MaryBeth Jul 13 '16 at 19:46
3

You want to use an UpdateCursor, not a SearchCursor to make any edits to the table:

A search cursor can be used to retrieve rows. An update cursor can be used to positionally update and delete rows, while an insert cursor is used to insert rows into a table or feature class.

1

You could probably do this with update cursors, but it might be faster to do a count tool, followed by a density tool.

In Spatial Analyst (if you have the license):

Point Density

Calculates a magnitude per unit area from point features that fall within a neighborhood around each cell.

As for generating the count field you could do this: http://support.esri.com/en/knowledgebase/techarticles/detail/30779

If you really want to use cursors then you'll probably have to do a search cursor on an intersect to a point output first. (with this blow away the fields of your feature that don't relate to what the id of the polygon which it falls inside is, that way you'll have a field with an ID which differentiates which polygon each one falls into)

The first search cursor could be used to create your base data (you could create a tracking variable for each polygon that you encounter and iterate to add the number of features inside every time you process a row). Then an update cursor to write the data. Possibly you could do it all with an update cursor, too.

I'll visit it more if you'd like but that should get you started if you know how to script with cursors.

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