Select to view content in your preferred language

find_nearest error

2488
8
Jump to solution
03-12-2021 03:23 PM
YuliaMamonova
Frequent Contributor

Hi all,

I get the following error when I run the script with find_nearest function or any other function from use_proximity module. I am lost, tried all kinds of workarounds, nothing worked so far. I would appreciate any help.

The script is as following:

import arcgis
from arcgis.features import FeatureLayer, FeatureLayerCollection, use_proximity
from arcgis.features.use_proximity import find_nearest
from arcgis.geometry import Geometry, Point, Polyline
from arcgis.gis import GIS

agoLogin = GIS(#),
username='#',
password='#',
verify_cert=False)
 
# Get point layer with trees
trees_layer = agoLogin.content.get('#')
trees = trees_layer.layers[0].query()
 
# Get line layer with road segments
roads_layer = agoLogin.content.get('#')
roads = roads_layer.layers[0].query()

# Find nearest road segment for each tree
nearest = use_proximity.find_nearest(analysis_layer=trees, near_layer=roads,measurement_type = "StraightLine",gis = agoLogin,max_count=1)
 
The error is as following:
File "/usr/local/lib/python3.9/site-packages/arcgis/features/use_proximity.py", line 773, in find_nearest
params = inspect_function_inputs(fn=gis._tools.featureanalysis._tbx.find_nearest,
File "/usr/local/lib/python3.9/site-packages/arcgis/_impl/tools.py", line 644, in _tbx
self._gptbx = import_toolbox(url_or_item=self._url, gis=self._gis, verbose=self._verbose)
File "/usr/local/lib/python3.9/site-packages/arcgis/geoprocessing/_tool.py", line 454, in import_toolbox
f = executor.submit(fn=_generate_fn, **{"task": task, "tbx" :tbx})
TypeError: submit() missing 1 required positional argument: 'fn'
 
Thank you!!!
0 Kudos
1 Solution

Accepted Solutions
YuliaMamonova
Frequent Contributor

I changed the environment to conda and the script ran successfully. I don't quite understand why, because arcgis was installed on both environments. Any ideas?

View solution in original post

0 Kudos
8 Replies
DavidPike
MVP Frequent Contributor

I think because you have only imported find_nearest from use_proximity, when you then reference use_proximity.find_nearest() it croaks.

perhaps try just find_nearest() or otherwise - from arcgis.features import use_proximity

0 Kudos
YuliaMamonova
Frequent Contributor

Thank you, I tried what you've proposed before, still same error no matter what.

YuliaMamonova
Frequent Contributor

When I try this create_bufferes function on any hosted layer, I get the same result. I am thinking - can there be a problem with geoprocessing on my end because of my negative arcgis credits balance?

YuliaMamonova_0-1615653345807.png

 

0 Kudos
by Anonymous User
Not applicable

Hi Yulia,

That is definitely possible. A lot of these analysis tools use the default ArcGIS Online utility services, which can incur a credit cost. A worthwhile test may be to add a table/hosted feature layer to a new Web Map in your Portal organization, and then click the Analysis button from the toolbar. Here, we can run the same tools manually, including Find Nearest. If run in the web map, does the tool succeed?

Also, what do you see listed under Portal -> Organization -> Settings -> Utility Services -> Directions and Routing -> Closest Facility (Asynchronous)? If this is an ArcGIS Online URL, then it means that the operation will cost credits according to the credit breakdown here: https://doc.arcgis.com/en/arcgis-online/administer/credits.htm#ESRI_SECTION1_709121D2C7694DCAB9B8592...

The Find Nearest tool using this utility service endpoint to perform the operation.

Thanks, 

Calvin

YuliaMamonova
Frequent Contributor

Hi Calvin,

I realized that this issue is not related to credits, because my colleague successfully ran the same script with the same account credentials.

I don't know what else I can do about it. The error persists with all analysis module functions. 

Thank you,

Yulia

0 Kudos
YuliaMamonova
Frequent Contributor

I changed the environment to conda and the script ran successfully. I don't quite understand why, because arcgis was installed on both environments. Any ideas?

0 Kudos
JACooper
Regular Contributor

Update

See below for more.

Original Post

I was having the same issue but with the arcgis.features.analysis.join_features() function. It was returning the same `f = executor.submit(fn...` error. See full error below. 

What I eventually did to get it to work was roll back my arcgis installation to v1.8.4. My error was happening on python interpreters using v1.9.1 and v1.8.5.post3. I can't find anything in the release notes that would suggest any change (except maybe this?). @YuliaMamonova, perhaps your conda environment had a different installation of the arcgis package which is why it worked?

This is the second error moving beyond v1.8.4, though they may have cleaned this up in >=2.0. Anyone else have any insight? 

Full error:

Traceback (most recent call last):
File "~\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3553, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-17-9f3d49ba8bbe>", line 9, in <cell line: 9>
joined_layer = join_features(
File "~\venv\lib\site-packages\arcgis\features\summarize_data.py", line 748, in join_features
params = inspect_function_inputs(fn=gis._tools.featureanalysis._tbx.join_features, **kwargs)
File "C:\Users\Jacob.Cooper\Documents_LocalOnly\coding\local_ssm\py_venv\venv\lib\site-packages\arcgis\_impl\tools.py", line 678, in _tbx
self._gptbx = import_toolbox(url_or_item=self._url, gis=self._gis, verbose=self._verbose)
File "~\venv\lib\site-packages\arcgis\geoprocessing\_tool.py", line 463, in import_toolbox
f = executor.submit(fn=_generate_fn, **{"task": task, "tbx" :tbx})
TypeError: submit() missing 1 required positional argument: 'fn'

0 Kudos
JACooper
Regular Contributor

Update

After receiving the TypeError on an arcgis v1.8.4 installation, I did more testing and arrived at the same conclusion as @YuliaMamonova in the solution: it's not mattering which version of arcgis I am using, but the conda-based python interpreter seems to be the key to success for my script. So, my previous suggestion was incorrect. Why conda interpreters work is confounding; the other interpreters I was testing on were either the one installed directly with ArcGIS Pro or downstream virtual environments built off of that original ArcPro interpreter.

0 Kudos