Select to view content in your preferred language

Notebook will run in ArcGIS Pro, but fails in ArcGIS Online

111
0
3 weeks ago
DavidHood_USFS
Occasional Contributor

I've developed a python script in a notebook in ArcGIS Pro and it will run correctly without errors, but the same python code in a notebook in ArcGIS Online fails.  Here are the first 3 blocks of my code, its the second block that fails in ArcGIS Online.  The 4th code block is the error message from trying to run it in the ArcGIS Online Notebook.

It appears to be a problem with the query on the fire perimeters (fires_url) but I can't figure out what it doesn't like about my query in the ArcGIS Online Notebook.

from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.features.analysis import overlay_layers
import datetime

# 🔐 Connect to GIS
gis = GIS("home")
print(gis)
# Input Feature Services
fires_url = "https://services3.arcgis.com/T4QMspbfLg3qTGWY/arcgis/rest/services/WFIGS_Interagency_Perimeters_Internal/FeatureServer/0"
ownership_url = "https://services1.arcgis.com/gGHDlz6USftL5Pau/arcgis/rest/services/BaseStaticSnapshotForMobile_LandDesignationsOwnership/FeatureServer/0"

fires_fl = FeatureLayer(fires_url)
ownership_fl = FeatureLayer(ownership_url)

# Filter Fires
FireQuery = "attr_IncidentTypeCategory = 'WF' And attr_FireCause = 'Natural' AND (attr_ContainmentDateTime >= timestamp '2023-10-01 00:00:00.000' Or (attr_ContainmentDateTime IS NULL And attr_EstimatedContainmentDate >= timestamp '2023-10-01 00:00:00.000'))"
selectedFires = fires_fl.query(where=FireQuery, out_fields='*', return_geometry=True)

# Filter USFS Ownership
usfs_query = "OWNERCLASSIFICATION IN ('USDA FOREST SERVICE')"
usfs_ownership = ownership_fl.query(where=usfs_query, out_fields='*', return_geometry=True)

print(f"USFS ownership features: {len(usfs_ownership.features)}")
print(f"Wildfire features: {len(selectedFires.features)}")
#Intersect Fires and Ownership.  Output to Feature Service with _YYYYMMDD at the end of the name
current_date = datetime.datetime.now()
formatted_date = current_date.strftime("%Y%m%d%H%M")

OverlayName = "Fire_DataCall_" + formatted_date
print(OverlayName)

OverlayOutput_url = "https://services1.arcgis.com/gGHDlz6USftL5Pau/arcgis/rest/services/" + OverlayName + "/FeatureServer/0"
#print(OverlayOutput_url)

# Intersect fires with USFS ownership (KEEP ALL ATTRIBUTES)
print("Running overlay (Intersect)...")

results = overlay_layers(
    #input_layer=fires_url,
    input_layer={"url": fires_url, "filter": FireQuery},
    #overlay_layer=ownership_url,
    overlay_layer={"url": ownership_url, "filter": usfs_query},
    overlay_type="intersect",
    output_type="Input",
    # Outputs results as a new hosted feature layer
    output_name=OverlayName,
    context={"overwrite": True}
)

 

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
File /opt/conda/lib/python3.11/site-packages/requests/models.py:974, in Response.json(self, **kwargs)
    973 try:
--> 974     return complexjson.loads(self.text, **kwargs)
    975 except JSONDecodeError as e:
    976     # Catch JSON-related errors and raise as requests.JSONDecodeError
    977     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File /opt/conda/lib/python3.11/site-packages/simplejson/__init__.py:514, in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, use_decimal, allow_nan, **kw)
    510 if (cls is None and encoding is None and object_hook is None and
    511         parse_int is None and parse_float is None and
    512         parse_constant is None and object_pairs_hook is None
    513         and not use_decimal and not allow_nan and not kw):
--> 514     return _default_decoder.decode(s)
    515 if cls is None:

File /opt/conda/lib/python3.11/site-packages/simplejson/decoder.py:386, in JSONDecoder.decode(self, s, _w, _PY3)
    385     s = str(s, self.encoding)
--> 386 obj, end = self.raw_decode(s)
    387 end = _w(s, end).end()

File /opt/conda/lib/python3.11/site-packages/simplejson/decoder.py:416, in JSONDecoder.raw_decode(self, s, idx, _w, _PY3)
    415         idx += 3
