Gen*_*pec 3 python database path dataset arcpy
我正在尝试获取要素类的数据库路径,该要素类可能在要素数据集中,也可能不在要素数据集中.我正在使用os.path.dirname要素类.如果要素类不在要素数据集中(这很好),这将为我提供数据库路径,但如果要素类位于要素数据集中,它将为我提供要素数据集的路径.
这可以是文件,个人或sde地理数据库.我在考虑split使用'.sde',但如果它是一种不同类型的地理数据库则无法使用.
路径的示例可以是:
在这两种情况下,我想得到C:\ GISData\Data.gdb.
谢谢.
小智 6
查看这篇简短的博客文章,他们使用以下功能:
def get_geodatabase_path(input_table):
'''Return the Geodatabase path from the input table or feature class.
:param input_table: path to the input table or feature class
'''
workspace = os.path.dirname(input_table)
if [any(ext) for ext in ('.gdb', '.mdb', '.sde') if ext in os.path.splitext(workspace)]:
return workspace
else:
return os.path.dirname(workspace)
Run Code Online (Sandbox Code Playgroud)
小智 5
文档中不明显的另一种方法是使用路径(只读)属性:
import arcpy
desc = arcpy.Describe(r"C:\GISData\Data.gdb\Erf")
print desc.path
# prints: u"C:\\GISData\\Data.gdb"
Run Code Online (Sandbox Code Playgroud)