arcgis python 参数验证
import arcpy
class ToolValidator(object):
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog.""" def __init__(self):
"""Setup arcpy and the list of tool parameters."""
self.params = arcpy.GetParameterInfo() def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
return def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
if self.params[0].value:
try:
desc = arcpy.Describe(self.params[0].value)
shapeType = desc.shapeType
sr = desc.spatialReference
gcsOrMercator = False if not sr.GCSName and sr.PCSName.upper().find("MERCATOR") == -1 else True if shapeType.upper() == "POINT":
self.params[1].filter.list = ["POINT_X_Y_Z_M"]
elif shapeType.upper() == "MULTIPOINT":
self.params[1].filter.list = ["CENTROID", "PART_COUNT", "EXTENT"]
elif shapeType.upper() == "POLYLINE":
if desc.hasZ:
lineList = ["LENGTH", "LENGTH_GEODESIC", "LENGTH_3D", "LINE_START_MID_END", "CENTROID", "CENTROID_INSIDE", "PART_COUNT", "POINT_COUNT", "LINE_BEARING", "EXTENT"]
else:
lineList = ["LENGTH", "LENGTH_GEODESIC", "LINE_START_MID_END", "CENTROID", "CENTROID_INSIDE", "PART_COUNT", "POINT_COUNT", "LINE_BEARING", "EXTENT"]
self.params[1].filter.list = lineList
if gcsOrMercator:
lineList.remove("LENGTH")
if desc.hasZ:
lineList.remove("LENGTH_3D")
self.params[1].filter.list = lineList
elif shapeType.upper() == "POLYGON":
polyList = ["AREA", "AREA_GEODESIC", "PERIMETER_LENGTH", "PERIMETER_LENGTH_GEODESIC", "CENTROID", "CENTROID_INSIDE", "LINE_START_MID_END", "PART_COUNT", "POINT_COUNT", "EXTENT"]
self.params[1].filter.list = polyList
if gcsOrMercator:
polyList.remove("AREA")
polyList.remove("PERIMETER_LENGTH")
self.params[1].filter.list = polyList if self.params[1].value:
self.params[5].parameterDependencies = [0]
self.params[5].schema.clone = True
newFields = []
propDict = {"POINT_X_Y_Z_M": ["POINT_X",
"POINT_Y",
"POINT_Z",
"POINT_M"],
"PART_COUNT": ["PART_COUNT"],
"CENTROID": ["CENTROID_X",
"CENTROID_Y",
"CENTROID_Z",
"CENTROID_M"],
"EXTENT": ["EXT_MIN_X",
"EXT_MIN_Y",
"EXT_MAX_X",
"EXT_MAX_Y"],
"POINT_COUNT": ["PNT_COUNT"],
"LINE_START_MID_END": ["START_X",
"START_Y",
"START_Z",
"START_M",
"MID_X",
"MID_Y",
"MID_Z",
"MID_M",
"END_X",
"END_Y",
"END_Z",
"END_M"],
"LINE_BEARING": ["BEARING"],
"CENTROID_INSIDE": ["INSIDE_X",
"INSIDE_Y",
"INSIDE_Z",
"INSIDE_M"],
"LENGTH": ["LENGTH"],
"PERIMETER_LENGTH": ["PERIMETER"],
"AREA": ["POLY_AREA"],
"LENGTH_GEODESIC": ["LENGTH_GEO"],
"AREA_GEODESIC": ["AREA_GEO"],
"LENGTH_3D": ["LENGTH_3D"],
"PERIMETER_LENGTH_GEODESIC":["PERIM_GEO"],
}
currentFields = [x.name for x in desc.fields]
for prop in str(self.params[1].value).split(";"):
try:
for field in propDict[prop]:
if not field in currentFields:
newField = arcpy.Field()
newField.type, newField.name = "DOUBLE", field
newFields.append(newField)
except:
pass
self.params[5].schema.additionalFields = newFields
except:
pass
return def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
============================================================
class ToolValidator:
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog.""" def __init__(self):
"""Setup the Geoprocessor and the list of tool parameters."""
import arcpy
self.params = arcpy.GetParameterInfo() def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
return def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parmater
has been changed."""
import arcpy if self.params[0].value:
mxd = arcpy.mapping.MapDocument(self.params[0].value.value) #The following will display an error if mxd is not DDP enabled
testDDP = mxd.dataDrivenPages #Generate unique list of layer names
lyrs = arcpy.mapping.ListLayers(mxd)
layerList = []
for lyr in lyrs:
layerList.append(lyr.name)
uniqueLayerList = list(set(layerList))
uniqueLayerList.sort() if not self.params[1].altered:
self.params[1].filter.list = uniqueLayerList #Generate unique list of field names
if self.params[1].altered:
selectedLayer = self.params[1].value
layerRef = arcpy.mapping.ListLayers(mxd, selectedLayer)[0]
fields = arcpy.ListFields(layerRef.dataSource)
fieldList = []
for field in fields:
fieldList.append(field.name)
uniqueFieldList = list(set(fieldList))
uniqueFieldList.sort()
self.params[2].filter.list = uniqueFieldList #Generate unique list of page names
if self.params[2].altered:
fieldName = self.params[2].value
rows = arcpy.SearchCursor(layerRef.dataSource)
row = rows.next()
pageNameList = []
while row:
if row.getValue(fieldName) not in pageNameList:
pageNameList.append(row.getValue(fieldName))
row = rows.next()
pageNameList.sort()
self.params[3].filter.list = pageNameList #Generate the printer list
printerList = arcpy.mapping.ListPrinterNames()
if not self.params[1].altered:
self.params[4].filter.list = printerList return def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
arcgis python 参数验证的更多相关文章
- arcgis python 参数类型和含义
数据类型 datatype 关键字 描述 地址定位器 DEAddressLocator 用于地理编码的数据集,存储地址属性.关联的索引以及用于定义将地点的非空间描述转换为空间数据这一过程的规则. 地址 ...
- ArcGIS Python人门到精通目录基于ArcGIS10.2,100以上案例15章42个视频806分钟,51GIS网站上线
ArcGIS Python人门到精通目录 闫老师 QQ:276529800 微信13108507190 1. ArcGIS Python基础 1.1 ArcGIS为什么学习Python 1.2 A ...
- 【ArcGIS遇上Python】ArcGIS Python批处理入门到精通实用教程目录
目录 1. 专栏简介 2. 专栏地址 3. 专栏目录 1. 专栏简介 Python语言是目前很火热的语言,极大的促进了人工智能发展.你知道在ArcGIS中也会有python的身影吗?事实上,在ArcG ...
- C# 中参数验证方式的演变
一般在写方法的时候,第一步就是进行参数验证,这也体现了编码者的细心和缜密,但是在很多时候这个过程很枯燥和乏味,比如在拿到一个API设计文档的时候,通常会规定类型参数是否允许为空,如果是字符可能有长度限 ...
- Java和C#下的参数验证
参数的输入和验证问题是开发时经常遇到的,一般的验证方法如下: public bool Register(string name, int age) { if (string.IsNullOrEmpty ...
- DUBBO参数验证
public class ValidationParameter implements Serializable { private static final long seria ...
- ASP.NET WebAPI 11 参数验证
在绑定完Action的所有参数后,WebAPI并不会马上执行该方法,而要对参数进行验证,以保证输入的合法性. ModelState 在ApiController中一个ModelState属性用来获取参 ...
- C# 中参数验证方式
C# 中参数验证方式 一般在写方法的时候,第一步就是进行参数验证,这也体现了编码者的细心和缜密,但是在很多时候这个过程很枯燥和乏味,比如在拿到一个API设计文档的时候,通常会规定类型参数是否允许为空, ...
- 自动化CodeReview - ASP.NET Core请求参数验证
自动化CodeReview系列目录 自动化CodeReview - ASP.NET Core依赖注入 自动化CodeReview - ASP.NET Core请求参数验证 参数验证实现 在做服务端开发 ...
随机推荐
- springboot项目命linux环境下命令启动
测试环境:dev nohup java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 \-Dcom.s ...
- OpenStack kilo版(1) 部署环境
硬件 VMware workstation虚拟机 Ubuntu14.04操作系统 虚拟机网络规划 管理网络: eth0, 桥接模式 10.0.0.0/24 外部网络: eth1, nat模式(需要关闭 ...
- ASE —— 第一次结对作业
问题定义 游戏规则: N个玩家,每人写一个或两个0~100之间的有理数 (不包括0或100),提交给服务器,服务器在当前回合结束时算出所有数字的平均值,然后乘以0.618,得到G值. 提交的数字最靠近 ...
- pytorch训练模型的一些坑
1. 图像读取 opencv的python和c++读取的图像结果不一致,是因为python和c++采用的opencv版本不一样,从而使用的解码库不同,导致读取的结果不同. 详细内容参考:https:/ ...
- 用js刷剑指offer(链表中倒数第k个结点)
题目描述 输入一个链表,输出该链表中倒数第k个结点. 牛客网链接 思路 设置两个指针,p,q,先让p走k-1步,然后再一起走,直到p为最后一个 时,q即为倒数第k个节点 js代码 // 空间复杂度1 ...
- jade-if-else-unless-case
if else - var lession = ['node','jade'] if lession if lession.length > 2 p 1 #{lession.join(', ') ...
- 系统---添加一个相机的IP实现opencv读取rstp视频流
系统---添加一个相机的IP实现opencv读取视频流 这里: 第一步,添加一个6段的相机IP地址:先ping 一个IP地址,ping通的是再用的IP,不可添加:ping不通的,添加IP到网络. 第二 ...
- 在 java 程序中怎么保证多线程的运行安全?(未完成)
在 java 程序中怎么保证多线程的运行安全?(未完成)
- CDN加速地址URL拿不到,显示“无法访问此网站”
问题:CDN加速地址URL拿不到,显示“无法访问此网站” 原因:浏览器缓冲原因,导致拿到的content-encoding不是一个标准的值 解决方法: 1. 客户机器 ping一下访问的CDN加速域名 ...
- js 获取扫码枪信息
---- js 获取扫码枪不需要记录 lastCode 啊,只需要在时间超出范围的时候重置 lastTime 和 code 就行了.如果 码枪会输入回车,那就在 keyCode === 13 的时候使 ...