Copying a arc map .mxd document into a new workspace or lets say new computer always creates problems like missing links, Location of all shape files scattered on different locations in the creator's computer.Thus zipping all those scattered files into a single folder which on double clicking directly takes you to the map document with no broken link of data is an attempt made by us through development of this tool.
Using arc map to create package map along with a report file [metadata]
1. A TOOL TO PACKAGE THE CONTENT OF A
MAP(.MPK) AND GENERATE ITS REPORT(
.TXT) FORMAT
Project members:
Bibek Karki(13)
Upendra Oli(19)
Uttam Pudasaini(22)
2. WHAT HAVE WE DONE??
Developed a script that produces a simple report for the current
map document and provides:
Information about all data frames and layers in the map
List all such layers having broken data links
A map package (*.mpk) for the current mxd document
3. MOREOVER,
Assessing user-provided inputs
Branching and looping statements in python
Execute a Geoprocessing tool
Show messages that report the script‟s progress
Access objects in a map document (Data frames and Layers )
Create, open, and write reports to text files
4. OBJECTIVE
Distributing maps to those who do not normally have access to the
data along with
Its details(Data provider information, total data frames in the
compressed .mpk document)
5. ABOUT THE PROGRAM
1. Import modules:
import os, sys ,arcpy and import arcpy.mapping as mapping
2. Read User Inputs
Output_Location = arcpy.GetParameterAsText(0)
Packaged_Map = arcpy.GetParameter(1)
Information_BrokenLayers = arcpy.GetParameter(2)
6. CONTD…
3. Obtain map document where the user is currently working using
"Current" keyword
mxd_current = mapping.MapDocument('Current')
Required parameter for the MapDocument function is
“either a path to a map document on disk” or
The keyword “Current”
4. Write the output text file for our mxd file (text file)
Output_Path = Output_Location + '' +"Metadata For" +mxd.title
+ '.txt'
5. Open the file ,The file will be created if it doesn't exist.
Output_File = open(Output_Path, 'w')
7. CONTD…
6. Include the details to be included to provide information about the
mxd producer
Details = 'Title: ' + mxd.title + 'n'
Details += 'Author: ' + mxd.author + 'n'
Details += 'Description: ' + mxd.description + 'n„
7. User will have two options to check once the tool runs
For creating package Map
For generating the output report of current mxd document
8. 8. Creating packacgemap
Use ArcPy to call the PackageMap geoprocessing tool.
package_map_Path = outDir + '' + mxd.title.replace('.', '_') +
'.mpk
if (os.path.exists(package_map_Path)):
arcpy.AddMessage('Map package already exists (' +
package_map_Path+ ')')
else:
arcpy.AddMessage('Creating map package (' +
package_map_Path + ')'
arcpy.PackageMap_management(mxd.filePath,
package_map_Path)
Note: PackageMap_management requires the path to the map
document and the path to the output package file
9. 9. Acquire all data frames (Data frame name and spatail Reference)
in this map document
DataFrames = mapping.ListDataFrames(mxd, '')
for frame in DataFrames:
Details += 'nData Frame: ' + frame.name + 'n'
Details += 'Spatial Reference: ' + frame.spatialReference.name + 'n'
# Obtain all layers in this data frame
layers = mapping.ListLayers(mxd, '', frame)
i = 0 # layer index position
# Loop through all layers in the data frame
for lyr in layers:
# Report index position and name
Details += 'tLayer ' + str(i) + ': ' + lyr.name + 'n'
i += 1
10. 10. To check for layers with a missing data source
if checkBrokenLayers:
arcpy.AddMessage('Checking for missing data sources')
brokenList = mapping.ListBrokenDataSources(mxd)
# Get the count of broken layers
Details += 'nFound ' + str(len(brokenList)) + ' layers with missing
data.'
# Loop through all broken layers in the list
for broken in brokenList:
# report broken layer name
Details += 't- ' + broken.name + 'n'
11. 11. Write the text stored in the Details variable to the output file
reportFile.write(Details)
reportFile.close()
del mxd # delete the mxd object
12. BEFORE YOU RUN THIS SCRIPT
Be sure to enter descriptive information about the mxd file
it in the Map Document Properties dialog box.
To let others know the basic description of your map documents
You can access this dialog box by clicking File > Map
Document Properties on the main menu.
13. SCRIPT PARAMETERS
Reading Inputs Parameter
Name
Data Type Default Value
GetParameterAsText(0) Output
location
Folder Optional
GetParameter(2) Package
Map
Boolean False
GetParameter(3) Broken link
check
Boolean True
Its because parameter values are read from an ordered list of inputs…
14. OUTPUT
Package map:
Packages a map document and all referenced data sources to
create a single compressed .mpk file.
Report file:
Metadata information about the mxd documents and its all data
frames