When is a FID not a FID?

694
0
01-08-2015 02:12 PM
VinceAngelo
Esri Esteemed Contributor
1 0 694

Actually, that turns out to be a trick question -- The answer is never.

I had some ArcObjects Java code that needed to make XML from a shapefile or file geodatabase table.  It turns out that the easiest way to get shapefile to XML is by copying the shapefile to a file geodatabase via FeatureClassToFeatureClass (as a GPTool), then using a GdbExporter (IGdbXmlExport interface) to create the XML.  Then my client threw in a twist: Sometimes, only the schema is necessary.  So sometimes I'll be copying a million row shapefile to FGDB, and then not using those rows when the XML is generated.  It saves on XML file size and processing time to go straight to schema (gdbXmlExport.exportDatasetsSchema(...) vice gdbXmlExport.exportDatasets(...)), but how to save time on the copy as well?

The answer is to apply a WHERE clause to the FeatureClassToFeatureClass GPTool which results in no rows.  But there's still a hitch:  What WHERE clause to use?

It turns out that ArcObjects honors the old SQL trick for selecting zero rows ("WHERE 1 = 0") with file geodatabase, but not for shapefile.  In theory, using the objectid column with a negative value should work, but using FeatureClass.getOIDFieldName() turns out to be surprisingly convoluted when you start with a simple String name.

The solution turned out to be simpler than I had feared: Shapefiles have a virtual column named "FID"  (zero-based row number).  This is true of both J Random Shapefile and a shapefile that had a string "FID" column defined in an attempt to break a "FID < 0" query -- The dBase FID field is renamed (to "FID_1" in my case), and the virtual FID is retained.  So in the end I used an 'if' test to set the WHERE clause, "1 < 0" for FGDB and "FID < 0" for shapefile, quick and easy.

About the Author
Thirty-five years with Esri, with expertise in Software Engineering, Large Database Management and Administration, Real-time Spatial Data Manipulation, Modeling and Simulation, and Spatial Data Manipulation involving Topology, Projection, and Geometric Transformation. Certifications: Security+ (SY0-601), Esri EGMP (2201), Esri EGMP (19001), Esri EGMP (10.3/10.1), Esri ESDA (10.3), Esri EGMA (10.1) Note: Please do not try to message me directly or tag me in questions; just ask a question in an appropriate community, and if I see it, have something to add, and have the time, I'll respond.
Labels