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. 简单SQL注入试探、二

    DVWA——简单SQL注入小记 今天我们来记录简单的盲注过程 简单的SQL injection(blind) Level:low 登陆后选择SQL Injection(Blind) 能看到这样的界面 ...

  2. C#的预处理指令

  3. Server SAN

    http://blog.sina.com.cn/s/blog_5946bd590102veni.html http://blog.sina.com.cn/s/blog_5946bd590102vemm ...

  4. 排序算法(冒泡、选择)-python代码展示

    冒泡排序: def bubble_sort(list): for i in range(len(list) - 1): # 这个循环负责设置冒泡排序进行的次数 for j in range(len(l ...

  5. openpose-opencv 的coco数据多人体姿态估计

    介绍 opencv除了支持常用的物体检测模型和分类模型之外,还支持openpose模型,同样是线下训练和线上调用.这里不做特别多的介绍,先把源代码和数据放出来- 实验模型获取地址:https://gi ...

  6. JS 自定义组件

    经常会用到JS插件,但从未研究过插件的写法 目前主流的写法有多种,各有各的优缺点,下面,我就以最常规的一种写法举例 // plugin.js ;(function(undefined) {//防止出现 ...

  7. 图像Image类、打印Printing相关

    一.Images 1.概述 Image 类为Bitmap(位图) 和 Metafile(矢量图) 的类提供功能的抽象基类.Image类不能直接创建对象的,但Image.FromFile()返回的是Bi ...

  8. jq监听页面的滚动事件,

    jQuery监听页面的滚动状态,实现代码: $(document).scroll(function() {       var scroH = $(document).scrollTop(); //滚 ...

  9. JSP运行原理以及执行过程源码分析

    我们在开发JavaWeb的过程中,可能有过这样的疑问,当我们编写jsp页面时,不用引用不用创建就可以使用request.session.application对象,当使用浏览器访问JSP页面时,查看页 ...

  10. python执行ad_hoc

    import shutil from collections import namedtuple from ansible.parsing.dataloader import DataLoader f ...