在 NumPy 数组中使用 OR 运算符追加多个项目
Using OR operator in NumPy Array to Append multiple items
我正在使用 NumPy 数组在 Esri ArcGIS 中显示特征 class。我有一个要附加到 NumPy 数组的项目元组。一个 field/column 应该能够根据代理输入使用多个值,即如果类别是大件物品,则字段 sccatdesc 应该是 sbi,如果类别是电子垃圾,则 sccatdesc 应该是 mbe。此示例展示了使用 NumPy 数组的基本逻辑。我怎样才能成功地为一个字段使用多个值。
dt = np.dtype([('Address', 'U40'),
('Y_CoordShape', '<f8'),
('X_CoordShape', '<f8'),
('Y_Coord', '<f8'),
('X_Coord', '<f8'),
('ReasonCode','U128'),
('NUMBERCYLA', 'U40'),
('SRNumber', 'U40'),
('FullName', 'U40'),
('RESOLUTION_CODE','U128'),
('HOME_PHONE', 'U40'),
('CreatedDate', 'U128'),
('UpdatedDate', 'U128'),
('ItemDesc', 'U128'),
('Category', 'U128',),
('SCHEDULE_DATE', 'U128'),
('CYLA_District', 'U128'),
('SCCatDesc ', 'U128'),
# ('Collect_Day', 'U128'),
# ('Description', 'U128'),
('Prior_RESOLUTION_CODE', 'U128',),
('CYLA_DISTRICT', 'U128',),
])
items.append((Address,
x,
y,
x,
y,
ReasonCode,
SRNumber,
SRNumber,
FullName,
ResolutionCode,
HomePhone,
CreatedDate,
UpdatedDate,
BulkyItemInfo,
k_bulky_comm or k_manual_pickup_comm,
ServiceDate,
CYLA_DISTRICT,
SCCatDesc,
# ServiceNotes,
Prior_Resolution_Code,
CYLA_DISTRICT,
))
sr = arcpy.SpatialReference(4326)
arr = np.array(items,dtype=dt)
NumPyArray = arcpy.da.NumPyArrayToFeatureClass(arr, fc, ['Y_CoordShape', 'X_CoordShape'], sr)
不是在追加中执行 "OR",而是需要执行 if 语句:
if category == 'bulky item':
items.append((Address,
x,
y,
x,
y,
ReasonCode,
SRNumber,
SRNumber,
FullName,
ResolutionCode,
HomePhone,
CreatedDate,
UpdatedDate,
BulkyItemInfo,
k_bulky_comm,
ServiceDate,
CYLA_DISTRICT,
SCCatDesc,
# ServiceNotes,
Prior_Resolution_Code,
CYLA_DISTRICT,
))
elif category == 'e-waste':
items.append((Address,
x,
y,
x,
y,
ReasonCode,
SRNumber,
SRNumber,
FullName,
ResolutionCode,
HomePhone,
CreatedDate,
UpdatedDate,
BulkyItemInfo,
k_manual_pickup_comm,
ServiceDate,
CYLA_DISTRICT,
SCCatDesc,
# ServiceNotes,
Prior_Resolution_Code,
CYLA_DISTRICT,
))
我正在使用 NumPy 数组在 Esri ArcGIS 中显示特征 class。我有一个要附加到 NumPy 数组的项目元组。一个 field/column 应该能够根据代理输入使用多个值,即如果类别是大件物品,则字段 sccatdesc 应该是 sbi,如果类别是电子垃圾,则 sccatdesc 应该是 mbe。此示例展示了使用 NumPy 数组的基本逻辑。我怎样才能成功地为一个字段使用多个值。
dt = np.dtype([('Address', 'U40'),
('Y_CoordShape', '<f8'),
('X_CoordShape', '<f8'),
('Y_Coord', '<f8'),
('X_Coord', '<f8'),
('ReasonCode','U128'),
('NUMBERCYLA', 'U40'),
('SRNumber', 'U40'),
('FullName', 'U40'),
('RESOLUTION_CODE','U128'),
('HOME_PHONE', 'U40'),
('CreatedDate', 'U128'),
('UpdatedDate', 'U128'),
('ItemDesc', 'U128'),
('Category', 'U128',),
('SCHEDULE_DATE', 'U128'),
('CYLA_District', 'U128'),
('SCCatDesc ', 'U128'),
# ('Collect_Day', 'U128'),
# ('Description', 'U128'),
('Prior_RESOLUTION_CODE', 'U128',),
('CYLA_DISTRICT', 'U128',),
])
items.append((Address,
x,
y,
x,
y,
ReasonCode,
SRNumber,
SRNumber,
FullName,
ResolutionCode,
HomePhone,
CreatedDate,
UpdatedDate,
BulkyItemInfo,
k_bulky_comm or k_manual_pickup_comm,
ServiceDate,
CYLA_DISTRICT,
SCCatDesc,
# ServiceNotes,
Prior_Resolution_Code,
CYLA_DISTRICT,
))
sr = arcpy.SpatialReference(4326)
arr = np.array(items,dtype=dt)
NumPyArray = arcpy.da.NumPyArrayToFeatureClass(arr, fc, ['Y_CoordShape', 'X_CoordShape'], sr)
不是在追加中执行 "OR",而是需要执行 if 语句:
if category == 'bulky item':
items.append((Address,
x,
y,
x,
y,
ReasonCode,
SRNumber,
SRNumber,
FullName,
ResolutionCode,
HomePhone,
CreatedDate,
UpdatedDate,
BulkyItemInfo,
k_bulky_comm,
ServiceDate,
CYLA_DISTRICT,
SCCatDesc,
# ServiceNotes,
Prior_Resolution_Code,
CYLA_DISTRICT,
))
elif category == 'e-waste':
items.append((Address,
x,
y,
x,
y,
ReasonCode,
SRNumber,
SRNumber,
FullName,
ResolutionCode,
HomePhone,
CreatedDate,
UpdatedDate,
BulkyItemInfo,
k_manual_pickup_comm,
ServiceDate,
CYLA_DISTRICT,
SCCatDesc,
# ServiceNotes,
Prior_Resolution_Code,
CYLA_DISTRICT,
))