Hi there
I am following the examples in this workbook workforce-scripts/3 - Assigning Work.ipynb at master · Esri/workforce-scripts · GitHub
Because i want to assign work to our workforce based on the predetermined zones from an existing feature layer on the map.
I have completed my code section like so:
for assignment in assignments: contains = squadZones_df["SHAPE"].geom.contains(Geometry(assignment.geometry)) containers = squadZones_df[contains] if not containers.empty: squadZone = containers['OBJECTID'].iloc[0] if squadZone == 2: assignment.worker = squad_WSFF assignment.status = "assigned" assignment.assigned_date = datetime.utcnow() elif squadZone == 5: assignment.worker = squad_LL assignment.status = "assigned" assignment.assigned_date = datetime.utcnow() elif squadZone == 8: assignment.worker = squad_WG assignment.status = "assigned" assignment.assigned_date = datetime.utcnow() elif squadZone == 11: assignment.worker = squad_RR assignment.status = "assigned" assignment.assigned_date = datetime.utcnow() elif squadZone == 16: assignment.worker = squad_HLG assignment.status = "assigned" assignment.assigned_date = datetime.utcnow() elif squadZone == 18: assignment.worker = squad_JE assignment.status = "assigned" assignment.assigned_date = datetime.utcnow() assignments = project.assignments.batch_update(assignments)
However, I keep getting this error:
Traceback (most recent call last):
File "C:/Users/.../PycharmProjects/APITesting/assign_work.py", line 45, in <module>
containers = squadZones_df[contains]
File "C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\frame.py", line 2970, in __getitem__
if com.is_bool_indexer(key):
File "C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\common.py", line 130, in is_bool_indexer
raise ValueError(na_msg)
ValueError: cannot index with vector containing NA / NaN values
Can anyone help with this at all? My feature layer table looks like this:
Thanks!
UPDATE
It looks like this part here:
for assignment in assignments: contains = squadZones_df["SHAPE"].geom.contains(Geometry(assignment.geometry)) print(contains)
Is actually returning "None" in the field values, I added the print check to confirm my suspicions.
0 None
1 None
2 None
3 None
4 None
5 None
However, the assignments are being found ok and the df is being created fine as well with all data contained within.
Does this help anyone with my query?
Thanks
Do you have a geometry engine in your python environment (e.g. arcpy or shapely)? If you don't the API will return None rather than True/False. You can install it via
conda install -c conda-forge shapely