I have a shapefile with 5,000 city points. I need to populate a new field, "cls_pop", based on each cities population, so that cities with a population > 2,000,000 will have "cls_pop" = 1, cites with a population > 1,800,000 and < 1,600,000 = 2 and so on and so on. I know there are a lot of different ways to accomplish this and I think I have really confused myself reading to much. I want to write this as a arcpy script so I can change out the variables and use it on different fields but I'm unsure of the best way to go about this. I wrote this but it just places "1" in each row of pop_class.
city_points = "C:\\Desktop\\citypoints.shp"
cursor = arcpy.SearchCursor(city_points,"", "", "population")
for row in cursor:
if row.getValue(cursor) > 2000000:
arcpy.CalculateField_management(city_points, "cls_pop", '"{0}"'.format(1), "PYTHON")
if row.getValue(cursor) > 1800000 and row.getValue(field) < 2000000:
arcpy.CalculateField_management(city_points, "cls_pop", '"{0}"'.format(2), "PYTHON")
ect……………….
Am I on the correct track or is there a better way for me to do this?
row.getValue(cursor)
berow.getValue("pop_class")
row.population
.getValue(field_name)
takes a field namecursor
is not a field ref help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…cls_pop
arithmetically. This can be done in one simple field calculation. Although the description in the question seems confused (it skips from the interval [2000000, Infinity] to [1600000, 1800000]) it likely is intended to equalmax(1, 11 - int("population"/200000))
, which assigns 1 to [2000000, infinity), 2 to [1800000, 2000000), 3 to [1600000, 1800000), and so on, down to 11 for [0, 200000).