ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Checking for the existence of data

To check for the existence of data in a script, use the Exists function.

Exists(dataset)

Tests for the existence of feature classes, tables, datasets, shapefiles, workspaces, layers, and other files in the current workspace at the time of execution. The function returns a Boolean indicating whether the element exists.

Exists function

When checking for the existence of geographic data, use the Exists function, since it recognizes catalog paths. A catalog path is a path name 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 Infrastructure.gdb (a folder) does not contain a file named Infrastructure. In short, Windows doesn't know about feature datasets or feature classes, so you cannot use Python existence functions like os.path.exists. Of course, everything in ArcGIS knows how to deal with catalog paths. Universal Naming Convention (UNC) paths can also be used.

import arcpy

arcpy.env.workspace = "d:/St_Johns/data.gdb"
fc = "roads"

# Clip a roads feature class if it exists
#
if arcpy.Exists(fc):
   arcpy.Clip_analysis(fc, "urban_area", "urban_roads")
Tip:

The Exists function honors the geoprocessing workspace environment allowing you to just specify the base name.

If the data resides in an enterprise geodatabase, the name must be fully qualified.

import arcpy

arcpy.env.workspace = "Database Connections/Bluestar.sde"
fc = "ORASPATIAL.Rivers"

# Confirm that the feature class exists
#
if arcpy.Exists(fc): 
    print("Verified {} exists".format(fc))

In scripting, the default behavior for all tools is to not overwrite any output that already exists. This behavior can be changed by setting the overwriteOutput property to True (arcpy.env.overwriteOutput = True). Attempting to overwrite when the overwriteOutput is False, causes a tool to fail.

Related topics

  • Exists
  • Setting paths to data in Python
  • Paths explained: Absolute, relative, UNC, and URL

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2019 Esri. | Privacy | Legal