Paths explained: Absolute, relative, UNC, and URL
You deal with paths every day to browse to your data and toolboxes. You probably don't give them much thought, nor do you need to, until it comes time to share your data and tools. This section delves into detail about paths, defining the different types and how ArcGIS manages them.
Paths and pathnames
Path
A path is a slash-separated list of directory names followed by either a directory name or a file name. A directory is the same as a system folder.
E:\Data\MyStuff (path terminating in a directory name) E:\Data\MyStuff\roads.shp (path terminating in a file name)
Pathname
On occassion, you may see the term pathname or path name. Path, pathname, and path name are synonymous.
System versus catalog path
ArcGIS uses the term catalog path or ArcCatalog path. A catalog path is a path that only ArcGIS recognizes. For example:
D:\Data\Final\Infrastructure.gdb\EastValley\powerlines
refers to the powerlines feature class found in the EastValley feature dataset in the file geodatabase Infrastructure. This is not a valid system path as far as the Windows operating system is concerned, since Windows doesn't recognize feature datasets or feature classes within a file geodatabase. Of course, everything in ArcGIS can operate with catalog paths.
Workspace and base name
Catalog paths consist of two parts: the workspace and the base name, as illustrated below:
Location
Location is a catchall term for path, as in "Browse to the location of your data" or "Enter the location of your data."
Forward versus backward slashes
The Windows convention is to use a backward slash (\) as the separator in a path. UNIX systems use a forward slash (/). Throughout ArcGIS, it doesn't matter whether you use a forward or backward slash in your path—ArcGIS will always translate forward and backward slashes to the appropriate operating system convention.
Backward slash in scripting
Programming languages that have their roots in UNIX and the C programming language, like Python, treat the backslash (\) as the escape character. For example, \n signifies a carriage return. Since paths can contain backslashes, you need to prevent backslashes from being used as the escape character. The easiest way is to convert paths into Python raw strings using the r directive, as shown below. This instructs Python to ignore backslashes.
thePath = r"E:\data\telluride\newdata.gdb\slopes"
Absolute and relative paths
Absolute, or full, path
An absolute, or full, path begins with a drive letter followed by a colon, such as D:.
Relative path
A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy. A single dot represents the current directory itself.
In the example directory structure below, assume you used Windows Explorer to navigate to D:\Data\Shapefiles\Soils. After navigating to this directory, a relative path will use D:\Data\Shapefiles\Soils as the current directory (until you navigate to a new directory, at which point the new directory becomes the current directory). The current directory is sometimes referred to as the root directory.
If you wanted to navigate to the Landuse directory from the current directory (Soils), you could type the following in the Windows Explorer Address box:
..\Landuse
Windows Explorer would navigate to D:\Data\Shapefiles\Landuse. A few more examples using D:\Data\Shapefiles\Landuse as the current directory are below:
.. (D:\Data\Shapefiles) ..\.. (D:\Data) ..\..\Final (D:\Data\Final) . (D:\Data\Shapefiles\Landuse - the current directory) .\..\Soils (D:\Data\Final\Soils) ..\..\.\Final\..\Shapefiles\.\Landuse (D:\Data\Shapefiles\Landuse)
You cannot type relative paths (using the dot and double-dot notation) in any ArcGIS application. Nor can you use relative paths in Python scripts.
A relative path cannot span disk drives. For example, if your current directory is on drive D, you cannot use relative paths to navigate to any directory on the E drive.
Absolute and relative paths in ArcMap
When you create an ArcMap (or ArcScene or ArcGlobe) document, you can specify that paths will be stored as relative paths. To set this option, look under the File menu and click Map Document Properties. Here, you can specify whether to store absolute or relative paths.
When you save the document with relative paths, the application converts paths into relative paths (using the dot/double-dot notation) relative to the location where you stored the document (the current directory). For example, if your document is stored in
D:\Maps\Posters\Newmap.mxd
and the data in one of your layers is
D:\Data\Final\Infrastructure.gdb\Streets
what gets stored in Newmap.mxd is the following:
..\..\Data\Final\Infrastructure.gdb\Streets
When you open Newmap.mxd again, ArcMap converts the stored relative path from the dot/double-dot notation back into the absolute path representation, which is displayed as the data source for a layer. This conversion is always relative to the location of the map document (the current directory).
Only paths on the same disk are converted
Relative paths cannot span disk drives. That is, if the root directory is on drive D, you cannot use relative paths to navigate to a directory on drive E. When you store your map document using relative paths, only those paths that are on the same drive are converted and stored.
Absolute and relative paths in model tools
Just like data in ArcMap, you can specify that paths in your model tools will be stored as relative paths.
The current directory used for relative paths is the directory where the tool's toolbox resides. The relative path option converts and stores paths to the following:
- Data in a model
- Graphic images in a model
- Tools used in your model
- Files referenced in tool metadata and help
- Style sheets
- Layer files used for symbology
- Compiled help files (.chm)
To store as relative paths, right-click the model tool, click Properties, then click the General tab. At the bottom of the dialog box, check Store relative path names (instead of absolute paths), as shown below.
Only paths on the same disk are converted
Relative paths cannot span disk drives. That is, if the root directory is on drive D, you cannot use relative paths to navigate to a directory on drive E. When you store your model using relative paths, only those paths that are on the same drive are converted and stored.
Absolute and relative paths in script tools
When using the Add Script wizard, the option to store relative paths will appear on the first panel. You can also set this option by right-clicking the script tool, clicking Properties, then clicking the General tab. At the bottom of the dialog box, check Store relative path names (instead of absolute paths).
The current directory used for relative paths is the directory where the tool's toolbox resides. The relative path option converts and stores paths to the following:
- The script
- Datasets used for the default value property
- Files referenced in tool metadata and help
- Layer files used for the symbology property
- Compiled help files (.chm)
- Style sheets
Only paths on the same disk are converted
Relative paths cannot span disk drives. That is, if the root directory is on drive D, you cannot use relative paths to navigate to a directory on drive E. When you store your script tool using relative paths, only those paths that are on the same drive are converted and stored.
Paths within the script are not converted
There is no reliable way for ArcGIS to examine your script code, find all the paths, and convert them to relative paths. Furthermore, you cannot use the dot and double-dot notation in scripts. For example, the following will not work:
arcpy.AddField_management("..\redlands.mdb\streets", "ref_ID", "long", "9", "#", "#", \ "refcode", "NULLABLE", "REQUIRED", "#")
because ..\redlands.mdb\streets is a relative path.
You need to modify your script code so that you can find data relative to a known location. The one location you can easily find is the location of the script, as described in Techniques for sharing Python scripts.
Why use relative versus absolute paths?
Using absolute paths, the following are true:
- You can move the document or toolbox anywhere on your computer and the data will be found when you reopen the document or tool.
- On most personal computers, the location of data is usually constant. That is, you typically don't move your data around much on your personal computer. In such cases, absolute paths are preferred.
- You can reference data on other disk drives.
Using relative paths, these adjustments are necessary:
- When moving a map document or toolbox, you must also move the referenced data.
- When delivering documents, toolboxes, and data to another user, relative paths should be used. Otherwise, the recipient's computer must have the same directory structure as yours.
For example, consider the directory structure below. In this example, D:\Tools\Toolboxes\Toolbox1 contains a script tool that uses D:\Tools\Scripts\MyScript.py.
Using absolute paths, if you moved the toolbox from
D:\Tools\Toolboxes\Toolbox1
to a different disk, such as
E:\Final\Toolbox1
ArcGIS will find D:\Tools\Scripts\MyScript.py and everything will work fine. If, however, you use relative paths, ArcGIS will not find the script and the tool will not work. The tool dialog box will open, but when you execute, you'll get the error message "Script associated with this tool does not exist." You will have to open the tool's properties and enter the correct path to the script.
On the other hand, if you use relative paths, you can simply copy the folder D:\Tools anywhere on anyone's computer and everything will work. This won't work if you use absolute paths, because the recipient could copy the folder to F:\NewTools and the path D:\Tools\Scripts\MyScript.py won't exist on his or her computer.
Summary
- Relative paths cannot span disk drives.
- Absolute paths work best when data isn't moved, which is typical for disks on a personal computer.
- Relative paths work best when you're delivering documents and data to another user.
- Relative paths use dot/double-dot (. and ..) notation. You can enter relative paths with this notation in Windows Explorer or at the Windows command prompt.
- ArcGIS doesn't allow you to enter relative paths using dot/double-dot notation. Rather, relative paths are stored in the document or toolbox (once you check the Store relative path names option).
- Relative paths are relative to a current directory, which is the location of the saved document or toolbox.
UNC paths
UNC stands for Universal (or Uniform or Unified) Naming Convention and is a syntax for accessing folders and files on a network of computers. The syntax is as shown:
\\<computer name>\<shared directory>\
followed by any number of directories and terminated with a directory or file name.
For example:
\\pondermatic\public\studyarea.gdb \\omnipotent\shared_stuff\wednesday\tools
The computer name is always preceded by a double backward slash (\\).
In UNC, the computer name is also known as the host name.
These are a few rules for UNC paths:
- UNC paths cannot contain a drive letter (such as D).
- You cannot navigate to directories above the shared directory.
- The Store relative path names option for documents and tools has no effect on UNC paths.
In ArcGIS, you can use a UNC path anywhere a path is requested. This is particularly advantageous for shared data on a local area network (LAN). Data can be stored on one computer and everyone with access to the computer can use the data, as long as the computer is not turned off or removed from the network.
In Windows, you can share a folder so that other users on your local area network can access it. In ArcCatalog or Windows Explorer, right-click a folder, click Sharing and Security, then follow the instructions on the dialog box that opens.
URLs
URL stands for Uniform Resource Locator and uniquely specifies the address of any document on the Internet. The components of a URL are these:
- The protocol used to access the resource, such as HTTP (Hypertext Transfer Protocol) or FTP (File Transfer Protocol)
- The host (server) to communicate with
- The path to the file on the host
For example:
http://www.esri.com/products.html
Windows Internet Explorer allows you to type www.esri.com in the Internet Explorer address bar, and it will automatically add http://. It's more correct, however, to specify the protocol, such as http. Other protocols include HTTPS (Secure Hypertext Transfer Protocol), FTP, mailto (e-mail address), and news (Usenet newsgroups), among others.
In ArcGIS, you can only use URLs where permitted. In general, the user interface will tell you whether a URL is permitted or needed. When using URLs in ArcGIS, it's recommended that you include the protocol, as in
http://www.esri.com
rather than
www.esri.com
ArcSDE connection file path
Geoprocessing tools use the path to an ArcSDE connection file (.sde) to locate data stored in an ArcSDE database.
D:\Data\Final\Connection to ArcSDE.sde\EastValley\powerlines
The connection information in the .sde file is used to create a connection to ArcSDE, and the geodatabase looks up the data being requested in the same way as it does for file or personal geodatabases (see above).
As with other geodatabase data formats (.gdb and .mdb), you should store your .sde files under your ToolShare folder and your tools should access the .sde file using relative paths. It is not recommended that you use the default location where ArcGIS stores ArcSDE connection files, the Database Connections system path, to store and access .sde files when sharing tools. This location is different for every user (it is associated with your local Windows user profile) and may contain .sde files named the same as what your shared tools are using, but with different connection information that may cause your tools to fail.
When using ArcSDE data in shared tools, not only must the tool you are sharing have access to the .sde file, but the .sde file must also contain secure, authorized connection information for the user you are sharing the tool with, and that user must have access to the network on which the ArcSDE geodatabase resides. In many organizations, it is considered a security breach to share database connection information with someone who is not authorized to connect to the database. Simply sharing an ArcSDE connection file with your connection information in it with someone else could put you in breach of your organization's security policies. To avoid any security issues, you should first ensure the user you are sharing your tools with is authorized to connect to the ArcSDE database. If so, the .sde file you provide in the ToolShare folder should not contain a user name/password and you should provide documentation explaining how to update the ArcSDE connection file with the user's connection information. See your ArcSDE and database administrators so you understand your organization's security policies.