Bugs in ArcGIS Pro map and layer metadata?

159
0
06-02-2021 07:00 AM
PaulHopgood1
New Contributor

HI All, I am using ArcGIS Pro Basic License, version 2.8.0 and PyCharm 3.7. I would not class myself as an expert, but just past beginner in Python, I set myself this project as a challenge so I will become more proficient with Python and its application within ArcGIS Pro.

The project is to build a number of tools for Map Management within ArcGIS Pro.

The Map Management Tools will need to complete the following:

1. Extract the map extent from the project and insert this into a feature class with multiple attributes defined from user input and automatially generated inputs.

2. Analyse the layer metadata by comparing it to the map metadata for specific criteria. For example, if the map security level is designated as 'Restricted' and a Layer security level is designated as 'Confidential', this is warning flagged to the map creator once they have run the tool. The same applied to scale, if say the map scal is set to '1:50,000' and the layer maximum scale is set to '1:100,000', then a warning is flagged to the creator that there is a risk of generalisation errors by using this data set.

3. Update the map metadata from the inputs provided by the map creator and those automatically generated

4. Add the User inputs and those inputs that are automatically generated that apply directly into the layouts associated with the map, whether they are a single map or map series

 

I have come across a couple of 'bugs' I think, code below:

1. When I extract the layer.maxScale from a layer metadata I get a a number in natural number format, that makes no sense. Also when I rerun the code, I get a totally different number. Has anyone seen this before or have tried to do something similar?

2. When I try to update the map metadata with the map creator and automatically generated input, it refuses to update. When I go onto the esri site for map metadat is says that the the map metadata is read only, i.e. it cannot be updated through code. Is this correct or am I missing something?

 

The code for point 1 is:

try:
from arcpy import env, metadata as md

# Use the current arcgis pro project
##aprx = arcpy.mp.ArcGISProject("CURRENT")
aprx = map.ArcGISProject(r"C:\Users\HP\Documents\ArcGIS\Projects\Plant To Grid\PlantToGrid\PlantToGrid.aprx")
tblInfoSecurity = r"C:\Users\HP\Documents\ArcGIS\Projects\Plant To Grid\PlantToGrid\PlantToGrid.gdb\tblInfoSecurity"

for m in aprx.listMaps():
print("Map: "+m.name)
lyt = aprx.listLayouts()[0]
print("Layouts: " + lyt.name)
# active_object derived from aprx.activeView
mf = lyt.listElements("MAPFRAME_ELEMENT")[0]
# print("mapframe is: " + mf.name)
# get the extent of the camera
frameExtent = mf.camera.getExtent()


# Map Scale
MAP_SCALE: int = round(mf.camera.scale)
print(MAP_SCALE)
MAP_SCALE_TXT = str('1:') + str(MAP_SCALE)
print(MAP_SCALE_TXT)

# Define metadata created in the map management process
mm_md = ""
mm_md_mapscale: int = 0

for m in aprx.listMaps():
print("Map: "+m.name)
mm_md = md.Metadata(m)
mm_md.id = "XXXXXXX" # MAP_DOC_REF
#print("Map Document Reference: " + mm_md.id)
arcpy.AddMessage("Map Document Reference :" + mm_md.id)
mm_md.title = "Map Title" # MAP_TITLE
arcpy.AddMessage("Map Title is: " + mm_md.title)
mm_md.tags = "Map Tags" # MAP_TAGS
arcpy.AddMessage("Map Tags are: " + mm_md.tags)
mm_md.summary = "Map Summary" # MAP_SUMMARY
arcpy.AddMessage("Map Summary is: " + mm_md.summary)
mm_md.description = "Map Description " # MAP_DESCRIPTION
arcpy.AddMessage("Map Description is: " + mm_md.description)
mm_md_mapscale = MAP_SCALE
arcpy.AddMessage("Map Scale is: " + str(mm_md_mapscale))
mm_md.credits = "Map Credits" ##MAP_CREDITS
arcpy.AddMessage("Map Credits are: " + mm_md.credits)
mm_md.accessConstraints = "Restricted" # SECURITY
arcpy.AddMessage("Map Security Level is: " + mm_md.accessConstraints)


InfoSec_Desc: str = ""
print("Map: {0} Layers".format(m.name))
# Extract layer metadata for each layer applied in the map
lyr_metadata = ""
lyr_metadata_secref = ""
lyr_metadata_seclevel: str = ""
#lyr_metadata_maxscale: int = 0
mm_md_secref = ""
mm_md_seclevel: str = ""

for lyr in m.listLayers():
lyr_metadata = lyr.metadata
print(lyr.name)
print(lyr_metadata.title)

# Extract from layer metadata the layer maximum scale
lyr_metadata_maxscale = lyr_metadata.maxScale
print("Layer Metadata Maximum Scale is: " + str(lyr_metadata_maxscale))

del aprx

except Exception as e:
print("Error: " + e.args[0])

The result is:
Map: 20210501
Layouts: XXX-20210506-001
550000
1:550000
Map: 20210501
Map Document Reference :XXXXXXX
Map Title is: Map Title
Map Tags are: Map Tags
Map Summary is: Map Summary
Map Description is: Map Description
Map Scale is: 550000
Map Credits are: Map Credits
Map Security Level is: Restricted
Map: 20210501 Layers
Output_FC_pt
Output Feature Class Point file
Layer Metadata Maximum Scale is: 6.87508996722e-312

Any help appreciated, thanks in advance.
0 Kudos
0 Replies