已有数据:区域的点数据
一个cad的图幅号数据(图幅号跟左下角坐标有关)
代码
# -*- coding: utf-8 -*- # @File : expandmappabled.py # @Date : 2022-10-31-09 # @Author : DHDX-ZHANGXIANG import copy import arcpy import xlrd import os import xlwt import sys # 导入sys模块 sys.setrecursionlimit(9000) # 将默认的递归深度修改为3000 # 获取路径 path = os.getcwd() path_base = os.path.join(path, "basedata") path_work = os.path.join(path, "work") basefile = os.path.join(path_work, "coor.xls") def writeRow(coor): global count polyright = copy.deepcopy(coor) polyleft = copy.deepcopy(coor) polytop = copy.deepcopy(coor) polybottom = copy.deepcopy(coor) polynext = copy.deepcopy(coor) polylist = [polyright, polyleft, polytop, polybottom] # 判断是否超出范围 if polynext["p3"][0] > polyexpand["xmin"]: if polynext["p3"][1] > polyexpand["ymin"]: if polynext["p1"][0] < polyexpand["xmax"]: if polynext["p1"][1] < polyexpand["ymax"]: num = 0 sheet.write(count, num, count) num += 1 for item in coor: if len(coor[item]) == 2: polyleft[item][0] = coor[item][0] - 250 polyright[item][0] = coor[item][0] + 250 polytop[item][0] = coor[item][0] polybottom[item][0] = coor[item][0] polyleft[item][1] = polyleft[item][1] polyright[item][1] = polyright[item][1] polytop[item][1] = polytop[item][1] + 250 polybottom[item][1] = polybottom[item][1] - 250 for poly in polylist: # print(poly["p3"]) a = str(poly["p3"][1])[:4] + "." b = str(poly["p3"][1])[4:6] + "-" c = str(poly["p3"][0])[:3] + "." d = str(poly["p3"][0])[3:5] poly["mapcode"] = a + b + c + d # print(poly["mapcode"]) # print(poly["mapcode"]) if poly["mapcode"] not in mapcode: mapcode.append(poly["mapcode"]) # print(poly) # 写入excel sheet.write(count, 0, count) sheet.write(count, 1, poly["p1"][0]) sheet.write(count, 2, poly["p1"][1]) sheet.write(count, 3, poly["p2"][0]) sheet.write(count, 4, poly["p2"][1]) sheet.write(count, 5, poly["p3"][0]) sheet.write(count, 6, poly["p3"][1]) sheet.write(count, 7, poly["p4"][0]) sheet.write(count, 8, poly["p4"][1]) sheet.write(count, 9, poly["p1"][0]) sheet.write(count, 10, poly["p1"][1]) sheet.write(count, 11, poly["mapcode"]) count += 1 # print(count) writeRow(poly) return return return if __name__ == '__main__': book = xlwt.Workbook(encoding='utf-8', style_compression=0) sheet = book.add_sheet("coor", cell_overwrite_ok=True) title = ['pcode', 'p1x', 'p1y', 'p2x', 'p2y', 'p3x', 'p3y', 'p4x', 'p4y', 'p5x', 'p5y', 'mapcode'] for i in title: sheet.write(0, title.index(i), i) # 已知的其中一个cad的数据 polystar = { "p1": [511250, 3691000], "p2": [511250, 3690750], "p3": [511000, 3690750], "p4": [511000, 3691000], "mapcode": "3690.75-511.00" } # 边界 polyexpand = { "xmin": 518000, "xmax": 520200, "ymin": 3689600, "ymax": 3695200 } # 防止重复调用 mapcode = [polystar["mapcode"]] # 写入的行数 count = 1 writeRow(polystar) book.save(basefile) pass