0

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

5
  • 2
    Could 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
    Apr 29, 2015 at 13:52
  • 1
    Drop 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
    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. 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
    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
    Apr 30, 2015 at 12:57

1 Answer 1

1

Eventually, I find some sort of solution, an adaption after the very brilliant solution for adding ranks found here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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