I use summary statistics GP tool to extract the max OBJECTID from a feature layer. After that I use arcpy SerachCursor to get the OBJECTID value from the statistics, but the result returned is not an integer.
The statistics contents:
The result of SearchCursor:
The python code:
import arcpy
arcpy.env.workspace = "C:/Users/lyao/Documents/ArcGIS/Default.gdb"
feature = "C:/Users/lyao/Documents/ArcGIS/Default.gdb/BQ_Segment_1_Statistics1"
with arcpy.da.SearchCursor(feature, ("MAX_geri_db_DBO_BQ_Segment_1_OBJECTID",), '"OBJECTID" = 1') as cursor:
for row in cursor:
print str(row[0])
I want to know:
How to get the exact same OBJECTID as in the statistics.
I am using vb.net, so I want to know how to return the result to vb.net.
I am using arcmap 10.2.
Answer
In VB.net:
Dim pWSF As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory()
Dim pWS As ESRI.ArcGIS.Geodatabase.IWorkspace = pWSF.OpenFromFile("C:/Users/lyao/Documents/ArcGIS/Default.gdb", 0)
Dim pFws As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace = CType(pWS, ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)
Dim pTable As ESRI.ArcGIS.Geodatabase.ITable = pFws.OpenTable("BQ_Segment_1_Statistics1")
Dim pCur As ESRI.ArcGIS.Geodatabase.ICursor = pTable.Search(Nothing, False) ' open the cursor
Dim pRow As ESRI.ArcGIS.Geodatabase.IRow = pCur.NextRow ' first row
Dim pValue As Integer = pRow.Value(2) ' the value in the 3rd column
That is assuming that the table never deviates from the format shown.
You start with an IWorkspaceFactory (set the type to match the database) from which you create an IWorkspace which gets changed into a IFeatureWorkspace which is able to open the table. With the table start the cursor, get the first row and then retrieve the value.
You can see why arcpy is so popular... The online help will give some explanation and options for the objects shown but that's the way to open a table from scratch.
No comments:
Post a Comment