多语言展示
当前在线:1081今日阅读:159今日分享:18

使用 Arcpy 读取要素类并转成Html

1 Read the TableIf you want to read the feature class or table by Arcpy, you first need to know Data Access Model.The data access module,arcpy.da, is a Python module for working with data. It allows control of the edit session, edit operation, improved cursor support (including faster performance), functions for converting tables and feature classes to and from NumPy arrays, and support for versioning, replicas, domains, and subtypes workflows. Class ofdata access module Data Access classesFirst,we need to get the fields of Table, the function of ListFileds will be used:fields = arcpy.ListFields(tablePath)tablePath means the path of table of what you want to read.Then, create a array for fields and append it:fieldNames = []for field in fields: if (field.type <> 'Geometry' and field.type <> 'BLOB'): fieldNames.append(field.name) outfile.write('\n')outfile.write('\n')Then,we will write the name of field:for fieldName in fieldNames: outfile.write('\n') outfile.write('\n')Finally, we will use the class of SearchCursor to write the data:for row in arcpy.da.SearchCursor(tablePath, fieldNames): outfile.write('\n') for value in row: outfile.write('\n') outfile.write('\n')outfile.write('
' + fieldName + '
' + str(value) + '
\n')All of the program is here:import arcpyimport sysimport stringimport ostablePath = arcpy.GetParameterAsText(0)filePath = arcpy.GetParameterAsText(1)outfile = open(filePath, 'w')fields = arcpy.ListFields(tablePath)fieldNames = []for field in fields: if (field.type <> 'Geometry' and field.type <> 'BLOB'): fieldNames.append(field.name) outfile.write('\n')outfile.write('\n')for fieldName in fieldNames: outfile.write('\n') outfile.write('\n')for row in arcpy.da.SearchCursor(tablePath, fieldNames): outfile.write('\n') for value in row: outfile.write('\n') outfile.write('\n')outfile.write('
' + fieldName + '
' + str(value) + '
\n')outfile.flush()outfile.close()The Result is just like that:
推荐信息