点集转线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 ...
随机推荐
- 我常用的 Python 调试工具 - 博客 - 伯乐在线
.ckrating_highly_rated {background-color:#FFFFCC !important;} .ckrating_poorly_rated {opacity:0.6;fi ...
- Centos7配置vsftpd3.0.2
1.安装vsftpd vsftp使用本地用户登陆方式 yum -y install vsftpd yum安装的版本3.0.2 2.配置vsftpd vim /etc/vsftpd/vsftpd.con ...
- 浅谈C、C++及其区别、兼容与不兼容
一.闲说C C语言之所以命名为C,是因为C语言源自Ken Thompson发明的B语言,而 B语言则源自BCPL语言. 1967年,剑桥大学的Martin Richards对CPL语言进行了简化,于是 ...
- mongo blancer
在 sharded cluster 体系结构中,Balancer 进程的作用是转移数据,当一个 shard 中的数据比其它 shard 的数据多并达到一定条件时,Balancer 进程触发. 为了减少 ...
- Redis(四)Redis高级
一Redis 数据备份与恢复 Redis SAVE 命令用于创建当前数据库的备份. 语法 redis Save 命令基本语法如下: redis 127.0.0.1:6379> SAVE 实例 r ...
- Spring Boot 实用MyBatis做数据库操作
前言: 本项目基于maven构建,使用mybatis-spring-boot作为spring-boot项目的持久层框架 spring-boot中使用mybatis持久层框架与原spring项目使用方式 ...
- 8-10 Coping Books uva714
题意:把一个包含m个正整数的序列划分为k个 1<=k<=m<=500的非空连续子序列 使得每个正整数恰好属于一个序列 设第i个序列的各个数之和为 Si 你的任务是让所有的 ...
- 004 关于Java如何扫描指定package下所有的类
q前言: 在工作中看到这个知识点,就顺便参考了百度的一些资料,整理一下,希望以后用的到. 一:理论部分 1.使用场景 写一个MVC框架,需要从包中扫描出组件并注册到容器中,而JDK没有提供现成的从方法 ...
- Python爬虫个人记录(三)爬取妹子图
这此教程可能会比较简洁,具体细节可参考我的第一篇教程: Python爬虫个人记录(一)豆瓣250 Python爬虫个人记录(二)fishc爬虫 一.目的分析 获取煎蛋妹子图并下载 http://jan ...
- Python爬虫个人记录(二) 获取fishc 课件下载链接
参考: Python爬虫个人记录(一)豆瓣250 (2017.9.6更新,通过cookie模拟登陆方法,已成功实现下载文件功能!!) 一.目的分析 获取http://bbs.fishc.com/for ...