在NumPy数组中使用OR运算符来追加多个项目

时间:2015-06-17 19:54:09

标签: python-2.7 numpy arcgis arcpy

我在Esri ArcGIS中使用NumPy数组来表示要素类。我有一个项目元组,我附加到NumPy数组。一个字段/列应该能够使用代理输入上的多个值,即如果类别是一个庞大的项目,那么字段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)

1 个答案:

答案 0 :(得分:1)

而不是做&#34; OR&#34;在追加内部,你需要做一个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,
            ))