#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
土地报批文件转SHP
最新推荐文章于 2024-08-03 19:27:22 发布