点集转线python最优代码
import arcpy
import os
import types def convertPoints():
arcpy.env.overwriteOutput = True inPts = arcpy.GetParameterAsText(0) # Input point FC
outFeatures = arcpy.GetParameterAsText(1) # Output FC
IDField = arcpy.GetParameterAsText(2) # Feature Field
sortField = arcpy.GetParameterAsText(3) # Sort Field
closeLine = arcpy.GetParameterAsText(4) # Close Line or Leave Open if IDField in ["", "#"]: IDField = None if sortField in ["", "#"]:
cursorSort = IDField
else:
if IDField:
cursorSort = IDField + ";" + sortField
else:
cursorSort = sortField if not isinstance(closeLine, types.BooleanType):
if closeLine.lower() == "false":
close = False
else:
close = True convertPointsToLine(inPts, outFeatures, IDField, cursorSort, close) def getZM(propType, hasMZ):
envValue = getattr(arcpy.env, propType).upper() if envValue in ['ENABLED', 'DISABLED']:
return envValue
else:
if hasMZ:
return "ENABLED"
else:
return "DISABLED" def convertPointsToLine(inPts, outFeatures, IDField, cursorSort, close):
try:
# Assign empty values to cursor and row objects
iCur, sRow, feat = None, None, None desc = arcpy.Describe(inPts)
shapeName = desc.shapeFieldName # Create the output feature class
outPath, outFC = os.path.split(outFeatures)
arcpy.CreateFeatureclass_management(outPath, outFC, "POLYLINE", "",
getZM("outputMFlag", desc.hasM),
getZM("outputZFlag", desc.hasZ),
inPts) outShapeName = arcpy.Describe(outFeatures).shapeFieldName # If there is an IDField, add the equivalent to the output
if IDField:
f = arcpy.ListFields(inPts, IDField)[0]
fName = arcpy.ValidateFieldName(f.name, outPath)
arcpy.AddField_management(outFeatures, fName, f.type, f.precision, f.scale, f.length,
f.aliasName, f.isNullable, f.required, f.domain) # Open an insert cursor for the new feature class
iCur = arcpy.InsertCursor(outFeatures) # Create an array needed to create features
array = arcpy.Array() # Initialize a variable for keeping track of a feature's ID.
ID = -1
fields = shapeName
if cursorSort:
fields += ";" + cursorSort for sRow in arcpy.gp.SearchCursor(inPts, "", None, fields, cursorSort, arcpy.env.extent):
pt = sRow.getValue(shapeName).getPart(0)
if IDField:
currentValue = sRow.getValue(IDField)
else:
currentValue = None if ID == -1:
ID = currentValue if ID <> currentValue:
if array.count >= 2: # To close, add first point to the end
#
if close:
array.add(array.getObject(0)) feat = iCur.newRow()
if IDField:
if ID: #in case the value is None/Null
feat.setValue(IDField, ID)
feat.setValue(outShapeName, array)
iCur.insertRow(feat)
else:
arcpy.AddIDMessage("WARNING", 1059, unicode(ID)) array.removeAll() array.add(pt)
ID = currentValue # Add the last feature
if array.count > 1:
# To close, add first point to the end
if close:
array.add(array.getObject(0)) feat = iCur.newRow()
if IDField:
if ID: #in case the value is None/Null
feat.setValue(IDField, currentValue)
feat.setValue(outShapeName, array)
iCur.insertRow(feat)
else:
arcpy.AddIDMessage("WARNING", 1059, unicode(ID))
array.removeAll() except Exception as err:
import traceback
arcpy.AddError(
traceback.format_exception_only(type(err), err)[0].rstrip()) finally:
if iCur:
del iCur
if sRow:
del sRow
if feat:
del feat try:
# Update the spatial index(es)
#
r = arcpy.CalculateDefaultGridIndex_management(outFeatures)
arcpy.AddSpatialIndex_management(outFeatures, r.getOutput(0), r.getOutput(1), r.getOutput(2))
except:
pass if __name__ == '__main__':
convertPoints()
点集转线python最优代码的更多相关文章
- python 常忘代码查询 和autohotkey补括号脚本和一些笔记和面试常见问题
笔试一些注意点: --,23点43 今天做的京东笔试题目: 编程题目一定要先写变量取None的情况.今天就是因为没有写这个边界条件所以程序一直不对.以后要注意!!!!!!!!!!!!!!!!!!!!! ...
- <转>机器学习系列(9)_机器学习算法一览(附Python和R代码)
转自http://blog.csdn.net/han_xiaoyang/article/details/51191386 – 谷歌的无人车和机器人得到了很多关注,但我们真正的未来却在于能够使电脑变得更 ...
- 机器学习算法的基本知识(使用Python和R代码)
本篇文章是原文的译文,然后自己对其中做了一些修改和添加内容(随机森林和降维算法).文章简洁地介绍了机器学习的主要算法和一些伪代码,对于初学者有很大帮助,是一篇不错的总结文章,后期可以通过文中提到的算法 ...
- Python 坑爹之 代码缩进
建议:统一使用空格!!!!!!!!!不要Tab Python代码缩进 这两天python-cn邮件列表有一条thread发展的特别长,题目是<python的代码缩进真是坑爹>(地址), ...
- Python第一行代码
Python版本:Python 3.6.1 0x01 命令行交互 在交互式环境的提示符>>>下,直接输入代码,按回车,就可以立刻得到代码执行结果.现在,试试输入100+200,看看计 ...
- python的PEP8 代码风格指南
PEP8 代码风格指南 这篇文章原文实际上来自于这里:https://www.python.org/dev/peps/pep-0008/ 知识点 代码排版 字符串引号 表达式和语句中的空格 注释 版本 ...
- 用python处理html代码的转义与还原
用python处理html代码的转义与还原 转义 escape: import cgi s = cgi.escape("""& < >" ...
- 【转】利用Boost.Python将C++代码封装为Python模块
用Boost.Python将C++代码封装为Python模块 一. 基础篇 借助Boost.Python库可以将C/C++代码方便.快捷地移植到python模块当中,实现对python模块的扩 ...
- python爬虫小说代码,可用的
python爬虫小说代码,可用的,以笔趣阁为例子,python3.6以上,可用 作者的QQ:342290433,汉唐自远工程师 import requests import refrom lxml i ...
随机推荐
- nginx + tomcat 集群记录
昨天晚写的时候已经下班了.时间紧迫.写的略简! 昨天说过.接到部署的任务之后.首先想到的是apache httpserver 毕竟pache.我们接触的比较多!然而部署之后遇到了很多问题.比如apac ...
- GreenPlum学习笔记:create table创建表
二维表同样是GP中重要的存储数据对象,为了更好的支持数据仓库海量数据的访问,GP的表可以分成: 面向行存储的普通堆积表 面向列存储的AOT表(append only table) 当然AOT表也可以是 ...
- linux的IPC进程通信方式-匿名管道(一)
linux的IPC进程通信-匿名管道 什么是管道 如果你使用过Linux的命令,那么对于管道这个名词你一定不会感觉到陌生,因为我们通常通过符号"|"来使用管道,但是管道的真正定义是 ...
- box-sizing定义的盒模型之间的区别
- Kylin使用笔记-1: 安装
2016年1月14日 9:57:23 星期四 背景介绍 Apache Kylin是一个开源的分布式分析引擎,提供Hadoop之上的SQL查询接口及多维分析(OLAP)能力以支持超大规模数据,最 ...
- 【POJ】4007.Flood-it!
原题戳这里 题解 搜索是个好东西,不是人人都会搜 迭代加深,然后用一个函数估值,值是除了和左上连通的部分还有几个颜色不同的块,如果走的步数加上估值大于当前枚举的深度就跳出 代码 #include &l ...
- windows下mysql配置(第一次)
忙活了大半天,总算配置好了,本文献给windows下没试用过Mysql的小白,勿喷 http://blog.csdn.net/z1074907546/article/details/51482718 ...
- Emacs 编辑verilog 学习日记
终于开始写博客啦.以前一直打算写.由于工作忙一次次延期了.写博客的好处不必多说. 以前有一些学习心得总是用一个word,或者note记录一些.时间久了都不知道弄哪儿去了.. 从今天开始记录学习中 ...
- mysql 错误解决:Plugin 'FEDERATED' is disabled. /usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
今天安装完Mysql后,开启发生了错误: 1.打开相应文件夹,查看错误信息: 2.打开错误信息文件,查看错误原因是:Plugin 'FEDERATED' is disabled. /usr/sbin/ ...
- HTTP/FTP压力测试工具siege
HTTP/FTP压力测试工具siege 压力测试可以检测服务器的承载能力.针对HTTP和FTP服务,Kali Linux提供专项工具siege.该工具可以模拟多个用户同时访问同一个网站的多个网页, ...