首页 > 解决方案 > AttributeError:“unicode”对象没有属性“strftime”

问题描述

我有以下代码:

import arcpy, os

from arcpy.sa import *


arcpy.env.overwriteOutput = True

fc = r'E:\dada proj\DRAW OBJECTS\VIPPoints.mdb\Allfeat'
# Point feature class, needs to be in a file geodatabase (for the where clause to work)
output_folder = r'C:\GIS\data\testdata'  # Where the rasters will be saved

date_field = 'date_'  # field holding the dates (date type, not string)
value_fields = ['CO', 'O3', 'NO2']  # field with the values to interpolate

all_dates = list({i[0] for i in arcpy.da.SearchCursor(fc, date_field)})  # List all unique dates



for date in all_dates:
    # Create a feature layer of each unique date
    where = "{0}=date '{1}'".format(arcpy.AddFieldDelimiters(datasource=fc, field=date_field),
                                    date.strftime('%Y-%m-%d'))
    arcpy.MakeFeatureLayer_management(in_features=fc, out_layer='lyr', where_clause=where)

    # For each field interpolate. This is untested since I dont have spatial analyst
    for fieldname in value_fields:
        outIDW = Idw(in_point_features='lyr', z_field=fieldname,
                     cell_size=10)  # , {power}, {search_radius}, {in_barrier_polyline_features})
        outIDW.save(os.path.join(output_folder, '{0}_{1}.tif'.format(fieldname, date.strftime('%Y%m%d'))))

当我运行它时,我得到了错误

AttributeError: 'unicode' object has no attribute 'strftime'

我的日期在表格和格式中:yyyy/mm/dd 感谢任何解决错误的建议

标签: pythondatearcpystrftime

解决方案


推荐阅读