How to get Borough names using ArcGIS API for Python through geocoding?

580
2
12-18-2018 09:03 AM
AndréSchuck
New Contributor
I'm new to ArcGIS API for Python. Is it possible to do do geocoding of an area, specifically New York City and get all the boroughs' names (that are already saved in ArcGis database)?
i.e.: Geocode request for all boroughs in New York city and get in the 'District' element: 'Bronx, Brooklyn, Manhattan, Queens, Staten Island'
in: geocoding.geocode('New York, NY') 
out:{'address': 'New York', 'location': {'x': -74.00713999999994, 'y': 40.71455000000003},
  'score': 100,  
  'attributes': {'Loc_name': 'World',   
   'Status': 'T',   
   'Score': 100,   
   'Match_addr': 'New York',   
   'LongLabel': 'New York, NY, USA',   
   'ShortLabel': 'New York',   
   'Addr_type': 'Locality',  
    'Type': 'City',   
   'PlaceName': 'New York',   
   'Place_addr': 'New York',   
   'Rank': 2.5,  
    'AddBldg': '',  
    'Nbrhd': '',  
    'District': '',   
   'City': 'New York',  
    'MetroArea': 'New York City Metro',  
    'Subregion': 'New York County',   
   'Region': 'New York',   
   'RegionAbbr': 'NY',   
   'Territory': '',   
   'Country': 'USA',   
   'LangCode': 'ENG',  
    'Distance': 0,'},  
   'extent': {'xmin': -74.25713999999994,   
   'ymin': 40.46455000000003,  
    'xmax': -73.75713999999994,   
   'ymax': 40.96455000000003}}

Tags (3)
0 Kudos
2 Replies
JohnYaist1
Esri Contributor

Hi André Schuck 

You could make a list of the boroughs and loop through it to get the first result for each geocode:

from arcgis.geocoding import geocode

boroughs = ['Manhattan', 'Bronx', 'Staten Island', 'Queens', 'Brooklyn']
for borough in boroughs:
    print(f"{borough.upper()}\n{'=' * 50}")
    b_geocode = geocode(borough)
    print(f"{':2}{b_geocode[0]['location']}")‍‍‍‍‍‍‍‍‍‍‍‍‍‍


QUEENS
==================================================
  {'x': -73.82998999999995, 'y': 40.714000000000055}
MANHATTAN
==================================================
  {'x': -74.00600999999995, 'y': 40.714500000000044}
STATEN ISLAND
==================================================
  {'x': -74.07526999999999, 'y': 40.64242000000007}
BRONX
==================================================
  {'x': -73.92308999999995, 'y': 40.82600000000008}
BROOKLYN
==================================================
  {'x': -73.99035999999995, 'y': 40.692450000000065}
AndréSchuck
New Contributor

Hi John, thank for your help. Assuming I do not know the names of the neighborhoods, is it possible to use geocode to extract all the names of neighborhoods that are inserted in a city? That is my main doubt. 

0 Kudos