AnsweredAssumed Answered

Python API field calculator

Question asked by dot_mmekuria on Dec 16, 2019
Latest reply on Dec 21, 2019 by bixb0012

I have been inclined to use the layer calculator since it is much faster than updating features using the API.  The feature update also fails if for example I try to update a large set of features at one time.  The layer calculator does the job much faster but I am having to scale the query as it limits the type of query.

 

here is what I have encountered a problem with.  I want to limit the calculation query by a date field and a time stamp or any way that makes comparing a field and a date possible.  How can I coerce the date data or the field to match a certain format? 

 

  Below is a code snippet

 

val = datetime.today()  # today's date

fld = 'todayis'  # featrue table field containng datetime

valx = datetime.strftime(datetime.today(),'%Y%m%d')

qry0 = "format({},'yyyyMMdd') <> '{}'".format(fld,val)

val2 = datetime.today() + timedelta(days=7)

fld2="nextweekdy'

result = lyr.calculate(where=qry0,calc_expression={"field" : fld2 , "value" : val2})

 

 

Running this code I get an error saying where parameter is invalid.  

RuntimeError:
'where' parameter is invalid
(Error Code: 400)

 

any insights?

Outcomes