NumPyArrayToFeatureClass

摘要

将 NumPy 结构化数组转换为点要素类。

说明

如果输入数组中的字段名称相对于输出格式无效,则将对其进行验证。 输入字段名称中的所有无效字符都将在输出字段名称中替换为下划线 (_)。 字段名称的限制取决于所使用的特定数据库。

即使将 overwriteOutput 环境设置为 True,NumPyArrayToFeatureClass 也不会覆盖现有要素类。

NumPy 是 Python 中用于进行科学计算的基础包,其包括支持功能强大的 N 维数组对象。有关详细信息,请参阅在 ArcGIS 中使用 NumPy

语法

NumPyArrayToFeatureClass (in_array, out_table, shape_fields, {spatial_reference})
参数说明数据类型
in_array

NumPy 结构化数组。

数组必须包含字段名称和 NumPy dtype。

NumPyArray
out_table

将写入 NumPy 数组中记录的输出点要素类。

String
shape_fields
[shape_fields,...]

用于创建要素类几何的字段名称列表(或组)。坐标以 x、y、z 和 m 的顺序指定。z 坐标与 m 值字段为可选字段。

假设 x、y、z 和 m 的字段名称位于 numpy 数组中,则要素类可如下构建。

import arcpy
# Create a feature class with x,y fields
arcpy.da.NumPyArrayToFeatureClass(array, fc, ("x", "y"))
# Create a feature class with x,y,z fields
arcpy.da.NumPyArrayToFeatureClass(array, fc, ("x", "y", "z"))
# Create a feature class with x,y,m fields
arcpy.da.NumPyArrayToFeatureClass(array, fc, ("x", "y", "", "m"))
# Create a feature class with x,y,z,m fields
arcpy.da.NumPyArrayToFeatureClass(array, fc, ("x", "y", "z", "m"))
String
spatial_reference

要素类的空间参考。 指定此参数后,将根据输入的空间参考对要素进行投影(或变换)。 如果未指定,则将使用输入要素类的空间参考。 此参数的有效值为 SpatialReference 对象或等效字符串。

(默认值为 None)

SpatialReference

代码示例

import arcpy
import numpy
outFC = "C:/data/texas.gdb/fd/pointlocations"
# Create a numpy array with an id field, and a field with a tuple 
#  of x,y coordinates
#
array = numpy.array([(1, (471316.3835861763, 5000448.782036674)),
                     (2, (470402.49348005146, 5000049.216449278))],
                    numpy.dtype([('idfield',numpy.int32),('XY', '<f8', 2)]))
# Define a spatial reference for the output feature class
#
SR = arcpy.Describe("C:/data/texas.gdb/fd").spatialReference
# Export the numpy array to a feature class using the XY field to
#  represent the output point feature
#
arcpy.da.NumPyArrayToFeatureClass(array, outFC, ['XY'], SR)

相关主题