I am going over this ESRI training: https://learn.arcgis.com/en/projects/update-real-time-data-with-python/ , I get stuck on step 17 in the "Create stand-alone script" section. There is a similar post available online (https://community.esri.com/t5/python-questions/the-workspace-work-gdb-does-not-exist-failed-to/m-p/1080002 ), but I couldn't figure out an answer since I am fairly new to python scripting.
Any help would be appreciated, thank you.
Here is my code:
import sys, arcpy, os, tempfile, json
from urllib import request
def feedRoutine (url, workGDB):
# workGDB and default workspace
print("Creating workGDB...")
arcpy.env.workspace = workGDB
arcpy.management.CreateFileGDB(os.path.dirname(workGDB) , os.path.basename(workGDB))
# Download and split json file
print("Downloading data...")
temp_dir = tempfile.mkdtemp()
filename = os.path.join(temp_dir, 'latest_data.json')
response = request.urlretrieve(url, filename)
with open(filename) as json_file:
data_raw = json.load(json_file)
data_stations = dict(type=data_raw['type'], features=[])
data_areas = dict(type=data_raw['type'], features=[])
for feat in data_raw['features']:
if feat['geometry']['type'] == 'Point':
data_stations['features'].append(feat)
else:
data_areas['features'].append(feat)
# Filenames of temp json files
stations_json_path = os.path.join(temp_dir, 'points.json')
areas_json_path = os.path.join(temp_dir, 'polygons.json')
# Save dictionaries into json files
with open(stations_json_path, 'w') as point_json_file:
json.dump(data_stations, point_json_file, indent=4)
with open(areas_json_path, 'w') as poly_json_file:
json.dump(data_areas, poly_json_file, indent=4)
# Convert json files to features
print("Creating feature classes...")
arcpy.conversion.JSONToFeatures(stations_json_path, 'alert_stations')
arcpy.conversion.JSONToFeatures(areas_json_path, 'alert_areas')
# Add 'alert_level ' field
arcpy.management.AddField('alert_stations', 'alert_level', 'SHORT', field_alias='Alert Level')
arcpy.management.AddField('alert_areas', 'alert_level', 'SHORT', field_alias='Alert Level')
# Calculate 'alert_level ' field
arcpy.management.CalculateField('alert_stations', 'alert_level', "int(!alert!)")
arcpy.management.CalculateField('alert_areas', 'alert_level', "int(!alert!)")
# Deployment Logic
print("Deploying...")
deployLogic()
# Return
print("Done!")
return True
def deployLogic():
pass
if __name__ == "__main__":
[url, workGDB] = sys.argv[1:]
feedRoutine (url, workGDB) This is the error code:
(arcgispro-py3-user) C:\training>python coral_reef_exercise.py https://coralreefwatch.noaa.gov/product/vs/vs_polygons.json C:\Temp\Work.gdb
Creating workGDB...
Downloading data...
Creating feature classes...
Traceback (most recent call last):
File "coral_reef_exercise.py", line 56, in <module>
feedRoutine (url, workGDB)
File "coral_reef_exercise.py", line 34, in feedRoutine
arcpy.conversion.JSONToFeatures(stations_json_path, 'alert_stations')
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 576, in JSONToFeatures
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 573, in JSONToFeatures
retval = convertArcObjectToPythonObject(gp.JSONToFeatures_conversion(*gp_fixargs((in_json_file, out_features, geometry_type), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
CreateFeatureClassName: The workspace does not exist.
Failed to execute (JSONToFeatures).