the best way to get the OBJECTID OID name in arcpy?
arcgis操作、制图、开发、分析、培训、研发、单位机构和重大科技项目技术咨询,qq group ArcGisky: 878796212
What's the best way to get the OBJECTID OID name in arcpy?
https://gis.stackexchange.com/questions/104664/whats-the-best-way-to-get-the-objectid-name
What's the best way to get the OBJECTID name of a feature class?
I know you can use "OID@" in a cursor to get the field, but can you get the name from that as well?
I'm writing a script, and need to take into account varying OBJECTID names, like OBJECTID_2, OBJECTID_12, FID, etc. that will be used in a query.
Is using Describe the only way to get the name?
For example:
oid_field = [field.name for field in arcpy.ListFields("FC") if field.type == "OID"]
I'm just wondering if there's another way.
Thanks.
arcpy objectid
1 Answer
I would say that using describe is the best
oid_fieldname = arcpy.Describe(fc).OIDFieldName
is quite straightforward. Otherwise, you can directly filter when you use listFields, so you could try
oid_fieldname = arcpy.ListFields(fc,"","OID")[0].name
but this will return an error if there is no oidField (unlikely, but...)
share improve this answer follow
answered Jul 9 '14 at 17:59
45.3k11 gold badge5252 silver badges130130 bronze badges
-
1
I agree it is very straightforward. I've just noticed Describe can be a bit slow. Thanks. – ianbroad Jul 9 '14 at 18:04
-
Is ListFields faster than Describe? – Learner Mar 3 at 7:12
-
From my experience, no, they are both relatively slow... I've tested on two different medium size) gdb and the results are ~6.4 for Describe and ~7.4 for ListFields (from scratch). If the fc is already in memory, the time is ~1.6 and 2.5, respectively. – radouxju Mar 3 at 9:13
arcgis操作、制图、开发、分析、培训、研发、单位机构和重大科技项目技术咨询,qq group ArcGisky: 878796212
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2011-08-09 使用Word2007发布博客文章的方法汇总(转)
2011-08-09 ArcGIS数据融合