import arcpy import math def ZXpoint(shppath,outpath): txtpath = outpath + '\\ZXpoint.txt' arcpy.MakeFeatureLayer_management(shppath, 'SHP') with open(txtpath,'w') as line: with arcpy.da.SearchCursor('SHP', ['SHAPE@', '宗地编号']) as cursorA: for curA in cursorA: zdbh = curA[1] shp1 = curA[0] #中心点的计算 ceny = (shp1.extent.YMax + shp1.extent.YMin)/2 cenx = (shp1.extent.XMax + shp1.extent.XMin)/2 line.write(zdbh + ':' + str(round(cenx,4)) + ',' + str(round(ceny,4))) line.write('\n') if __name__ == '__main__': try: # 输入shp,输出界址点文件夹 ZXpoint(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1)) except arcpy.ExecuteError: arcpy.AddMessage(arcpy.GetMessages())