要素集和记录集 您所在的位置:网站首页 要素要素类要素数据集的区别 要素集和记录集

要素集和记录集

2024-06-01 18:46| 来源: 网络整理| 查看: 265

创建和使用 FeatureSet 和 RecordSet 对象

FeatureSet 和 RecordSet 对象可以直接用于地理处理工具的输入。 可以根据需要和应用情景以多种方式创建对象;可以通过提供给类构造函数的参数或通过下方示例中描述的各种方法来创建。 load 方法可用于将不同的要素集或行加载到对象,而 save 方法可用于保留磁盘上的要素或行。 此外,类构造函数和类 load 方法接受多种数据源,如 FeatureSet 和 RecordSet 主题中所述。

创建空 FeatureSet 对象。

feature_set = arcpy.FeatureSet()

根据输入要素类创建 FeatureSet 对象。

feature_set = arcpy.FeatureSet("c:/base/roads.shp")

使用 SQL 表达式将一组要素加载到 FeatureSet 对象。

feature_set.load("c:/base/roads.shp", "CITY = 'Redlands'")GetParameterValue

要使用工具输入的特定方案创建 FeatureSet 或 RecordSet 对象,请通过 GetParameterValue 函数使用合适的方案创建空 FeatureSet 或 RecordSet 对象。

import arcpy # Add a custom server toolbox arcpy.ImportToolbox("http://flame7/arcgis/services;BufferByVal", "servertools") # Get the default input from a tool in_recordset = arcpy.GetParameterValue("bufferpoints", 0)GetParameter

使用脚本工具时,可以使用 GetParameter 函数从工具中获取 FeatureSet 和 RecordSet 对象。

import arcpy # Get the RecordSet from a script tool in_recordset = arcpy.GetParameter(0)

了解有关 GetParameter 函数的详细信息

结果类 getInput 和 getOutput 方法

使用服务器工具时,可以明确询问其输出。 当输出为 FeatureSet 或 RecordSet 对象时,Result 对象 getOutput 方法可用于在 FeatureSet 或 RecordSet 对象中返回工具输出。 此外,Result 对象的 getInput 方法可用于获取输入 FeatureSet 或 RecordSet 对象。

import time import arcpy # Add a toolbox from a server arcpy.ImportToolbox("http://flame7/arcgis/services;GP/BufferByVal", "servertools") # Use GetParameterValue to get a featureset object with the default # schema of the first parameter of the tool 'bufferpoints' in_featureset = arcpy.GetParameterValue("bufferpoints", 0) # Load a shapefile into the featureset in_featureset.load("c:/base/roads.shp") # Run a server tool named BufferPoints with featureset created above result = arcpy.BufferPoints_servertools(in_featureset, "5 feet") # Check the status of the result object every 0.2 seconds until it # has a value of 4 (succeeded) or greater while result.status < 4: time.sleep(0.2) # Get the output FeatureSet back from the server and save to a # local geodatabase out_featureset = result[0] out_featureset.save("c:/temp/base.gdb/towers_buffer")


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有