arcpy 批量读取文件夹下所有shp文件的属性
包括属性表数据
中心点经纬度
上下左右经纬度 Xmin,Xmax,Ymin,Ymax
def get_property_sheet(shp_path): """ :param inshp: 输入的shp文件 :return: """ try: for infiles in os.listdir(shp_path): inshp = shp_path + infiles if inshp[-4:] == '.shp': print inshp # 获取shp文件的属性表数据 cond = ['NAME2004','AD2004','SHAPE@X', 'SHAPE@Y'] with arcpy.da.SearchCursor(inshp, cond) as cursor: for row in cursor: result = row # 讀取上下左右的經緯度最大最小值 with arcpy.da.SearchCursor(inshp, 'SHAPE@') as cursor: for row in cursor: resultcode = row[0].extent resultcode = str(resultcode).split() if str(result[1]) =='000000': parent_code = '' area_level = 'quanguo' elif str(result[1])[2:] =='0000': parent_code = '000000' area_level = 'province' elif str(result[1])[4:] =='00': parent_code =str(result[1])[:2]+'0000' area_level = 'city' else: parent_code = str(result[1])[:4] + '00' area_level = 'county' # 保存数据到数据表 print result[0], str(result[1]) ,parent_code, 'S', area_level, result[2], result[3], resultcode[0], resultcode[2], resultcode[3] center_x = result[2], # 中心点经度 center_y = result[3], # 中心点维度 min_x = resultcode[0], # shp左边界 max_x = resultcode[2], # shp右边界 min_y = resultcode[1], # shp下边界 max_y = resultcode[3])# shp上边界) except Exception,e: print traceback.format_exc(e)