NumPyArrayToFeatureClass (arcpy.da)

摘要

将 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

The output point feature class to which the records from the NumPy array will be written.

String
shape_fields
[shape_fields,...]

A list (or tuple) of field names used to create the feature class' geometry. Coordinates are specified in the order of x, y, z, and m. z-coordinate and m-value fields are optional.

Assuming field names of x, y, z, and m in a numpy array, feature classes could be constructed as below.

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)

相关主题

5/10/2014