While figuring out what I have to do, practically creating a field for each arrondise, and in each, rank each FID (which are part of the respective arrondise) by the size of its shape area.
Hopefully, it is a bit clear now.
EDIT Currently, trying to rank each row which is part of a certain arrondise (ex. 1, 2) in terms of its shape area.
import arcpy
arcpy.env.workspace = "D:/M1 Geomatique/Programmation II/Dossier"
fc = "zones_rattachement.shp"
try:
fieldRoot = "RANG_R"
for counter in range(1,21):
arcpy.AddField_management(fc, fieldRoot + str(counter),'SHORT')
size_rank = 1
numlist = list(range(1,21))
for num in numlist:
arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", "arrondisse = '%c'")
rows = arcpy.UpdateCursor(fc, sort_fields="shape_area D")
for row in rows:
row.setValue("RANG_R1", size_rank)
size_rank += 1
rows.updateRow(row)
except:
arcpy.GetMessages()
enter image description here
-
2Could you please include a sample dataset (a screenshot of a table will do) including original data and your intended output? I am unclear if you want to rank the features by size and how you want to handle the attribute integers. Additionally, how do you want to identify connecting voting stations?Aaron– Aaron ♦2015年04月29日 13:52:46 +00:00Commented Apr 29, 2015 at 13:52
-
1Drop your try/except or add a print in the except. The way you're approaching it will actually hide what the exception is. That said, your code should actually work, so my hunch is that your input doesn't exist. Maybe you left of a file extension? .shp?DWynne– DWynne2015年04月29日 19:11:42 +00:00Commented Apr 29, 2015 at 19:11
-
His code tries to add (or even adds; I can't spot any issues) long integer fields RANG_RAPPORT1, RANG_RAPPORT2, ..., RANG_RAPPORT20. That's all. It can be done manually, faster. Seems that his question (using boolean and logic) is far more complex than the code.Remigijus Pankevičius– Remigijus Pankevičius2015年04月29日 20:01:53 +00:00Commented Apr 29, 2015 at 20:01
-
Quite a good observation, as I mentioned...my code doesn't do much as of now. Missing the extension, and I'll remove the try and except and see what happens.Geosphere– Geosphere2015年04月29日 21:03:37 +00:00Commented Apr 29, 2015 at 21:03
-
Made some minor modifications but nothing too important. I still can't figure out why is it not adding ranks in the proper fields.Geosphere– Geosphere2015年04月30日 12:57:35 +00:00Commented Apr 30, 2015 at 12:57
1 Answer 1
Eventually, I find some sort of solution, an adaption after the very brilliant solution for adding ranks found here.