arapy生成面数据

已有数据:区域的点数据

一个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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值