How to reverse geocode lat/lon into boroughs efficiently

ぐ巨炮叔叔 提交于 2019-12-11 00:13:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!