使用python读取txt坐标文件生成挖空地块,并且批量生成。效果图如下:
# encoding:utf-8
import arcpy
import fileinput
import os
arcpy.env.workspace = r"F:\test.gdb"
fc = "polygon"
# 如果工作空间下不存在该FeatureClass,那么新建FeatureClass
isexist = arcpy.Exists(fc)
if not isexist:
arcpy.CreateFeatureclass_management(env, fc, "POLYGON",
spatial_reference="China Geodetic Coordinate System 2000.prj")
# 创建插入游标,txt坐标文件名称就是项目名称
cursor = arcpy.da.InsertCursor(fc, ["XMMC", "DKID", "DKMC", "MJ", "SHAPE@"])
# 遍历所有坐标文件
dirpath = r"F:\txt\\"
txtlist = os.listdir(dirpath)
txtname = ""
try:
# 遍历文件夹目录下所有的txt文件
for txtpath in txtlist:
txtname = txtpath.split(".")[0]
txt = fileinput.input(dirpath + txtpath)
rowstr = txt.readline()
rownum = 0
fieldlist = []
# 遍历单个txt坐标文件的坐标值
while rowstr:
fieldlist = rowstr.split(",")
fieldcount = len(fieldlist)
# 跳过txt坐标文件前面部门的属性描述
if fieldcount != 9:
rowstr = txt.readline()
continue
# 根据界址点数,读取坐标值
rownum = int(fieldlist[0])
dkid = fieldlist[2].decode("gbk")
dkmc = fieldlist[3].decode("gbk")
mj = float(fieldlist[1])
xyarray = arcpy.Array()
temparray = arcpy.Array()
wkarray = []
pnt = arcpy.Point()
# 标识当前的圈号
qhmark = 1
bh = 0
if fieldlist[8] == "@\n":
for i in range(rownum):
rowstr = txt.readline()
fieldlist = rowstr.split(",")
#首先读取圈号,如果圈号为1则为外圈,如果圈号大于1则为内圈,即挖空地块
qh = int(fieldlist[1])
if qh > 1:
if qhmark != qh:
#如果存在多个挖空,则把挖空地块存放在列表wkarray中
if len(temparray) > 0:
temppoly = arcpy.Polygon(temparray)
wkarray.append(temppoly)
#对于多个挖空地块,遍历下一个挖空地块时,先把上一个挖空地块的坐标从列表中清除
temparray.removeAll()
bh = 0
y = fieldlist[2]
x = fieldlist[3].replace("\n", "")
pnt.ID = i
pnt.X = x
pnt.Y = y
temparray.append(pnt)
bh = bh + 1
print "第{0}个界址点的坐标是:{1},{2}".format(bh, pnt.X, pnt.Y)
qhmark = qh
else:
y = fieldlist[2]
x = fieldlist[3].replace("\n", "")
pnt.ID = i
pnt.X = x
pnt.Y = y
temparray.append(pnt)
bh = bh + 1
print "第{0}个界址点的坐标是:{1},{2}".format(bh, pnt.X, pnt.Y)
#遍历到最后1行坐标,将最后1个挖空地块添加到列表wkarray中
if i == rownum - 1:
if len(temparray) > 0:
temppoly = arcpy.Polygon(temparray)
wkarray.append(temppoly)
#挖空地块处理完,就直接遍历下一行坐标
continue
#遍历外圈坐标
y = fieldlist[2]
x = fieldlist[3].replace("\n", "")
pnt.ID = i
pnt.X = x
pnt.Y = y
xyarray.append(pnt)
bh = bh + 1
print "第{0}个界址点的坐标是:{1},{2}".format(bh, pnt.X, pnt.Y)
poly = arcpy.Polygon(xyarray)
wkpolynum = len(wkarray)
#遍历挖空地块,并执行裁剪
for j in range(wkpolynum):
poly = poly.symmetricDifference(wkarray[j])
cursor.insertRow([txtname, dkid, dkmc, mj, poly])
xyarray.removeAll()
#print "地块{0}已经生成!".format(dkid)
rowstr = txt.readline()
print txtpath.decode("gbk") + " is finished!"
except Exception as err:
# print (err.args[0]).decode("gbk")
print err.args[0]
else:
print "全部生成!"
del cursor
测试数据如下:
16,0.853,地块1,地块1,面,,,,@
1,1,3821371.027,36521753.145
2,1,3821315.508,36521790.155
3,1,3821302.228,36521712.826
4,1,3821365.557,36521709.026
5,2,3821349.635,36521725.314
6,2,3821323.441,36521730.870
7,2,3821325.823,36521749.126
8,2,3821354.398,36521746.745
9,3,3821329.781,36521758.420
10,3,3821316.807,36521758.059
11,3,3821317.167,36521771.033
12,3,3821327.979,36521771.754
13,4,3821317.528,36521736.797
14,4,3821318.248,36521720.220
15,4,3821309.960,36521719.860
16,4,3821310.681,36521736.437

