2

I have an Attribute table with 151823 rows. I want to cut off the upper and lower 5% of the data so I sorted the Value field ascendingly but now I am not able to select the first and the last 7591 entries which would be the 5%, as the FID is not in the right order anymore. I tried it with a new field (NewID) with the intention to just have a new sequential numbering but this did not work. I used the script presented here

Sorting feature class to calculate sequential ID field using ArcGIS Field Calculator?

Does anyone know a simple solution?

3
  • why did the NewID field ordering not work?
    – NULL.Dude
    Commented Nov 20, 2017 at 16:26
  • This looks like a possible duplicate of gis.stackexchange.com/q/262299/115
    – PolyGeo
    Commented Nov 20, 2017 at 19:55
  • You should of use procedure explained in 2nd answer, not what you call script in 1st.
    – FelixIP
    Commented Nov 21, 2017 at 4:28

1 Answer 1

1

I think the best solution is scripting.It's versatile.

Create a new field with "Long Integer" type.I named it to "SecondField".

Row count = 151823

First 5% finished to 7591 row (I rounded it)

Last 5% started from 144232 row

In this code set your workspace. example:

arcpy.env.workspace = "D:/test.gdb"

Set Layer name after "fc= " :

fc= "Mylayer"

Set field names in the bracket of "UpdateCursor". The id field name and the new field name respectively.

The First 5% and last 5% will be write in this new field.Then you can select records and extract them.

import arcpy
arcpy.env.workspace = r"...\Geodatabase.gdb"
fc = "YourlayerName"
arcpy.Delete_management("fclyr")
sorted_table = arcpy.Sort_management(fc,"fclyr","NewID DESCENDING")
with arcpy.da.UpdateCursor(sorted_table,["NewID","SecondField"]) as cur:
    for row in cur:
        if row[0]< 7591 or row[0]> 144232:           

            row[1] = 1
        cur.updateRow(row)
del row 
del cur

Note: There are some solutions to calculate the number of rows and first-last 5% numbers automatically.I want to give a simple example for you then i hardcode these numbers.

4
  • It is not a solution asker seeking, because no sorting involved.
    – FelixIP
    Commented Nov 21, 2017 at 4:25
  • I forgot sorted field. I edited my answer.
    – BBG_GIS
    Commented Nov 21, 2017 at 8:10
  • 1
    Thank you, I finally solved it using the posted links. But really thanks for your efforts.
    – Thessla
    Commented Nov 21, 2017 at 8:15
  • Well mark it as correct answer then.
    – FelixIP
    Commented Nov 21, 2017 at 8:49

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