FeatureClassToNumPyArray
汇总
此 FeatureClassToNumPyArray 函数用于将要素类转换为 NumPy 结构数组。
讨论
NumPy 是用于在 Python 中进行科学计算(包括支持功能强大的多维数组对象)的基础包。 有关详细信息,请参阅 ArcGIS 中的 NumPy 。
要将表转换成 NumPy 数组,请改用 TableToNumPyArray 函数。
语法
FeatureClassToNumPyArray(in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {skip_nulls}, {null_value})
| 参数 | 说明 | 数据类型 |
|---|---|---|
|
in_table |
要素类、图层、表或表视图。 |
String |
|
field_names |
字段名称列表(或组)。 对于单个字段,可以使用一个字符串,而不使用字符串列表。 要访问输入表中的所有字段(BLOB 字段除外),可以使用星号 ( 不支持栅格和 BLOB 字段。 使用 以令牌(如
Export a feature class to a NumPy array. The output array will include a field for the Object ID and a field containing a tuple of the feature's centroid's x,y coordinates.
(默认值为 *) |
String |
|
where_clause |
用于限制所返回的记录的可选表达式。 有关 WHERE 子句和 SQL 语句的详细信息,请参阅 在 ArcGIS 中使用的查询表达式的 SQL 参考 。 (默认值为 "") |
String |
|
spatial_reference |
要素类的空间参考。 指定此参数后,将根据输入的空间参考对要素进行投影(或变换)。 如果未指定,则将使用输入要素类的空间参考。 此参数的有效值为 Use the spatial_reference argument to return coordinates in a different spatial reference. Here, a second feature class is described to access a spatial reference object.
(默认值为 None) |
SpatialReference |
|
explode_to_points |
将要素解构为其单个点或折点。 如果将 (默认值为 False) |
Boolean |
|
skip_nulls |
控制是否跳过使用空值的记录。 可以是布尔值( 设置为 Skip all records that include a null.
使用 Python 函数或 Use a function to capture all records that are skipped because of nulls.
Use a lambda expression to capture all records that are skipped because of nulls.
注:在 NumPy 数组中,空值以浮点型(如 (默认值为 False) |
Variant |
|
null_value |
将输入的空值替换为新值。 在计算 Mask all None's in integer fields with a -9999.
Mask None's in integer fields with different values using a dictionary.
注意:提供掩膜(例如 -9999)允许将包含空值的整型字段导出到 NumPy 数组,但在任何分析中使用这些值时都请务必谨慎。 分析结果可能因引入的值而意外偏斜。 (默认值为 None) |
Integer |
返回值
| 数据类型 | 说明 |
|---|---|
|
NumPyArray |
NumPy 结构化数组。 |
代码示例
将表转化为 numpy 数组,并对 numpy 运算某些基本统计数据。
import arcpy
import numpy
input = "c:/data/usa.gdb/USA/counties"
arr = arcpy.da.FeatureClassToNumPyArray(input, ('STATE_NAME', 'POP1990', 'POP2000'))
# Sum the total population for 1990 and 2000
print(arr["POP1990"].sum())
print(arr["POP2000"].sum())
# Sum the population for the state of Minnesota
print(arr[arr['STATE_NAME'] == "Minnesota"]['POP2000'].sum())
使用 TableToNumPyArray 确定两个字段的相关系数。
import arcpy
import numpy
input = "c:/data/usa.gdb/USA/counties"
field1 = "INCOME"
field2 = "EDUCATION"
arr = arcpy.da.FeatureClassToNumPyArray(input, (field1, field2))
# Print correlation coefficients for comparison of 2 field values
print(numpy.corrcoef((arr[field1], arr[field2])))