Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have multiple feature classes in a geodatabase, each feature class has metadata including a Description, Credits, and other information. If I use the 'Add Data' button in ArcMap 10.1 to add one of feature classes then that metadata is imported into the layer description. Ie, I view the layer properties and Description, Credits, etc., are filled in. However, if I use arcpy and add the feature class using MakeFeatureLayer_management and AddLayer then that metadata is not imported.

Does anyone know if its possible to get that full functionality of feature classes and their description, credits, etc to load with arcpy? Am I doing something wrong? Or, must I export the metadata, read the sections I want, and add that text to the layer file?

As requested, a code sample is:

mxd=arcpy.mapping.MapDocument(path_to_blankmxd)
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
arcpy.MakeFeatureLayer_management(featureclass_sde,activation+"_"+featureclass)
addLayer=arcpy.mapping.Layer(activation+"_"+featureclass)
addLayer.name=layername
arcpy.mapping.AddLayer(df,addLayer)

The feature class to be inserted in the MXD is 'featureclass_sde' with full metadata. However, once its inserted all metadata is lost. At present I am exporting metadata as XML, parsing XML to get metadata elements (description, source, etc), and then inserting those elements into the MXD. It works but seems so.... wrong....

share|improve this question
    
I would expect this to work so are you able to post some code for your steps to be tested, please? –  PolyGeo May 22 '13 at 21:22
add comment

1 Answer 1

I agree that this appears to be a bug with AddLayer and so I think you should report it to your local Esri Support.

I was able to reproduce it easily by creating a file geodatabase, creating a feature class within it, and then using Item Description to Edit its Metadata including Credits.

When I drag and dropped this feature class into the map it created a layer that had the Credits on the General tab of its Properties - as expected.

However, when I ran the code below (based on yours) and looked in ArcMap at the layer thus created by AddLayer the expected Credits were missing!

import arcpy

path_to_blankmxd = r"C:\temp\test.mxd"
featureclass_gdb = r"C:\temp\test.gdb\testFC"
activation = "XX2"
layername = "test"
featureclass = "Poly"

mxd=arcpy.mapping.MapDocument(path_to_blankmxd)
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
arcpy.MakeFeatureLayer_management(featureclass_gdb,activation+"_"+featureclass)

addLayer=arcpy.mapping.Layer(activation+"_"+featureclass)
addLayer.name=layername
arcpy.mapping.AddLayer(df,addLayer)
mxd.save()
del mxd
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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