Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.89k stars 1.1k forks source link

Exception when enriching BufferStudyArea #1289

Closed IliaMarek closed 2 years ago

IliaMarek commented 2 years ago

Describe the bug I get an exception when trying to enrich a BufferStudyArea. Enriching by address works OK. The bug appeared after updating arcgis library from 1.9.1 to 2.0.1 To Reproduce Steps to reproduce the behavior:

buffered = BufferStudyArea(area='380 New York St Redlands CA 92373',
                           radii=[3], units='Miles', overlap=False)
drive_dist_df = enrich(study_areas=[buffered], analysis_variables=['KeyGlobalFacts.TOTPOP'])

error:

ValueError                                Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/features/geo/_accessor.py in name(self)
   1472                     idx = cols.index("shape")
-> 1473                     self.set_geometry(self._data.columns[idx])
   1474             except:

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/features/geo/_accessor.py in set_geometry(self, col, sr, inplace)
   1426                 warnings.simplefilter("ignore")
-> 1427                 self._data[col] = GeoArray(self._data[col])
   1428         elif (

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/features/geo/_array.py in __init__(self, values)
    253         self.data = data
--> 254         self._validate_data()
    255 

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/features/geo/_array.py in _validate_data(self)
    261             if isinstance(data[vindx], Geometry) == False:
--> 262                 self.data[:] = [Geometry(d) if d else None for d in data]
    263 

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/features/geo/_array.py in <listcomp>(.0)
    261             if isinstance(data[vindx], Geometry) == False:
--> 262                 self.data[:] = [Geometry(d) if d else None for d in data]
    263 

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/geometry/_types.py in __call__(cls, iterable, **kwargs)
    286                 cls = Geometry
--> 287         return type.__call__(cls, iterable, **kwargs)
    288 

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/geometry/_types.py in __init__(self, iterable, **kwargs)
    315             iterable = ()
--> 316         super(Geometry, self).__init__(iterable, **kwargs)
    317 

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/geometry/_types.py in __init__(self, iterable)
    162             iterable = {}
--> 163         self.update(iterable)
    164 

ValueError: dictionary update sequence element #0 has length 33; 2 is required

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
/var/folders/_d/k5k5ky497sb9t2f6d2bglsj40000gn/T/ipykernel_2560/166913043.py in <module>
      1 buffered = BufferStudyArea(area='380 New York St Redlands CA 92373',
      2                            radii=[3], units='Miles', overlap=False)
----> 3 drive_dist_df = enrich(study_areas=[buffered], analysis_variables=['KeyGlobalFacts.TOTPOP'])

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/geoenrichment/enrichment.py in enrich(study_areas, data_collections, analysis_variables, comparison_levels, add_derivative_variables, intersecting_geographies, return_geometry, gis, proximity_type, proximity_value, proximity_metric)
   1565 
   1566     # invoke enrich on the business analyst object
-> 1567     enrich_res = enrich_src.enrich(
   1568         geographies=study_areas,
   1569         enrich_variables=enrich_vars,

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/geoenrichment/_business_analyst/_main.py in enrich(self, geographies, enrich_variables, proximity_type, proximity_value, proximity_metric, return_geometry, output_spatial_reference, estimate_credits, **kwargs)
   1527             proximity_metric = "kilometers"
   1528 
-> 1529         e_df = self._enrich(
   1530             geographies,
   1531             enrich_variables,

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/geoenrichment/_business_analyst/_utils.py in wrapped(self, *args, **kwargs)
     72             raise NotImplementedError(f"'{self.source}' is not a recognized source.")
     73 
---> 74         return fn_to_call(*args, **kwargs)
     75 
     76     return wrapped

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/geoenrichment/_business_analyst/_main.py in _enrich_gis(self, geographies, enrich_variables, country, standard_geography_level, proximity_type, proximity_value, proximity_metric, return_geometry, output_spatial_reference, estimate_credits, **kwargs)
   1914 
   1915             # no matter what the input, get a spatially enabled dataframe
-> 1916             geographies = get_spatially_enabled_dataframe(geographies)
   1917 
   1918             # tack on the spatial reference to make sure it comes along for the ride

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/geoenrichment/_business_analyst/_utils.py in get_spatially_enabled_dataframe(input_object, spatial_column)
    510 
    511     # if the geometry has not been set, take care of it
--> 512     if input_object.spatial.name is None:
    513         assert spatial_column in input_object.columns, (
    514             f"The spatial column cannot be set to {spatial_column}, "

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/arcgis/features/geo/_accessor.py in name(self)
   1473                     self.set_geometry(self._data.columns[idx])
   1474             except:
-> 1475                 raise Exception("Spatial column not defined, please use `set_geometry`")
   1476         return self._name
   1477 

Exception: Spatial column not defined, please use `set_geometry`

Expected behavior I expected the "enrich" function to return DataFrame with the demographic data of the radius area around the given address.

Platform (please complete the following information):

nanaeaubry commented 2 years ago

Hello, Thank you for bringing this to our attention. We will look into fixing it but unfortunately do not have a work around at this time.

nanaeaubry commented 2 years ago

We are working on fixing this so that a buffer study area can be taken in.

In the meantime we suggest you use the parameters: proximity_type, proximity_value, and proximity_metric found on the enrich method in order to buffer the study areas.

Sorry for the inconvenience, hope this can help as a work around until the next release.

In this case the study_area = buffered.area, proximity_value = buffered.radii, proximity_metric = buffered.units