点集转线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 ...
随机推荐
- Introduction to MWB Minor Mode
Introduction to MWB Minor Mode */--> Table of Contents 1. Introduction 2. Usage 1 Introduction MW ...
- 20165203迭代和JDB测试
1.使用C(n,m)=C(n-1,m-1)+C(n-1,m)公式进行递归编程实现求组合数C(m,n)的功能 public class C { public static void main(Strin ...
- Python的简单语法(一)
import sys a=3 b=4 c=5.66 d=8.0 e=complex(c,d) f=complex(float(a),float(b)) print("a is type:&q ...
- nginx+keepalived高可用服务器宕机解决方案
http://blog.51cto.com/gdutcxh/2109841 https://blog.csdn.net/winsonyuan/article/details/52784988
- O(n log log n)实现FGT和FLT(Fast GCD/LCM Transformation)
本文是作者看不懂分治FFT之后开始娱乐一下自己写的 看到一道题时候询问了正解后,推出了一个奇怪的变换,发现这个很Transformation,我和正解推出来的奇怪的东西是一样的,但还是想写一下思路.. ...
- linux下解除端口占用
1.找出占用端口进程的pid sudo lsof -i:port 2.终止进程 pid
- matlab .fig转化成pdf 缺失
1. 在matlab figure里面,Edit -> Copy Figure 2. 粘贴到ppt中即可
- JAVAEE——淘淘商城第一天:电商行业的背景和技术特点,商城的介绍、技术的选型、系统架构和工程搭建
1. 学习计划 1.电商行业的背景. 2.电商行业的技术特点 3.商城的介绍 a) 常用的名词介绍 b) 系统功能介绍 4.淘淘商城的系统架构 a) 传统架构 b) 分布式架构 c) 基于服务的架构 ...
- poj1273(Edmonds-Karp)
这道题可以算是例题了. 求解最大流,采用EK算法,用广搜查找增广路径,找到后更新网络流矩阵,循环执行直至找不到增广路径为止.这里要小心的是重复边的情况. 程序也是参照了网上的模版来写的,有一些技巧.如 ...
- windows下thrift的使用(C++)
thrift cpp环境搭建: 1. 安装boost_1_53_0,注意,使用vs2010版本时,使用二进制的boost安装版本,生成的lib有可能是,在后续操作会出问题.在源码目录中,运行boot ...