geomete是一个使用google地理编码api的自动化地理编码工具。
geomate的Python项目详细描述
功能:
- 批量地理编码大量数据。
- 支持地址或坐标(反向地理编码)。
- 自动处理输入类型,以便在数组中混合地址和坐标。
- 在sqlite数据库中自动存储数据。
- 智能api密钥配额管理,您将永远不会停留在获取geocoderquotaexeeded错误。
- 内置的日志系统,或者你可以插入你的。
- 快速查找结果。
快速链接:
用法示例
基本上,您只需要做三件事,Geomete会为您处理其他一切:
- 准备api密钥。
- 给出数据库文件的路径。
- 创建要进行地理编码的地址或坐标列表。
importgeomateimportpprint# put your google map API key here, what you see here is all fakeapi_keys=["GoogleGeoCodingApiKey01",# user1"GoogleGeoCodingApiKey02",# user2..."GoogleGeoCodingApiKey99",# user991ihu8",]# create a google geocode API clientgooglegeocoder=geomate.GoogleGeocoder(api_keys=api_keys)googlegeocoder.check_usable()# show you which keys are available# bind to a geocoder and databasebatch=geomate.BatchGeocoder(googlegeocoder,db_file="geocode.sqlite3")# construct your todo address list anyway you wantlist_of_address=["675 15th St NW Washington, DC 20005","2317 Morgan Ln Dunn Loring, VA 22027","1201 Rockville Pike Rockville, MD 20852",(39.085801,-77.084513),(38.872719,-77.306417),(38.902027,-77.053536),]batch.process_this(list_of_address)# process everything# see what's we have doneforaddressinlist_of_address:pprint.pprint(batch.lookup(address))
提前使用
假设您有10000个地址,但其中5000个是无效地址,无法进行地理编码。而无效地址恰好位于队列的开头。你可能不想浪费api配额。geomete提供一个关键字shuffle来随机执行地理编码,因此平均而言,您可以在短时间内获得大多数有效地址地理编码:
batch.process_this(list_of_address,shuffle=True)
这里有些可能有用的东西。基本上,处理过程有两个步骤:
- 将待办地址作为主键插入表中,并跳过数据库中已有的地址。
- 做地理编码。
batch.add_addresses(list_of_address)batch.process_all(shuffle=True)
查找地理编码数据
您可以通过以下方式轻松检索地理编码数据:
foraddressinlist_of_address:data=batch.lookup(address)pprint(data)
当然,您也可以从sqlite数据库中手动读取它。
安装
geomate在pypi上发布,所以您只需要:
$ pip install geomate
要升级到最新版本:
$ pip install --upgrade geomate
先决条件:geopy,要安装:
$ pip install geopy