Error message when ArcGIS cant return an address within distance parameter

1599
3
08-16-2016 08:19 PM
NilsRudqvist
New Contributor

Hi, I am trying to print (geolocator.reverse('40.759516, -73.955443', distance='100')) on an location without an address within the distance parameter. I want to iterate through a list of locations, and store the locations that return a valid address. For example, if I run a iteration with coordinates over New York, I want to store all locations that actually have an address within the set distance. However, now, when there is no address within my set distance, I get an error:

Traceback (most recent call last):
  File "./google.py", line 28, in <module>
    location = geolocator.reverse(water, distance='100')
  File "/home/strix/anaconda3/lib/python3.5/site-packages/geopy/geocoders/arcgis.py", line 202, in reverse
    raise GeocoderServiceError(str(response['error']))
geopy.exc.GeocoderServiceError: {'code': 400, 'message': 'Cannot perform query. Invalid query parameters.', 'details': ['Unable to find address for the specified location.']}

Any ideas how to write a code that can handle such an error? Is it even possible since my script actually crashes (I am quite new to python, so please excuse any noob language).

My code:

from geopy.geocoders import ArcGIS
geolocator = ArcGIS()

location = geolocator.reverse('40.759516, -73.955443', distance='100')
print (location)

Thanks,

Nils

0 Kudos
3 Replies
BruceHarold
Esri Regular Contributor

Hi Nils

You might get better support sticking to 'unwrapped' approaches, i.e. vanilla Python calling Esri's REST API natively.  For example you can leverage the code in this sample to help with your reverse geocoding problem:

http://www.arcgis.com/home/item.html?id=da9efbe1232f426ead182213f53c8cd8 

Be aware storing the results of ArcGIS Online geocoding or reverse geocoding requires service credits; in the sample the user token is picked up from the app but you can do it standalone with the generateToken call.

Regards

BruceHarold
Esri Regular Contributor

The coordinate you entered was in Antactica, if you are looking in New York this works but you need a search distance of 1000 metres as its in the river:

-73.955443,40.759516

http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=-73.95544... 

0 Kudos
NilsRudqvist
New Contributor

Hi,

Thank you for the help. I will definitely look into using the native Esri REST API. Thanks for providing a link. I am not sure I understand the part about credits, but Ill make sure to read up on it.

Best,

Nils

0 Kudos