Paths are used to browse to data and toolboxes. This topic delves into detail about paths, defining the 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 folder.
Example | Description |
---|---|
E:\Data\MyStuff | A path terminating in a directory name. |
E:\Data\MyStuff\roads.shp | A path terminating in a file name. |
System vs. catalog path
ArcGIS uses the term catalog path or ArcCatalog path. A catalog path is a path that only ArcGIS recognizes. For example, consider the following path:
D:\Data\Final\Infrastructure.gdb\EastValley\powerlines
A feature class named powerlines is 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.
Workspace and base name
Catalog paths consist of two parts: the workspace and the base name, as illustrated below:
Forward vs. 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 Python
Programming languages that have their roots in UNIX and the C programming language, such as 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. A common technique is to escape the backslash, as follows:
the_path = "E:\\data\\telluride\\newdata.gdb\\slopes"
Another approach is to convert paths into Python raw strings using the r prefix, as shown below. This instructs Python to ignore backslashes.
the_path = 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.
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 browse to the Landuse directory from the current directory (Soils), you could type the following in the Windows Explorer Address box:
..\Landuse
Windows Explorer would browse to D:\Data\Shapefiles\Landuse. A few more examples using D:\Data\Shapefiles\Landuse as the current directory are below:
Path | Result |
---|---|
.. | D:\Data\Shapefiles |
..\.. | D:\Data |
..\..\Final | D:\Data\Final |
. | D:\Data\Shapefiles\Landuse—the current directory. |
.\..\Soils | D:\Data\Shapefiles\Soils |
..\..\.\Final\..\Shapefiles\.\Landuse | D:\Data\Shapefiles\Landuse |
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 and 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 ..\..\Data\Final\Infrastructure.gdb\Streets.
When you open Newmap.mxd next, 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 browse 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 (.lyr) 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 browse 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 in the first pane. 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 (.lyr) 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
You cannot use the dot and double-dot notation in scripts. For example, the following will not work because ..\redlands.gdb\streets is a relative path:
arcpy.AddField_management("..\redlands.gdb\streets", "ref_ID", "TEXT",
field_length=10)
Why use relative vs. 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 don't often move your data 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 appear, but the tool will fail when executed, since it will be unable to locate the script. 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 their 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 and double-dot 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 follows:
\\<computer name>\<shared directory>\
This path structure can be followed by any number of directories and terminated with a directory or file name, for example:
\\pondermatic\public\studyarea.gdb
\\omni\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 browse 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 resulting dialog box.
URLs
URL stands for uniform resource locator and uniquely specifies the address of any document on the internet. The components of a URL are as follows:
- The protocol used to access the resource, such as HTTP (Hypertext Transfer Protocol) or FTP (File Transfer Protocol)
- The host (server) with which to communicate
- The path to the file on the host
For example:
http://www.esri.com/products.html
Web browsers allow you to type www.esri.com in the address bar, and the browser will automatically add https://. It's more correct, however, to specify the protocol, such as https.
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 https://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 enterprise database.
D:\Data\Final\Connection to ArcSDE.sde\EastValley\powerlines
The connection information in the .sde file is used to create a connection to the enterprise geodatabase, and the geodatabase looks up the data being requested in the same way as it does for file or personal geodatabases.