scottg@nysits

Using a Custom Geocoder

Discussion created by scottg@nysits on Sep 7, 2018

In NYS we have a custom ESRI geocoding service that can geocode to rooftop level accuracy, and I am trying to use for batch geocoding in a Jupyter notebook using python.  However when I attempt to perform a batch_geocode operation I am not convinced that the address is being sent to the NYS service rather than the ESRI universal geocoding service.  Here is my code:

 


In [1]:   # Import the necessary libraries

            from arcgis.gis import GIS
            from arcgis.geocoding import Geocoder, get_geocoders, batch_geocode, geocode

 

In [2]:   #Set custom ESRI geocoding service url to the NYS Geocoding Service

            nys_gcdr_url = 'Locators/Street_and_Address_Composite (GeocodeServer) '

 

In [3]:   #Establish my connection to ArcGIS Online and set the preferred geocoder to the NYS geocoder

            gis = GIS("http://www.arcgis.com", "username", "password")

            esrinl_geocoder = Geocoder(nys_gcdr_rul, gis)

            esrinl_geocoder

Out [3]:   <Geocoder                url:"https://gisservices.its.ny.gov/arcgis/rest/services/Locators/Street_and_Address_Composite/GeocodeServe                r">

 

In [4]:   addresses = ["80 South Swan Street, Albany, NY, 12201",
                                 "10 B Airline Drive, Albany, NY, 12205",
                                 "800 North Pearl Street, Albany, NY, 12204",
                                 "5826 Fayetteville Rd, Durham, NC 27713"]

 

In [6]:     results = batch_geocode(addresses, esrinl_geocoder)

 

In [7]:      for result in results:
                     print("Score " + str(result['score']) + " : " + result['address'])

Out [7]:   

Score 99.52 : 80 S Swan St, Albany, New York, 12210 Score 100 : 10 Airline Dr, Albany, New York, 12205 Score 100 : 800 N Pearl St, Albany, New York, 12204 Score 100 : 5826 Fayetteville Rd, Durham, North Carolina, 27713

In [8]:       results[1]['location']

Out [8]:    {'x': -73.81899493299994, 'y': 42.73686765800005}

  

My issue...

 

From what I can gather, the gis = GIS() in Input [3]: establishes a connection to ArcGIS Online using my developer account credentials.  Even though I set the Geocoder to the NYS geocoder url with esrinl_geocoder, I’m wondering which geocoder is actually being used?  The results/scores I output in the code are higher than I expect them to be, for example I get a score of 95.0 when I run the first address against the NYS geocoder here (Find Address Candidates: (Locators/Street_and_Address_Composite) ).  Also the x,y for the address vary based on method: 

{'x': -73.81899493299994, 'y': 42.73686765800005} for ESRI Python and 

 

{'x': -73.75989873712614, 'y': 42.654069473771784} for NYS Geocoder

 

In addition, the North Carolina address should not provide a match against the NYS geocoder, however it returns a score of 100 in Out [7].

 

So:

 

1) Does the batch_geocode operation default to the ESRI Geocoder despite the custom geocoder url being set with esrinl_geocoder?

 

2) Are there certain circumstances when this occurs, such as the ESRI geocoder kicks in when a match cannot be returned with the specified geocoder (e.g.; NC address)?

 

Thanks for any insight!

Outcomes