Obtain coordinates for: street addresses, intersections, place names, or zip codes
Enables
- Mapping of addresses
- Linking with other geospatial data
- Spatial calculations, such as distances
Juan Shishido, Andrew Chong
School of Information
GSR, D-Lab
Obtain coordinates for: street addresses, intersections, place names, or zip codes
Enables
In general, these are the steps in a geocoding project
Think about
Two primary options: local and remote
In some cases, you may want or need to use a local geocoder
Software options: ArcGIS, Postgres/PostGIS
Many options
Vary based on
Google Maps Geocoding API has high accuracy but has usage limits:
/street2coordinates
Pass in the address as a parameter
https://maps.googleapis.com/maps/api/geocode/json?address=<_your address_>
/street2coordinates
Pass in the address as a parameter
https://maps.googleapis.com/maps/api/geocode/json?address=
1600 Amphitheatre Pkwy, Mountain View, CA
{ "results" : ... "geometry" : { "location" : { "lat" : 37.422245, "lng" : -122.0840084 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 37.42359398029149, "lng" : -122.0826594197085 }, "southwest" : { "lat" : 37.4208960197085, "lng" : -122.0853573802915 } } }... }
https://maps.googleapis.com/maps/api/geocode/json?address=<_your address_>
What happens when
Photon is free and open source
However, "extensive usage will be throttled"
Search
photon.komoot.de/api/?q=berkeley
Limit number of results
photon.komoot.de/api/?q=berkeley&limit=1
Preferred language
photon.komoot.de/api/?q=berkeley&lang=fr
Pass in the address as a parameter
photon.komoot.de/api/?q=
1600 Amphitheatre Pkwy, Mountain View, CA
{"features": [{ "properties": { "osm_key":"office", "street":"Amphitheatre Parkway", "name":"Google Headquaters", "osm_id":2192620021, "osm_type":"N", "osm_value":"commercial", }, "type":"Feature", "geometry": { "type":"Point", "coordinates":[-122.0850862,37.4228139] } }], "type":"FeatureCollection"}
Geocoding with Python
Access to many geocoding services
Example from the docs
$ pip install geopy
>>> import geopy >>> from geopy.geocoders import Nominatim >>> geolocator = Nominatim() >>> location = geolocator.geocode("1600 Amphitheatre Pkwy, Mountain View, CA") >>> print((location.latitude, location.longitude)) (37.4228139, -122.0850862)
You can also reverse geocode, calculate distances, and more
Check out the geopy documentation
JavaScript Object Notation
Convert JSON to CSV
pandas
Go to Photon API linkand paste output in command below:
import json json_str = '[output from Photon API]' python_obj = json.loads(json_obj) # navigating dict by key type(python_obj) python_obj['features'] # navigating dict by list type(python_obj['features']) python_obj['features'][0]
Varies over services (remote & local)
Year matching between geocoded and reference data
Ways to assess quality
street_name
Because results are based on an underlying database or interpolation method, there will be variation in coordinate quality. In cases where the results are not good enough, consider using another service for those addresses.
To GeoJSON
Link to Census Blocks
http://data.fcc.gov/api/block/find?latitude=<_latitude_>&longitude=<_longitude_>
Block FIPS="060855046011175"
The first two characters (06) indicate the state (CA), the next three (085) indicate the county (Alameda), the next 6 indicate the census tract (5046.01) and the last four characters indicates the census block group and block number (1175). The first digit of the block identifies the block group.
Several options
Preprocess data
Sample and test
Use multiple sources
Map results to verify
Clone the repo or download the zip file from:
https://github.com/dlab-geo/geocoding-geopy
Navigate to the directory and start an IPython notebook instance
$ ipython notebook
Let's get to work
We'll create a map of the 44 BART stations in the Bay Area