转载于:https://www.cnblogs.com/apromise/p/10150784.html

使用python读取txt坐标文件生成挖空地块_批量相关推荐

  1. 使用python读取txt坐标文件生成挖空矿山_探矿批量

    # -*-coding:utf-8-*- import arcpy import fileinput import os # 探矿权坐标格式举例 # 111.0846,31.1530 # 111.10 ...

  2. python读取坐标文本文件_使用python读取txt坐标文件生成挖空矿山_探矿批量

    # -*-coding:utf-8-*- import arcpy import fileinput import os # 探矿权坐标格式举例 # 111.0846,31.1530 # 111.10 ...

  3. python导入txt文件并绘图-Python读取txt数据文件,并作图

    import re #Errors=['验证通过!','身份证号码位数不对!','身份证号码出生日期超出范围或含有非法字符!','身份证号码校验错误!','身份证地区非法!'] def checkId ...

  4. python读取txt数据-Python读取txt数据文件,并作图

    import re #Errors=['验证通过!','身份证号码位数不对!','身份证号码出生日期超出范围或含有非法字符!','身份证号码校验错误!','身份证地区非法!'] def checkId ...

  5. python读取txt文件为dataframe,python批量读取txt文件为DataFrame

    我们有时候会批量处理同一个文件夹下的文件,并且希望读取到一个文件里面便于我们计算操作.比方我有下图一系列的txt文件,我该如何把它们写入一个txt文件中并且读取为DataFrame格式呢? 首先我们要 ...

  6. python读取txt文件的行数_python读取txt文件符合条件的行数-女性时尚流行美容健康娱乐mv-ida网...

    女性时尚流行美容健康娱乐mv-ida网 mvida时尚娱乐网 首页 美容 护肤 化妆技巧 发型 服饰 健康 情感 美体 美食 娱乐 明星八卦 首页 > 高级搜索 python 关系网图 pyth ...

  7. Python——读取txt文件每一行数据

    Python--读取txt文件每一行数据生成列表 一.例子1 (间隔符:逗号) 1.1 文件 1.2 代码 1.3 结果 二.例子2 (间隔符:空格) 2.1 文件 2.2 代码 2.3 结果 参考文 ...

  8. python删除重复值所在的行数_使用python读取txt文件的内容,并删除重复的行数方法...

    注意,本文代码是使用在txt文档上,同时txt文档中的内容每一行代表的是图片的名字. #coding:utf-8 import shutil readDir = "原文件绝对路经" ...

  9. python读取txt文件并画图

    1,使用python读取txt文件 已知txt文件内容如下: 0 01 12 43 94 165 256 36 请以第一列为x轴,第二列为y轴画图 步骤如下: 1)使用readlines读取文件 2) ...

  10. python读取txt文件并写入excel-Python读取txt内容写入xls格式excel中的方法

    由于xlwt目前只支持xls格式,至于xlsx格式,后面会继续更新 import xlwt import codecs def Txt_to_Excel(inputTxt,sheetName,star ...

最新文章

  1. 微软Print to PDF打印机提示参数错误的解决方法
  2. IOS-关闭(退)键盘事件--转
  3. Icomparer和Icomparable集合排序
  4. php课设报告致谢_PHP学生管理系统毕业论文设计.doc
  5. SQL基础E-R图画法(三)
  6. View 事件传递体系知识梳理(1) 事件分发机制
  7. 广数工业机器人五点法_广州数控工业机器人GR-C控制系统操作说明书(2014年11月.pdf...
  8. React antd的table表格之嵌套表格
  9. java浮点数转整数_(题目2)自己实现浮点数转换为整数
  10. ARM CORTEX M3
  11. domoticz 使用esp8266通过mqtt控制灯开关
  12. 实践《如何使用Seata保证Dubbo微服务间的一致性》
  13. 二零年的十一月开始 努力做个极简的人
  14. PHP开发API接口代码展示
  15. 2021年广东专插本计算机专业学校,2021年广东省专插本学校名单和专业,广东专插本有哪些学校和那些专业...
  16. 稳定匹配(解决婚姻问题)
  17. 【贪心】中山纪念中学暑期游Day12——少女觉
  18. 商标注册申请的步骤是怎样的
  19. 【开源分享】一款开源支持多端发布的商城系统
  20. docker部署jar包的几种方式

热门文章

  1. appium相关记录
  2. IntelliJ IDEA使用技巧——关于版本控制(上)
  3. Android开发之使用GridView+仿微信图片上传功能(附源代码)
  4. memcache的简单应用
  5. Centos 6.8 为自己打造Linux小系统
  6. box-align,box-pack实现元素垂直底部对齐
  7. python异步回调函数的实现
  8. 怎么样更好的做好站内的优化
  9. C# 线程知识--异步编程模型(APM)
  10. 选择北大青鸟的九大理由