如何有效地将经纬度地理编码转换为行政区 [英] How to reverse geocode lat/lon into boroughs efficiently

查看:626
本文介绍了如何有效地将经纬度地理编码转换为行政区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用纽约市出租车数据集.数据集的列包括日期时间,取货纬度/经度,落差纬度/经度等.现在,我想对纬度/经度进行反向地理编码以找到自治市/邻里.我碰到了geopy,发现类似这样的东西非常有效:

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']

这很完美,正是我想要的.但是,我的数据集有几百万行,并且由于这是一个在线API,因此不可行.有没有更好的方法可以做到这一点?

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和[ 2个地区.

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.

这篇关于如何有效地将经纬度地理编码转换为行政区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