Using arcpy to access Pro map layer metadata

1411
7
Jump to solution
09-02-2020 05:39 PM
dcafdg
by
Occasional Contributor III

I am trying to access the metadata for a map layer in ArcGIS Pro via arcpy. When I have a map layer, all of its properties from the Pro metadata tab of the layer properties are null. Here is a screenshot of my Python editor when I look at the map layer object in debug mode: 

This is a layer that has its own metadata attached to the data source feature class. I copied the metadata to the layer, so it looks like the screenshot below, but I get the same result with null values. 

If I go to the feature class (in a file geodatabase), I do get values: 

>>> from arcpy import metadata as md
>>> tgt_item_md = md.Metadata(fc_path)
> tgt_item_md.isReadOnly
False
>>> tgt_item_md.title
'NOAA_WRC_Fish2015'
>>> tgt_item_md.description
'<DIV STYLE="text-align:Left;"><DIV><DIV><P><SPAN>The base geospatial information is the Watershed Boundary Dataset (WBD) [...etc...]'‍‍‍‍‍‍‍‍

Can anyone tell me how to correctly read the metadata from the layer properties metadata tab? 

thanks!

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor
7 Replies
DanPatterson
MVP Esteemed Contributor

All I see is...

Metadata—ArcGIS Pro | Documentation 

the last code example

Get a Metadata object from a map layer.

pulling out the properties as needed.  So you can read from various start levels of info (project, map, layer) if you want.


... sort of retired...
0 Kudos
dcafdg
by
Occasional Contributor III

Unfortunately, that's the example I was following. The layer and metadata objects in the screenshot above from my IDE came from that code sample.

0 Kudos
DanPatterson
MVP Esteemed Contributor

Then just make a def out of what you need, so you can reuse it when you need it


... sort of retired...
dcafdg
by
Occasional Contributor III

Dan Patterson‌, Joshua Bixby

I'm connecting to a Pro map layer that has metadata, but arcpy is returning all None values in the metadata properties. I'm not seeing how making a reusable def is going to help. 

I thought the screenshot from my IDE would help, but it looks like it's a distraction. Here is what I am doing. This is a map layer that has metadata defined. Assume in_project (path to aprx), map_name, and map_layer_name are strings defined above. 

aprx = arcpy.mp.ArcGISProject(in_project)
map_out = aprx.listMaps(map_name)[0]
layers = map_out.listLayers()
for layer in layers:
    if layer.name == map_layer_name:
        map_layer_out = layer
map_layer_out
<arcpy._mp.Layer object at 0x000001D64CFCFC50>
layer_md = map_layer_out.metadata
layer_md
<arcpy.metadata.Metadata object at 0x000001D64CFC0438>
layer_md.title   # has no output
type(layer_md.title)
<class 'NoneType'>
layer_md.description   # has no output
type(layer_md.description)
<class 'NoneType'>
type(layer_md.tags)
<class 'NoneType'>
type(layer_md.summary)
<class 'NoneType'>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Shouldn't I be getting actual values there, like what I see in the Pro screenshot I posted? 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Can you share a layer or layer package? 

I tried several different scenarios, and all of them work as expected with metadata.  I am using Pro 2.6.1, what version are you using?

DanPatterson
MVP Esteemed Contributor
dcafdg
by
Occasional Contributor III

I'm on 2.5, I think that bug must be it. Ugh. Waiting for my agency to approve a higher version. Thanks for the help!

0 Kudos