ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

帮助

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • 更多...

检查数据是否存在

要检查脚本中是否存在数据,请使用 Exists 函数。

Exists(dataset)

测试在执行期间当前工作空间中是否存在要素类、表、数据集、shapefile、工作空间、图层和其他文件。函数返回指示元素是否存在的布尔值。

Exists 函数

由于 Exists 函数能够识别目录路径,所以在检查地理数据是否存在时,必须使用该函数。目录路径是只有 ArcGIS 能够识别的路径名称。例如:D:\Data\Final\Infrastructure.gdb\EastValley\powerlines 是指在文件地理数据库 Infrastructure 的 EastValley 要素数据集中找到的 powerlines 要素类。就 Windows 操作系统而言,这不是有效的系统路径,因为 Infrastructure.gdb(文件夹)并不包含名为 Infrastructure 的文件。简而言之,Windows 不了解要素数据集或要素类,因此用户不能使用像 os.path.exists 这样的 Python 存在函数。当然,在 ArcGIS 中,系统知道如何处理目录路径。也可以使用通用命名约定 (UNC) 路径。

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")
提示:

Exists 函数支持地理处理工作空间环境,允许您仅指定基本名称。

如果数据位于企业地理数据库中,则必须对名称进行完全限定。

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))

在脚本中,所有工具的默认行为是不覆盖任何已存在的输出。可通过将 overwriteOutput 属性设置为 True (arcpy.env.overwriteOutput = True) 来更改此行为。在 overwriteOutput 为 False 时,试图进行覆盖将会导致工具无法使用。

相关主题

  • Exists
  • 使用 Python 设置数据的路径
  • 路径解释:绝对、相对、UNC 和 URL

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS 平台

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

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2019 Esri. | 隐私政策 | 法律声明