--> 416 return self.scan_once(s, idx=_w(s, idx).end())

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
Cell In[3], line 10
      8 # Filter Fires
      9 FireQuery = "attr_IncidentTypeCategory = 'WF' And attr_FireCause = 'Natural' AND (attr_ContainmentDateTime >= timestamp '2023-10-01 00:00:00.000' Or (attr_ContainmentDateTime IS NULL And attr_EstimatedContainmentDate >= timestamp '2023-10-01 00:00:00.000'))"
---> 10 selectedFires = fires_fl.query(where=FireQuery, out_fields='*', return_geometry=True)
     12 # Filter USFS Ownership
     13 usfs_query = "OWNERCLASSIFICATION IN ('USDA FOREST SERVICE')"

File /opt/conda/lib/python3.11/site-packages/arcgis/features/layer.py:2257, in FeatureLayer.query(self, where, out_fields, time_filter, geometry_filter, return_geometry, return_count_only, return_ids_only, return_distinct_values, return_extent_only, group_by_fields_for_statistics, statistic_filter, result_offset, result_record_count, object_ids, distance, units, max_allowable_offset, out_sr, geometry_precision, gdb_version, order_by_fields, out_statistics, return_z, return_m, multipatch_option, quantization_parameters, return_centroid, return_all_records, result_type, historic_moment, sql_format, return_true_curves, return_exceeded_limit_features, as_df, datum_transformation, time_reference_unknown_client, **kwargs)
   2214 # validate parameters
   2215 query_params = _query.QueryParameters(
   2216     where=where,
   2217     out_fields=out_fields,
   (...)
   2250     time_reference_unknown_client=time_reference_unknown_client,
   2251 )
   2252 return _query.Query(
   2253     layer=self,
   2254     parameters=query_params,
   2255     is_layer=True,
   2256     as_df=as_df,
-> 2257 ).execute()

File /opt/conda/lib/python3.11/site-packages/arcgis/_impl/common/_query.py:658, in Query.execute(self)
    655 self._get_url()
    657 # Two workflows: Return as FeatureSet or return as DataFrame
--> 658 return self._query(raw)

File /opt/conda/lib/python3.11/site-packages/arcgis/_impl/common/_query.py:679, in Query._query(self, raw)
    677     return self._process_query_result(result, raw)
    678 except Exception as query_exception:
--> 679     return self._handle_query_exception(query_exception)

File /opt/conda/lib/python3.11/site-packages/arcgis/_impl/common/_query.py:843, in Query._handle_query_exception(self, query_exception)
    840 if any(msg in str(query_exception) for msg in error_messages):
    841     return self._retry_query_with_fewer_records()
--> 843 raise query_exception

File /opt/conda/lib/python3.11/site-packages/arcgis/_impl/common/_query.py:677, in Query._query(self, raw)
    673     # Perform the initial query
    674     result = self.layer._con._session.get(
    675         self.url, params=encoded_parameters
    676     ).json()
--> 677     return self._process_query_result(result, raw)
    678 except Exception as query_exception:
    679     return self._handle_query_exception(query_exception)

File /opt/conda/lib/python3.11/site-packages/arcgis/_impl/common/_query.py:711, in Query._process_query_result(self, result, raw)
    707         features = self._fetch_all_features_single_thread(features, result)
    708     else:
    709         # Otherwise, we use a concurrent workflow with ids to fetch all features
    710         # This workflow also works if pagination is not supported
--> 711         features = self._fetch_all_features_by_chunk()
    713 result["features"] = features
    714 if self.as_df:

File /opt/conda/lib/python3.11/site-packages/arcgis/_impl/common/_query.py:829, in Query._fetch_all_features_by_chunk(self)
    827     # Step 4: Process the results
    828     for future in concurrent.futures.as_completed(futures):
--> 829         result = future.result().json()
    830         features += result.get("features", [])
    831 return features

File /opt/conda/lib/python3.11/site-packages/requests/models.py:978, in Response.json(self, **kwargs)
    974     return complexjson.loads(self.text, **kwargs)
    975 except JSONDecodeError as e:
    976     # Catch JSON-related errors and raise as requests.JSONDecodeError
    977     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 978     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

 

0 Kudos
0 Replies