土地报批文件转SHP

#coding=utf-8
import os
import arcpy
import io
arcpy.env.overwriteOutput = True
txt_folder = os.getcwd()
txts = os.listdir(txt_folder)
txts = [i for i in txts if i.endswith("txt") and \
        not i.startswith("~$")]
arcpy.CreateFileGDB_management(txt_folder, "fGDB.gdb", "10.0")
GDB = os.path.join(txt_folder, "fGDB.gdb")
spr = {"3-36": 4524, "3-37": 4525, "3-38": 4526, "3-39": 4527, "6-19": 4497, "6-20": 4498}
for txt in txts:
    name = os.path.splitext(txt)[0]
    txt_p = os.path.join(txt_folder, txt)

    fffs = io.open(txt_p,"r")
    input_data = fffs.readlines()
    fffs.close()
    n = -1
    list1 = []
    for i1 in input_data:
        n += 1
        if "@" in i1:
            list1.append(n)
        if u"几度分带" in i1:
            sprfd = i1[-2]
            # print(sprfd)
        if u"带号" in i1:
            sprdh = i1[-3:-1]
            # print(sprdh)

            sp = spr[str(sprfd) + "-" + str(sprdh)]
            print (sp)


    createFC = arcpy.CreateFeatureclass_management(GDB, "T" + name, "POLYGON",spatial_reference = sp)
    arcpy.AddField_management(createFC, "JZDS", "LONG")
    arcpy.AddField_management(createFC, "DKMJ", "FLOAT")
    arcpy.AddField_management(createFC, "DKBH", "TEXT", 254)

    arcpy.AddField_management(createFC, "DKMC", "TEXT", 254)
    arcpy.AddField_management(createFC, "TFH", "TEXT", 254)

    arcpy.AddField_management(createFC, "DKYT", "TEXT", 254)
    arcpy.AddField_management(createFC, "TXLX", "TEXT", 254)
    arcpy.AddField_management(createFC, "DLBM", "TEXT", 254)
    list1.append(len(input_data))
    list2 = [list1[i:i + 2] for i in range(0, len(list1), 1)]
    # list2.pop()
    list2.pop(-1)
    for i2 in list2:
        # print (i2)
        a = i2.pop(0)
        # print (a)
        b = i2.pop(0)
        # print (b)
        ab = input_data[a:b]
        # ab.pop(0)
        ab.pop()
        ab1 = ab.pop(0)
        ab2 = ab1[:-1].split(",")  # 每条属性首行划分
        # for i in ab2:
            # print (i)
        if ab2[0] == '':
            jzds = 0
        if ab2[0] != '':
            jzds = ab2[0]
        if ab2[1] == '':
            dkmj = 0
        if ab2[1] != '':
            dkmj = ab2[1]
        if ab2[2] == '':
            bh = ''
        if ab2[2] != '':
            bh = ab2[2]
        if ab2[3] == '':
            mc = ''
        if ab2[3] != '':
            mc = ab2[3]
        if ab2[4] == '':
            lx = ''
        if ab2[4] != '':
            lx = ab2[4]
        if ab2[5] == '':
            tfh = ''
        if ab2[5] != '':
            tfh = ab2[5]
        if ab2[6] == '':
            yt = ''
        if ab2[6] != '':
            yt = ab2[6]
        if ab2[7] != '':
            dlbm = ab2[7]
        if ab2[7] == '':
            dlbm = ''
        m = arcpy.Array()
        cursor = arcpy.da.InsertCursor(createFC,
                                        ["SHAPE@", "JZDS", "DKMJ", "DKBH", "DKMC", "TFH", "DKYT", "TXLX", "DLBM"])
        for i3 in ab:
            s = i3.split(",")
            t = arcpy.Point(s[3], s[2])
            m.add(t)
        polygon = arcpy.Polygon(m)
        # cursor.insertRow([polygon, 1, 1, 1, 1, 1, 1, 1, 1])
        cursor.insertRow([polygon, jzds, dkmj, bh, mc, tfh, yt, lx, dlbm])
        del cursor

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值