问题
I am working with the New York City taxi data set. The data set has columns including datetime, pickup lat/lon, dropoff lat/lon etc. Now I want to reverse geocode the lat/lon to find the borough/neighborhood. I came across geopy and found that something like this worked perfectly:
from geopy.geocoders import Nominatim
geolocator = Nominatim()
borough = []
loc = ['40.764141, -73.954430', '40.78993085, -73.9496098723']
for l in loc:
sub = str(geolocator.reverse(l))
borough.append(sub.split(', ')[2])
borough
## ['Upper East Side', 'East Harlem']
This is perfect, and exactly what I want. However, my dataset has a few million rows, and since this is an online API, it is not feasible. Are there any better ways to accomplish this?
回答1:
You can give Reverse Geocoder a try as I believe it provides the functionality you need.
It takes a latitude / longitude coordinate and returns (offline) the nearest town/city, country, administrative 1 & 2 regions.
回答2:
Check out this answer for a good approach. You might have to define your own polygons for the shapes, though.
来源:https://stackoverflow.com/questions/34984044/how-to-reverse-geocode-lat-lon-into-boroughs-efficiently