ArcGIS字段数据类型详解:选择与映射

7 下载量 111 浏览量 更新于2024-09-05 收藏 534KB PDF 举报
"ArcGIS 字段数据类型—帮助 _ ArcGIS Desktop.pdf" 在ArcGIS中,字段数据类型是创建要素类和表时需要考虑的关键因素,因为它们决定了如何正确存储和管理数据。数据类型的选择直接影响到数据的分析、管理和业务应用。ArcGIS提供了多种数据类型,包括数字类型、文本类型、日期类型、二进制大对象(BLOB)和全局唯一标识符(GUID)。 1. 数值类型: - 短整型:用于存储整数,范围在-32,768到32,767之间,占用2个字节。 - 长整型:用于存储更大的整数,范围在-2,147,483,648到2,147,483,647之间,占用4个字节。 - 浮点型(单精度浮点数):用于存储包含小数的数值,精度较低,占用4个字节。 - 双精度型(双精度浮点数):用于更精确的数值计算,包含更多小数位,占用8个字节。 选择数值类型时,需要根据数据特性来决定,例如是否需要存储小数以及存储空间的限制。通常,选择占用空间最小的数据类型可以提高性能并节省存储空间。 2. 文本类型: - 文本字段:用于存储文本数据,长度有限制,不同数据存储格式有不同的最大长度,如dbf表的文本字段通常限制在255个字符。 3. 日期类型: - 日期字段:用于存储日期和时间信息,支持完整的日期和时间范围,可用于时间序列分析和事件记录。 4. 二进制大对象(BLOB): - BLOB字段:用于存储非结构化的二进制大数据,如图像、音频文件或其他大型媒体内容。 5. 全局唯一标识符(GUID): - GUID字段:用于存储唯一标识符,确保每个记录在全球范围内都是独一无二的,常用于关联和跟踪数据。 当数据存储在ArcSDE地理数据库、个人地理数据库或数据库中时,ArcGIS的数据类型可能不直接对应于DBMS的数据类型,而是通过数据类型映射进行匹配。这意味着在DBMS中实际存储的数据类型可能与ArcGIS中显示的类型不同。要深入了解这种映射过程,可以查阅DBMS中的数据类型相关文档。 另外,不同的数据存储格式(如shapefile或dbf表)对数据类型和大小有特定限制。在移动数据时,必须了解目标存储格式的要求,以避免数据丢失或格式错误。 理解并正确选择ArcGIS中的字段数据类型是确保数据准确性和有效性的基础,同时也影响到数据的处理效率和兼容性。在创建和管理GIS数据时,应根据实际需求仔细选择合适的数据类型,并充分考虑各种因素,包括数据范围、精度需求和存储限制。

import arcpy # 设置工具箱参数 input_features = arcpy.GetParameterAsText(0) # 输入要素图层 join_features = arcpy.GetParameterAsText(1) # 连接要素图层 output_features = arcpy.GetParameterAsText(2) # 输出要素图层 join_fields = arcpy.GetParameterAsText(3).split(';') # 连接要素图层中需要赋值的字段,用“;”隔开 area_threshold = arcpy.GetParameterAsText(4) # 面积阈值,只有面积大于该值的要素才会被连接 # 创建空间连接对象 spatial_join = arcpy.SpatialJoin_analysis(target_features=input_features, join_features=join_features, out_feature_class=output_features, join_operation="JOIN_ONE_TO_MANY", join_type="KEEP_ALL", match_option="INTERSECT") # 根据面积阈值进行筛选 if len(area_threshold) > 0: arcpy.SelectLayerByAttribute_management(in_layer_or_view=spatial_join, where_clause="Shape_Area >= {}".format(area_threshold)) # 设置字段映射 field_mapping = arcpy.FieldMappings() for field in join_fields: field_map = arcpy.FieldMap() field_map.addInputField(spatial_join, field) output_field = field_map.outputField output_field.name = "{}_{}".format(join_features, field) field_map.outputField = output_field field_mapping.addFieldMap(field_map) # 对要素进行赋值 arcpy.FeatureClassToFeatureClass_conversion(spatial_join, output_features, "", field_mapping)运行错误:Traceback (most recent call last): File "D:\实验2\空间连接.py", line 15, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6688, in SelectLayerByAttribute raise e ExecuteError: 执行失败。参数无效。 The value cannot be a feature class ERROR 000840: 该值不是 栅格图层。 ERROR 000840: 该值不是 镶嵌图层。 执行(SelectLayerByAttribute)失败。 执行(空间连接多对一)失败。请改正代码

