2

I have to check an attribute table field (MY ID NO) of polygon feature against a tiff image of parcel map where fields are written as 12-58,65,87,2565-89999,58648.

Example: Parcel map tiff(image) contains plot no (MY ID NO in poly feature's attribute table) against each plot, each tiff has a corner box that describe the plot numbers included in this tiff map. Now I have to check is all the opposite plot no (collected from tiff image file, and also mentioned in the corner-box describing included plot no) is populated in the MY ID NO field.

Now I want a field calculator script (I think it is easy and better way to check, suggestions also preferred) to populate "Sorted Range" field. I need only "Sorted Range" field. My table as below:

Portion of Attribute Table

7
  • 1
    I'm not certain what your diagram indicates - are you saying that you do not want the first two column values changed and that you want the values indicated written to the third column in the order indicated? If so, I don't think Field Calculator will do it but a Python Script tool would have no trouble.
    – PolyGeo
    Jan 24 '13 at 7:08
  • First column(MY ID NO) is my data input, second column (Range) is unnecessary but shown here to get the idea what i need.I need only third column (Sorted Range)
    – SIslam
    Jan 24 '13 at 9:30
  • Are you wanting to sort first and then drop out all but the first and last members of any consecutive sets of numbers?
    – PolyGeo
    Jan 24 '13 at 9:33
  • yes, first and last for consecutive sets plus single for single member set (e.g. 258 in the image)please see the update of question for scenerio, i want this "Sorted Range" field for checking only, this field will be deleted after check.
    – SIslam
    Jan 24 '13 at 9:55
  • Are you using ArcGIS 10.0 or 10.1? I'm thinking new arcpy.da cursors will work faster than old arcpy cursors - and would prefer to code in 10.1.
    – PolyGeo
    Jan 24 '13 at 10:13
4

Take a look at the Sort tool, which is available at ArcInfo level, it will do exactly what you need/ There are also several other questions you may want to look at which point out issues you might experience when sorting the table.

1
  • @ Arabella, i do not want sorting only, but dropping out the values between ranges(highest-lowest) for consecutive set of three or more then three menmbers and eaxctly the members for set of one &/or two member-sets. The purpose is only for check as specified in the example
    – SIslam
    Jan 24 '13 at 12:38
2

This Python code should do it ...

import arcpy

valueList = []
rows = arcpy.SearchCursor(r"C:\Temp\test.gdb\test")
for row in rows:
    valueList.append(row.MY_ID_NO)
valueList = sorted(valueList)
del row,rows
print valueList

firstValue = valueList[0]
lastValue = valueList[len(valueList) - 1]
prevValue = firstValue
potentialEndRangeValue = firstValue
rangeSize = 0

rangeValueList = []
for value in valueList:
    if value == firstValue:
        # Always print first value
        rangeValueList.append(value)
    elif value == lastValue:
        # Always print last value
        if rangeSize > 0:
            # This is when last Value is NOT end of a range
            rangeValueList.append(potentialEndRangeValue)
        rangeValueList.append(value)       
    else:
        if value - prevValue > 1:
            # This indicates a gap since last value
            if rangeSize > 0:
                rangeValueList.append(potentialEndRangeValue)
            if value != lastValue:
                rangeValueList.append(value)
            rangeSize = 0
        else:
            rangeSize+=1
        prevValue = value
        potentialEndRangeValue = value
print rangeValueList

rows = arcpy.UpdateCursor(r"C:\Temp\test.gdb\test")
row = rows.next()
for rangeValue in rangeValueList:
    row.Sorted_Range = rangeValue
    rows.updateRow(row)
    row = rows.next()

del row,rows
2
  • Thanks PolyGeo, i will try this stand-alone python script.But is there any field calculator method?
    – SIslam
    Jan 26 '13 at 4:58
  • 1
    If there is a way to do it using Field Calculator then I do not know it.
    – PolyGeo
    Jan 26 '13 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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