1

I have a Network Analysis Layer and I would like to export one of its classes as a .lyr file. Doing this in the GUI is easy enough, just right click and export as a layer.

However, in arcpy and ModelBuilder, I have been trying to use CopyFeature replicate this process. It works for the most part, but the exported layer loses the ObjectID attribute (the temporary file before FeaturetoPoint also is missing ObjectID), which is retained when I do this through the GUI.

Here is the code exported from ModelBuilder:

dir = "C:\\Users\\Ariel\\Dropbox\\Maps\\Geo_Data\\"
Origins = "OD Cost Matrix\\Origins"
v170614_OD_Cost_Matrix_Final_lyr__2_ = dir + 
"170614_OD_Cost_Matrix_Final.lyr"
temp_origin_shp = dir + "temp_origin.shp"
v170623_Origins_shp = dir + "170623_Origins.shp"


# Process: Copy Features
tempEnvironment0 = arcpy.env.extent
arcpy.env.extent = 170614_OD_Cost_Matrix_Final.lyr (2)
arcpy.CopyFeatures_management(Origins, temp_origin_shp, "", "0", "0", "0")
arcpy.env.extent = tempEnvironment0

# Process: Feature To Point
arcpy.FeatureToPoint_management(temp_origin_shp, v170623_Origins_shp, 
"CENTROID")

I could probably try to export the attribute table and then join it back in in python, but might anyone know why CopyFeatures fails in this manner?

  • 2
    OBJECTID is a FeatureClass field maintained by a GeoDatabase. You are exporting to a shapefile which has an equivalent "FID". Suggest you export to a temporary File geodatabase? – Hornbydd Jun 23 '17 at 23:57
-1

It looks like the best way around this is to use Add Field for Network Analyst, then Calculate Field and save ObjectID as something else

|improve this answer|||||
  • What do you mean by "Add Field for Network Analyst"? – PolyGeo Feb 3 '18 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.