In Python I am running a script as a tool that takes a CSV file of coordinates and creates a feature class of points from the coordinates. I use the Convert Coordinate Notation tool. Script below for context but I am mainly taking issue with lines 43-45.
import arcpy import os import re arcpy.env.overwriteOutput=True # Get the datasets and folder locations oldFC = arcpy.GetParameterAsText(0) fallout = arcpy.GetParameterAsText(1) newFC = arcpy.GetParameterAsText(2) # set columns where longitude and latitude are, and the format (two columns assumed) lonAtt=arcpy.GetParameterAsText(3) latAtt=arcpy.GetParameterAsText(4) # Get layer spatial reference coo = arcpy.Describe(oldFC) coo = coo.spatialReference inCoo = arcpy.SpatialReference(4269) # Sanity check arcpy.AddMessage("Old met file: " + oldFC) arcpy.AddMessage("Backup location: " + fallout) arcpy.AddMessage("CSV data file: " + newFC) # This splits out the FC name from the Database Connection path sdeFC = os.path.split(oldFC) arcpy.AddMessage("SDE file name: " + sdeFC) # This splits out the Database Connection path sde = os.path.split(oldFC) arcpy.AddMessage("SDE: " + sde) # Also escape out the parentheses ...I don't remember why I did this sdeI = re.sub('\(.*\)', '', sde) sdeFCI = re.sub('\(.*\)', '', sdeFC) # replace special period character with underscores in FC name backItUp = re.sub('\.', '_', sdeFCI ) arcpy.AddMessage("backup name: " + backItUp) arcpy.CopyFeatures_management(oldFC, os.path.join(fallout, backItUp + ".shp")) # set output name the same as the original, so it will get overwritten with updated table arcpy.ConvertCoordinateNotation_management(in_table=newFC, out_featureclass=oldFC,x_field=lonAtt, y_field=latAtt, input_coordinate_format="DD_2", output_coordinate_format="DD_2", in_coor_system=inCoo, spatial_reference=coo)
Why does this tool create an OID field instead of an OBJECTID field? I assume it has something to do with the input being a table...but it doesn't make sense because it creates a feature class. Per this FAQ: What are the differences in the behavior of the OBJECTID, FID, and OID fields? "In a standalone dBase table, the 'OID' field contains the ObjectID, and the values start at zero".
The script overwrites an old feature class which has an OBJECTID field since it is in a geodatabase. This tool outputs the OID field and then my map services break because of the change in field name.
How can I get back an OBJECTID field and get rid of the OID? Right now my workaround is to not use this tool, and instead make an XY event layer from the table and then copy that into the GDB.
did you try to save it to a geodatabase rather than a shapefile. objectid is the equivalent to a shapefiles fid
OID is normally created in shapefiles since shapefiles now require a minimum of 3 fields, FID, Shape, OID are the minimum