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.

I have a feature class and I need to know the ObjectID of its last record.

What is the best way to find out last ObjectID?

Opening a search cursor and reading all the records is one way, but is there any other way?

share|improve this question
    
In a shapefile or database feature class? –  Michael Miles-Stimson Aug 22 at 2:57
    
In Database feature class , data set is in versioned SDE database –  shafey Aug 22 at 3:59
1  
Refer the answer by PolyGeo. Shapefiles are special in that their FIDs compress after editing so (outside of edits) their FIDs are unique/ascending with no gaps. Database feature classes retain the same OBJECTID for the feature and do not reuse expired values so they, although unique, can have gaps. –  Michael Miles-Stimson Aug 22 at 4:02
2  
Would you elaborate why do you need an ObjectID in first place? This is a system field which is maintained by ArcGIS and in general you don't want to build any business logic on this field. And by "last record", do you refer to the last edited/created feature? –  Alex Tereshenkov Aug 22 at 5:44
    
Actually , I have a feature class , that have no primary key to identify the individual records , I have a tool that inserted records onto feature class , before I insert I need to know what is the last record objectid –  shafey Sep 5 at 1:54

1 Answer 1

To do this I would use the Summary Statistics (Analysis) tool and this statistic type on ObjectID:

MAX—Finds the largest value for all records of the specified field.

Then if you want to read the MAX (highest) value you can use a search cursor on its output table to open and read the one record therein.

share|improve this answer

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.