2023-05-25 上传

运行import arcpy # 定义输入图层和输出图层 input_layer = arcpy.GetParameterAsText(0) output_layer = arcpy.GetParameterAsText(1) # 定义合并条件 merge_field = arcpy.GetParameterAsText(2) # 要合并的字段名 merge_gap = arcpy.GetParameterAsText(3) # 相邻图斑面积差距 # 定义面积筛选条件 selection_field = arcpy.GetParameterAsText(4) # 用于筛选的字段名 selection_value = arcpy.GetParameterAsText(5) # 筛选条件 selection_area = float(arcpy.GetParameterAsText(6)) # 面积筛选阈值 # 进行面积筛选 arcpy.MakeFeatureLayer_management(input_layer, "layer", "{}='{}' AND SHAPE_AREA > {}".format(selection_field, selection_value, selection_area)) # 寻找相邻图斑 arcpy.PolygonNeighbors_analysis("layer", "neighbors", ["FID"]) # 定义合并列表 merge_list = [] # 进行合并 with arcpy.da.SearchCursor("neighbors", ['src_FID', 'nbr_FID', 'src_{}'.format(merge_field)]) as cursor: for row in cursor: if row[0] < row[1]: src_geom = arcpy.da.SearchCursor("layer", ["SHAPE@"], "FID={}".format(row[0])).next()[0] nbr_geom = arcpy.da.SearchCursor("layer", ["SHAPE@"], "FID={}".format(row[1])).next()[0] if src_geom.area < nbr_geom.area: src_geom, nbr_geom = nbr_geom, src_geom if src_geom.area - nbr_geom.area > merge_gap: merge_list.append(row[0]) merge_list.append(row[1]) arcpy.management.Dissolve("layer", output_layer, "{}".format(merge_field), None, "MULTI_PART", "DISSOLVE_LINES") # 删除被合并的图斑 with arcpy.da.UpdateCursor(output_layer, ['FID']) as cursor: for row in cursor: if row[0] in merge_list: cursor.deleteRow()时报错Traceback (most recent call last): File "D:\实验YY\新建文件夹 (2)\批量合并小图斑.py", line 13, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\analysis.py", line 984, in PolygonNeighbors raise e ExecuteError: 执行失败。参数无效。 ERROR 000732: 输入要素: 数据集 layer 不存在或不受支持 执行(PolygonNeighbors)失败。 执行(批量合并小图斑)失败。请改正代码

2023-05-22 上传

import arcpy # 输入参数 input_features = arcpy.GetParameterAsText(0) # 连接要素 join_field = arcpy.GetParameterAsText(1) # 连接字段 target_feature = arcpy.GetParameterAsText(2) # 目标要素 target_field = arcpy.GetParameterAsText(3) # 目标字段 area_threshold = arcpy.GetParameterAsText(4) # 面积阈值 # 创建空间连接 arcpy.SpatialJoin_analysis(input_features, target_feature, "in_memory/spatial_join", "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT") # 选择面积大于阈值的连接要素 arcpy.Select_analysis("in_memory/spatial_join", "in_memory/selected_features", "Shape_Area > " + area_threshold) # 统计相同连接字段值的面积总和 arcpy.Statistics_analysis("in_memory/selected_features", "in_memory/summarized_features", "Shape_Area SUM", join_field) # 创建字典,存储连接字段值和对应的面积总和 sum_dict = {} with arcpy.da.SearchCursor("in_memory/summarized_features", [join_field, "SUM_Shape_Area"]) as cursor: for row in cursor: sum_dict[row[0]] = row[1] # 更新目标要素中的字段值 with arcpy.da.UpdateCursor(target_feature, [target_field, join_field]) as cursor: for row in cursor: join_value = row[1] if join_value in sum_dict: area_sum = sum_dict[join_value] row[0] = str(area_sum) cursor.updateRow(row) # 导出结果 arcpy.CopyFeatures_management(target_feature, arcpy.GetParameterAsText(5))运行出现错误Traceback (most recent call last): File "D:\实验2\空间连接.py", line 13, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\analysis.py", line 84, in Select raise e ExecuteError: ERROR 000358: 无效的表达式 Shape_Area > 600 执行(Select)失败。 执行(fzzz)失败。,请改正代码

