定向影像自定义输入类型
定向影像自定义输入类型可根据要添加到定向影像数据集的输入影像数据配置到 Python。 自定义输入类型允许用户将影像整合到定向影像数据集,同时保持一致性并遵守预定义的元数据标准。
创建 Python 模块时,请使用以下指南。 该模块提供了在定向影像模式中定义元数据、检索值和提取数据的功能。
模块和类的命名约定
以输入类型命名包含模块和类的文件夹,以便将影像添加到定向影像数据集。 命名约定确保了模块和类的可识别性和使用的直观性。
例如,如果输入类型是 MyInputType ,则按如下方式命名文件夹、模块和类:
文件夹名称 -
MyInputType模块名称 -
MyInputType.py类名称 -
MyInputType
类方法
该类包括用于定义输入数据模式、辅助参数、定向影像数据集字段和定向影像数据集属性以及生成定向影像记录的方法。 该类必须包括 input_data_schema 、 auxiliary_parameters 、 oriented_imagery_fields 、 oriented_imagery_properties 和 oriented_imagery_records 方法。
input_data_schema
input_data_schema 方法定义了生成定向影像记录所需的输入数据,并返回下述值。
返回
input_data_schema 方法返回了一个包含输入数据模式的字典。
每个键都代表了向定向影像数据集中添加影像所需的输入,必须在键值中说明是必要输入还是可选输入。
这就是 input_data_schema 方法的一个示例。
def input_data_schema(self):
"""Defines input data."""
return {
"Metadata File": {"required": True},
"Image Location": {"required": True},
"DEM": {"required": False}
}
auxiliary_parameters
auxiliary_parameters 方法使用默认值定义辅助参数。
返回
auxiliary_parameters 方法返回了一个包含辅助参数信息的字典。
辅助参数必须指定为键,键的对应默认值必须指定为字符串。 如果不需要辅助参数,则必须返回空字典。
这就是 auxiliary_parameters 方法的一个示例。
def auxiliary_parameters(self):
"""Defines auxiliary parameters."""
return {
"Default Ground Elevation": "0",
"Offset": "1.2"
}
在 地理处理 窗格中, 根据自定义输入类型添加图像 工具的 输入数据 和 辅助参数 参数会根据 input_data_schema 和 auxiliary_parameters 方法的返回值进行更新。
oriented_imagery_fields
oriented_imagery_fields 方法定义了必须添加到定向影像数据集的字段。
参数
参数如下:
input_data- 包含输入数据信息的字典。input_data的键与input_data_schema方法返回的键相对应,而值则是用户以字符串形式提供的输入数据。这是
input_data值的一个示例。{ "Metadata File": "C:/Documents/Files/metadata.json", "Image Location": "C:/Documents/Images", "DEM": None }aux_input- 辅助参数和数值字典。aux_input的键与auxiliary_parameters方法返回的键相对应,而值是字符串形式的参数值。这是
aux_input值的一个示例。{ "Default Ground Elevation": "309", "Offset": "1.2" }
返回
oriented_imagery_fields 方法会返回一个包含以下列表的元组:
字符串列表 - 属于 定向影像属性表 方案一部分的字段。
ImagePath和SHAPE@字段为必填字段,必须出现在列表中。字典列表 - 附加自定义字段必须以字典列表的形式提供,并以
field_name和field_type作为键。 定义附加字段名时,请查看 字段名称规则和限制 以及支持的 ArcGIS 字段数据类型 。
这就是 oriented_imagery_fields 方法的一个示例。
def oriented_imagery_fields(self, input_data, aux_params):
"""Define the input schema for the tool."""
standard_fields = [
"SHAPE@",
"Name",
"ImagePath",
"AcquisitionDate",
"CameraHeading",
"CameraPitch",
"CameraRoll",
"HorizontalFieldOfView",
"VerticalFieldOfView",
"CameraHeight",
"FarDistance",
"NearDistance",
"OrientedImageryType",
"CameraOrientation"
]
additional_fields = [
{"field_name":"CameraId", "field_type":"LONG"},
{"field_name":"CameraType", "field_type":"TEXT"}
]
return standard_fields, additional_fields
oriented_imagery_properties
oriented_imagery_properties 方法定义了定向影像数据集属性的默认值。 这些值可使用 更新定向影像数据集属性 工具进行更改。
参数
参数如下:
input_data- 包含输入数据信息的字典。input_data的键与input_data_schema方法返回的键相对应,而值则是用户以字符串形式提供的输入数据。aux_input- 辅助参数和数值字典。aux_input的键与auxiliary_parameters方法返回的键相对应,而值是字符串形式的参数值。
返回
oriented_imagery_properties 方法返回了一个包含定向影像数据集属性名称和值的字典。
ArcPy Describe 函数以字典形式检索所有定向影像属性及其相应值。 oriented_imagery_properties 方法可以返回除 horizontalMeasurementUnit 以外的任何属性。 水平测量值由数据集坐标系定义。
这就是 oriented_imagery_properties 方法的一个示例。
def oriented_imagery_properties(self, input_data, aux_params):
"""Define the default properties for the tool."""
return {
"maximumDistance": 2000,
"orientedImageryType": "Oblique",
"cameraPitch": 45,
"farDistance": 500,
"nearDistance": 120
}
oriented_imagery_records
oriented_imagery_records 方法通过读取元数据来获取信息,并生成包含已填写值的已定义模式的字典。
参数
参数如下:
input_data- 包含输入数据信息的字典。input_data的键与input_data_schema方法返回的键相对应,而值则是用户以字符串形式提供的输入数据。aux_input- 辅助参数和数值字典。aux_input的键与auxiliary_parameters方法返回的键相对应,而值是字符串形式的参数值。
生成
oriented_imagery_records 方法生成了一个字典,其中包含定向影像数据集表的字段值。
词典必须包含 oriented_imagery_fields 方法中定义为键的所有字段。 SHAPE@ 键必须以 ArcPy PointGeometry 对象的形式包含摄像机位置。
这就是 oriented_imagery_properties 方法的一个示例。
def oriented_imagery_properties(self, input_data, aux_input):
"""Generate the oriented imagery records."""
metadata = input_data["Metadata File"]
image_folder = input_data["Image Location"]
dem = input_data["DEM"]
def_ground = aux_input["Default Ground Elevation"]
offset = aux_input["Offset"]
# Implementation goes here
yield {
"SHAPE@": camera_point_geom,
"Name": image_name,
"ImagePath": image_path,
"AcquisitionDate": acquisition_date,
"CameraHeading": heading,
"CameraPitch": pitch,
"CameraRoll": roll,
"HorizontalFieldOfView": hfov,
"VerticalFieldOfView": vfov,
"CameraHeight": camera_height,
"FarDistance": far_distance,
"NearDistance": near_distance,
"OrientedImageryType": oi_type,
"CameraOrientation": cam_ori,
"CameraId": int(c_id),
"CameraType": c_type
}