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 参数验证的更多相关文章

  1. arcgis python 参数类型和含义

    数据类型 datatype 关键字 描述 地址定位器 DEAddressLocator 用于地理编码的数据集,存储地址属性.关联的索引以及用于定义将地点的非空间描述转换为空间数据这一过程的规则. 地址 ...

  2. ArcGIS Python人门到精通目录基于ArcGIS10.2,100以上案例15章42个视频806分钟,51GIS网站上线

    ArcGIS Python人门到精通目录 闫老师 QQ:276529800 微信13108507190 1.  ArcGIS Python基础 1.1  ArcGIS为什么学习Python 1.2 A ...

  3. 【ArcGIS遇上Python】ArcGIS Python批处理入门到精通实用教程目录

    目录 1. 专栏简介 2. 专栏地址 3. 专栏目录 1. 专栏简介 Python语言是目前很火热的语言,极大的促进了人工智能发展.你知道在ArcGIS中也会有python的身影吗?事实上,在ArcG ...

  4. C# 中参数验证方式的演变

    一般在写方法的时候,第一步就是进行参数验证,这也体现了编码者的细心和缜密,但是在很多时候这个过程很枯燥和乏味,比如在拿到一个API设计文档的时候,通常会规定类型参数是否允许为空,如果是字符可能有长度限 ...

  5. Java和C#下的参数验证

    参数的输入和验证问题是开发时经常遇到的,一般的验证方法如下: public bool Register(string name, int age) { if (string.IsNullOrEmpty ...

  6. DUBBO参数验证

    public class ValidationParameter implements Serializable {           private static final long seria ...

  7. ASP.NET WebAPI 11 参数验证

    在绑定完Action的所有参数后,WebAPI并不会马上执行该方法,而要对参数进行验证,以保证输入的合法性. ModelState 在ApiController中一个ModelState属性用来获取参 ...

  8. C# 中参数验证方式

    C# 中参数验证方式 一般在写方法的时候,第一步就是进行参数验证,这也体现了编码者的细心和缜密,但是在很多时候这个过程很枯燥和乏味,比如在拿到一个API设计文档的时候,通常会规定类型参数是否允许为空, ...

  9. 自动化CodeReview - ASP.NET Core请求参数验证

    自动化CodeReview系列目录 自动化CodeReview - ASP.NET Core依赖注入 自动化CodeReview - ASP.NET Core请求参数验证 参数验证实现 在做服务端开发 ...

随机推荐

  1. 整理一下Promise 的用法

    Promise 的定义 Pormise是JS的异步编程的一种解决方案,在ES6将其写进了语言标准,提供了原生的Promise对象. Promise简单来理解就是一个容器,里面存放着某个未来才会结束的事 ...

  2. OpenCV实现图象翻转、滤波、锐化

    OpenCV实现图象翻转.滤波.锐化 注:以下代码,使用opencv库函数实现了对图片的翻转.灰度图转换.各种滤波.各种锐化. 库函数相关参数及说明参阅:OpenCV中文站=>opencv教程( ...

  3. Marketing Cloud的contact merge机制

    Marketing Cloud的contact支持多种多样的数据源,如下图所示: SAP Hybris Commerce SAP ERP SAP Cloud for Customer SAP Gigy ...

  4. 主板(motherboard)

    若转载请于明显处标明出处:http://www.cnblogs.com/kelamoyujuzhen/p/8979262.html 整台PC都是围绕主板(motherboard)构建的,它是PC中最重 ...

  5. sk_buff内核api函数记录

    1.alloc_skb() 上层协议要发送数据包的时候或网络设备准备接收数据包的时候调用 2.kfree_skb() 释放sk_buff结构体 3.skb_put() 在数据区的末端添加某协议的尾部 ...

  6. 优秀技术Leader应具备的六项能力

    技术Leader是互联网公司中,战斗在一线的技术领导者,技术Leader们能力的强弱,决定着公司整个技术团队的战斗力,结合我之前管理上百人技术团队的经验,谈谈我心目中优秀技术Leader五个方面的能力 ...

  7. 挖矿病毒watchbog处理过程

    1 挖矿病毒watchbog处理过程 简要说明 这段时间公司的生产服务器中了病毒watchbog,cpu动不动就是100%,查看cpu使用情况,发现很大一部分都是us,而且占100%左右的都是进程wa ...

  8. idou老师教你学Istio :5分钟简析Istio异常检测

    异常检测 异常检测和踢出异常主机是一个动态检查上游主机是否正常工作,对不健康主机进行移除的过程.异常检测是一种被动健康检查,根据返回状态码来判断是否满足移除条件,最后将主机移除,首先我们来了解下驱逐算 ...

  9. Tcp/IP协议详讲

    TCP/IP协议分层详解 目录 TCP/IP 和 ISO/OSI TCP/IP分层模型 数据的封装与分用 其他相关概念 TCP/IP 通信传输流 负责传输的 IP 协议 正文 回到顶部 TCP/IP ...

  10. 18 Candidates for the Top 10 Algorithms in Data Mining

    Classification============== #1. C4.5 Quinlan, J. R. 1993. C4.5: Programs for Machine Learning.Morga ...