Select to view content in your preferred language

arcgis append hosted feature layer. "Job Failed" error

554
0
11-13-2021 05:48 AM
Labels (1)
AmmirKhan
New Contributor

I am trying to get this zip file I generated to update data -> append data to layer. If I manually download the zip file I generated and manually go in and append data to layer it works exactly how I want it. The problem is my python code, which I admit I am new to.

I want to make sure I am appending data to my layer aka doing what I did manually on python. I tried to code based on a tutorial I watched and I am getting an error which I cannot figure out. I am not sure if what I have would completely replace the layer or just add new data (which is what I am trying to accomplish)

Attached is my code with a photo of the error I get:

from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
import requests
import urllib.request
from zipfile import ZipFile
import xarray as xr
import matplotlib
import matplotlib.pyplot as plt
import metpy.calc as mpcalc
from metpy.units import units
from shapely import geometry
import numpy as np
import fiona

#Load data
#urllib.request.urlretrieve('rap.t00z.awp130pgrbf00.grib2', 'a.grib2')

# Open data file & read data
ds = xr.open_dataset('rap.t23z.awp252pgrbf00.grib2', engine='cfgrib')
lon, lat = ds.longitude.values-360., ds.latitude.values
t2m = mpcalc.smooth_gaussian((ds.variables['t2m'].values*units('K')).to('degF').magnitude, 4)

# Plot
fig = plt.figure(figsize=(12,10))
ax = fig.add_subplot(111)
cs = ax.contourf(lon, lat, t2m, levels=[10,20,30,32,36]) ## EDIT CONTOUR LEVELS HERE
#plt.close()
#plt.show()

# Write contours to shapefile
lvl_lookup = dict(zip(cs.collections, cs.levels))
PolyList=[]
for col in cs.collections:
z = lvl_lookup[col] # the value of this level
for contour_path in col.get_paths():
# create the polygon for this level
for ncp,cp in enumerate(contour_path.to_polygons()):
lons = cp[:,0]
lats = cp[:,1]
new_shape = geometry.Polygon([(i[0], i[1]) for i in zip(lons,lats)])
if ncp == 0:
poly = new_shape # first shape
else:
poly = poly.difference(new_shape) # Remove the holes

PolyList.append({'poly':poly,'props':{'z': z}})
schema = {'geometry': 'Polygon','properties': {'z': 'float'}}
crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': 'longlat'}
with fiona.collection('rap_temp.shp', 'w', driver='ESRI Shapefile', crs=crs, schema=schema) as output:
for p in PolyList:
output.write({'properties': p['props'],
'geometry': geometry.mapping(p['poly'])})

# create a ZipFile object
rap_temp = ZipFile('rap_temp2.zip', 'w')
# Add multiple files to the zip
rap_temp.write('rap_temp.cpg')
rap_temp.write('rap_temp.dbf')
rap_temp.write('rap_temp.prj')
rap_temp.write('rap_temp.shp')
rap_temp.write('rap_temp.shx')
#Close the zip file
rap_temp.close()

# ARC GIS

#Login
user = '****'
password = '****'
gis = GIS('https://rvhlcps.maps.arcgis.com', user, password)
un = gis.properties.user.username
print('Logged in as: {}'.format(un))

#overwrite layer with new data
itemid = '41b06ab534504b388c17b89c04bc0eef'
dataitem = gis.content.get(itemid)
print('1')
flayercol = FeatureLayerCollection.fromitem(dataitem)
print('2')
flayercol.manager.overwrite('rap_temp2.zip')
print('Layer Updated')
Here is the error:


---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-2-2dc8c4b4cf39> in <module>
14 flayercol = FeatureLayerCollection.fromitem(dataitem)
15 print('2')
---> 16 flayercol.manager.overwrite('rap_temp2.zip')
17 print('Layer Updated')

/opt/tljh/user/lib/python3.7/site-packages/arcgis/features/managers.py in overwrite(self, data_file)
2269 if related_data_item.update(item_properties=params, data=data_file):
2270 published_item = related_data_item.publish(
-> 2271 publish_parameters, overwrite=True
2272 )
2273 if published_item is not None:

/opt/tljh/user/lib/python3.7/site-packages/arcgis/gis/__init__.py in publish(self, publish_parameters, address_fields, output_type, overwrite, file_type, build_initial_cache, item_id, geocode_service)
12741 return Item(self._gis, ret[0]["serviceItemId"])
12742 else:
> 12743 serviceitem_id = self._check_publish_status(ret, folder)
12744 return Item(self._gis, serviceitem_id)
12745

/opt/tljh/user/lib/python3.7/site-packages/arcgis/gis/__init__.py in _check_publish_status(self, ret, folder)
13091 # print(str(job_response))
13092 if job_response.get("status") in ("esriJobFailed", "failed"):
> 13093 raise Exception("Job failed.")
13094 elif job_response.get("status") == "esriJobCancelled":
13095 raise Exception("Job cancelled.")

Exception: Job failed.

0 Kudos
0 Replies