Fixing broken Links
One of the common problems that is experienced in geospatial technology is broken links to data files, which generally occurs when either the project file is moved to a new location, a different computer is used, or that the data files have been moved to a different storage location. In general, it is a slow process fixing one or more broken links, even when all the broken links are in the same folder or geodatabase. Remember that a broken link appears with a red exclamation point. If the file is selected there will be a check in the box, but no information will be displayed. Generally, this problem is fixed by individual re-linking each file. Figure 11, shows four broken links in the table of contents.
|
Mapping Module
The mapping module is used as part of the solution to fix broken links. For this example, the Python Window in ArcMap will be used and the project file (mxd) will be opened in ArcMap. The operation could be done using an IDE, but generally, the user realizes the problem once they open ArcMap. The word ‘Current’ will be used in the script, this will only work when in ArcMap and the project file is opened. If the project file is not opened, then a qualified pathway to the information would be required.
Broken Links
- To determine the name of the file the MapDocument and ListBrokenDataSources commands are used. The MapDocument is using the parameter Current which not a pathway since the project file is open in ArcMap. The MapDocument command returns all the file names to the variable ‘project,’ i.e. the contents of the project file, which is a list variable.
2. The ‘broken’ variable will contain only those files that have a broken link through the use of the ListBrokenDataSources command.
3. The print commands are used to display the name of the broken files and the pathway to the broken file links, see Figure 13.
3. The print commands are used to display the name of the broken files and the pathway to the broken file links, see Figure 13.
Fixing Links
In the previous section, the broken links were identified but no repair was performed. If the only purpose is showing where the project file data is located, can be useful but does not solve the problem. There are multiple ways that this problem can be solved and this example will show only one method. It will be different from the method shown Figure 13. The method shown for fixing the link will be performed in an IDE and thus the full pathways must be defined instead of using the word current. It is suggested that the project file (.mxd) be closed before beginning this process. See Figure 14, to follow the process.
- Since this code is being created in an IDE the arcpy module must be added.
- The variable ‘project’ defines the location of the project file.
- The next line of script replaces the broken pathway with the correct one using the findAndReplaceWorkspacePaths. The first parameter is the pathway of the broken file and the second line is the pathway to where the file is currently located.
- The saveACopy command then saves the mxd, while a new mxd is not required, the author believes by creating a new project, this reduces the chances of locks causing potential problems. Therefore, the mxd is saved with a number 2 on the end.
- The final command deletes the variable project to get rid of any potential locks.