Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there any way we can select top 500 values in attribute table? I tried by sorting area field ascending/descending... but I can't count big numbers to select. In microsoft excell we can do know, similarly in arcgis, is there any code to keep in attribute selection ??

share|improve this question

3 Answers 3

up vote 1 down vote accepted

A non-programmable way to do this would be to sort your table as you have done, and then just go directly to the nth record that you want (by manually typing the value at the bottom of the attribute table). Once you get the field value for the nth value, just do step 4 in dklassen's first post.

share|improve this answer

I think this logic should work.

Step 1. cursor through the table and populate an array of the AREA values.

Step 2. sort the array by AREA.

Step 3. Find out the 500th largest AREA value.

Step 4. Select the table by attribute where AREA >= the 500th largest value.

share|improve this answer
    
I already mentioned this in my question that I did this. But how can we count very big numbers like "5896" from the attribute table? Its a hectic task. So I want a code or logic to include in attribute table so that I can avoid counting rows... it should be generic value may be 10,50,4567 or 339877.... –  Dr. A.D.Prasad Jul 6 '12 at 4:55

Perhaps I don't understand your question, but I am not sure why you are counting these values. Let your script do that.

e.g. In python

import arcpy

myarray = []

cur = arcpy.SearchCursor("MYSHAPEFILE")

for row in cur:

        myarray.append(row.SHAPE_AREA)

mysortedarray = sorted(myarray)

value500 = mysortedarray[-500]

Then you can select by attribute using this value.

share|improve this answer
    
Thanks for response. I really need your help in this to implement in arcgis 9.3/10 and check as I am very poor in programming. My aim is to select my attributes which are "top XXXX" (any number). –  Dr. A.D.Prasad Jul 6 '12 at 5:18
    
The above should work - simply replace the shapefile name and 500 number with your values and then add the arcpy.SelectByAttribute_management() syntax and you should get your answer. –  dklassen Jul 6 '12 at 5:21
    
Be careful with the above code, it wont work because the last two lines have an extra space in front of them. They shouldn't be indented. I would have edited it, but SE wont let me make edits which are less than 6 non-space characters. –  Fezter Jul 6 '12 at 6:13
    
I fixed the indentation - this forum is not the best for typing out code. But anyways, this is just an example of what can be done, not necessarily the best/most efficient way. –  dklassen Jul 6 '12 at 15:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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