arcpy处理mdb中的要素数据集和要素类

2020-09-18 10:20发布

最近在测试如何获取mdb中的要素数据集,并且查询mdb要素类的属性表内容。

测试数据

使用ArcMap的python环境(‪C:\Python27\ArcGIS10.7\python.exe),并使用下述代码进行测试,发现能够将mdb中要素数据集名称获取到,并且能够查询指定要素类的内容。

import arcpy
import os
ws = r"E:\test\testcwd.mdb"
arcpy.env.workspace = ws
fdss = arcpy.ListDatasets()
print fdss
fdss.append('')  # for those fc that reside in the root of the sde ws
 
for fds in fdss:
    fc_names = arcpy.ListFeatureClasses(feature_dataset=fds)
    for fc_name in fc_names:
        fc = os.path.join(ws, fds, fc_name)
        # do somthing with the fc
        print fc
#fc = r"E:\testing\test.gdb\b1"
fc_name1="area"
 
with arcpy.da.SearchCursor(fc_name1,"Shape@xy") as cursor:
	for row in cursor:
		print row

打印结果:

[u'jihetest']
E:\test\testcwd.mdb\jihetest\source2
E:\test\testcwd.mdb\jihetest\destination2
E:\test\testcwd.mdb\area
((6.790417257666718, 39.86516325366673),)
((6.92234888400003, 39.92592123933338),)
((6.823860585633426, 40.00989749142422),)

但是当使用C:\Python27\ArcGISx6410.7\python.exe环境,使用相同代码和数据,却不能获取mdb要素数据,打印结果如下:

[]
Traceback (most recent call last):
  File "D:/java/pycharmExample/ArcpyExample/ArcMapPython32/getListAndSearchFromMDB.py", line 18, in <module>
    with arcpy.da.SearchCursor(fc_name1,"Shape@xy") as cursor:
RuntimeError: cannot open 'area'

通过查找发现mdb在64位的python环境不被支持,详情见链接:
Python scripting with 64-bit processing - https://www.esri.com/arcgis-blog/products/arcgis-desktop/analytics/python-scripting-with-64-bit-processing/
Background Geoprocessing (64-bit) - https://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/64bit-background.htm
因此如果想获取要素数据集以及查询要素类,可以通过使用gdb或者使用python 32位环境来实现需求。


作者:gislaozhang

链接:https://blog.csdn.net/gislaozhang/article/details/100777929

来源:CSDN
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。