2023-05-24 上传

import arcpy # 输入参数 input_features = arcpy.GetParameterAsText(0) join_field = arcpy.GetParameterAsText(1) target_feature = arcpy.GetParameterAsText(2) target_field = arcpy.GetParameterAsText(3) area_threshold = arcpy.GetParameterAsText(4) # 创建空间连接 arcpy.SpatialJoin_analysis(input_features, target_feature, "in_memory/spatial_join", "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT") # 选择面积大于阈值的连接要素 arcpy.Select_analysis("in_memory/spatial_join", "in_memory/selected_features", '"Shape_Area" > ' + str(area_threshold)) # 统计相同连接字段值的面积总和 arcpy.Statistics_analysis("in_memory/selected_features", "in_memory/summarized_features", "Shape_Area SUM", join_field) # 创建字典,存储连接字段值和对应的面积总和 sum_dict = {} with arcpy.da.SearchCursor("in_memory/summarized_features", [join_field, "SUM_Shape_Area"]) as cursor: for row in cursor: sum_dict[row[0]] = row # 更新目标要素中的字段值 with arcpy.da.UpdateCursor(target_feature, [target_field, join_field]) as cursor: for row in cursor: join_value = row[1] if join_value in sum_dict: area_sum = sum_dict[join_value] row[0] = str(area_sum[1]) cursor.updateRow(row) # 导出结果 arcpy.CopyFeatures_management(target_feature, arcpy.GetParameterAsText(5))运行错误Traceback (most recent call last): File "D:\实验2\空间连接.py", line 14, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\analysis.py", line 84, in Select raise e ExecuteError: ERROR 000358: 无效的表达式 "Shape_Area" > 600 执行(Select)失败。 执行(fzzz)失败。请改正代码

2023-05-24 上传

import arcpy # 输入参数 input_features = arcpy.GetParameterAsText(0) join_field = arcpy.GetParameterAsText(1) target_feature = arcpy.GetParameterAsText(2) target_field = arcpy.GetParameterAsText(3) area_threshold = arcpy.GetParameterAsText(4) # 创建空间连接 arcpy.SpatialJoin_analysis(input_features, target_feature, "in_memory/spatial_join", "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT") # 选择面积大于阈值的连接要素 arcpy.Select_analysis("in_memory/spatial_join", "in_memory/selected_features", "\"Shape_Area\" > " + str(area_threshold)) # 统计相同连接字段值的面积总和 arcpy.Statistics_analysis("in_memory/selected_features", "in_memory/summarized_features", "Shape_Area SUM", join_field) # 创建字典,存储连接字段值和对应的面积总和 sum_dict = {} with arcpy.da.SearchCursor("in_memory/summarized_features", [join_field, "SUM_Shape_Area"]) as cursor: for row in cursor: sum_dict[row[0]] = row # 更新目标要素中的字段值 with arcpy.da.UpdateCursor(target_feature, [target_field, join_field]) as cursor: for row in cursor: join_value = row[1] if join_value in sum_dict: area_sum = sum_dict[join_value] row[0] = str(area_sum[1]) cursor.updateRow(row) # 导出结果 arcpy.CopyFeatures_management(target_feature, arcpy.GetParameterAsText(5))脚本运行错误:Traceback (most recent call last): File "D:\实验2\空间连接.py", line 14, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\analysis.py", line 84, in Select raise e ExecuteError: ERROR 000358: 无效的表达式 "Shape_Area" > 600 SquareMeters 执行(Select)失败。 执行(fzzz)失败。请改正代码

2023-05-24 上传