简体   繁体   English

如何有效地将经纬度地理编码转换为行政区

[英]How to reverse geocode lat/lon into boroughs efficiently

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: 我遇到了geopy ,发现类似这样的方法非常有效:

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. 但是,我的数据集有几百万行,并且由于这是一个在线API,因此不可行。 Are there any better ways to accomplish this? 有没有更好的方法可以做到这一点?

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. 它采用纬度/经度坐标,并返回(离线)最近的城镇/城市,国家/地区,行政区1和2。

Check out this answer for a good approach. 请查看此答案,以找到一种好的方法。 You might have to define your own polygons for the shapes, though. 但是,您可能必须为形状定义自己的多边形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM