其他
干货分享 | stata实现地址经纬度批量转换
在研究地理要素的空间分布状况时,我们往往只能得到地理单位的具体地址,而真正需要的确是对应的经纬度数据。在数据量较少时,还可以一个个核对。但是,如果当地理单位较多,特别是个体房价方面的数据时,这种方法明显不行。
这里我们将介绍如何使用stata进行批量的地址经纬度转换。
我们使用的是stata的chinagcode
命令,可通过命令ssc install chinagcode
安装,地址数据为北京市房价地址数据。我们先来看一下命令的语法格式:
完整的语法格式是:
chinagcode, baidukey(string) [province(varname) city(varname) district(varname) address(varname) fulladdress(varname)]
chinagcode
基于百度地图,其中,baidukey(string)
为百度地图密钥。密钥的获取在线资源很多,这里不再赘述。province
、city
、district
用于指定省、市、区;address
用于指定地址变量;fulladdress
用于指定包含全部信息的地址变量。详细说明如下:
Title
chinagcode -- Baidu Map API is widely used in China. This Stata module helps to extract longitude and latitude for a given Chinese
address from Baidu Map API(http://api.map.baidu.com)
Syntax
chinagcode, baidukey(string) [options]
+-----------------------+
----+ Credentials(required) +------------------------------------------------------------------------------------------------------------
baidukey(string) is required before using this command. You can get a secret key from Baidumap open platform(http://lbsyun.baidu.com).
The process normally will take 3-5 days after you submit your application online.
+---------+
----+ Address +--------------------------------------------------------------------------------------------------------------------------
province(varname) specifies the string variable that contains the name of province.
city(varname) specifies the string variable that contains the name of city.
district(varname) specifies the string variable that contains the name of district.
address(varname) specifies the string variable that contains the address.
fulladdress(varname) specifies the string variable that contains the full address.
+-------------------+
----+ Response switches +----------------------------------------------------------------------------------------------------------------
latitude(newvar) is required when you want to specify the name of the variable that contains latitude. Default choice is longitude.
longitude(newvar) is required when you want to specify the name of the variable that contains longitude. Default choice is latitude.
ffirst If the location yield from the combination address is different from the return location from the full address, ffirst specifies
that the location from the full location is a first priority.
为了方便,这里取前100个地址进行演示,如下:
use data.dta, clear
keep in 1/100
chinagcode, baidukey(zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf) lat(latitude) long(longitude) fulladdress(address)
列示前10个地址的转换效果
. list in 1/10
+-----------------------------------------------------------------------------------------------------------------------------------------+
| address price warm lon lat pratio grren longitude latitude |
|-----------------------------------------------------------------------------------------------------------------------------------------|
1. | 北京市大兴区西红门宏康路瑞海三区(瑞海家园三区) 39586 无 39.789369 116.33866 1.32 .25 116.33886 39.789476 |
2. | 北京市大兴区西红门宏康路瑞海三区(瑞海家园三区) 39586 集体供暖 39.789369 116.33866 1.32 .25 116.33886 39.789476 |
3. | 北京市大兴区西红门宏康路瑞海三区(瑞海家园三区) 39586 无 39.789369 116.33866 1.32 .25 116.33886 39.789476 |
4. | 北京市大兴区西红门宏康路瑞海三区(瑞海家园三区) 39586 无 39.789369 116.33866 1.32 .25 116.33886 39.789476 |
5. | 北京市丰台区刘家窑榴乡路84号院鲁能钓鱼台美高梅别墅 104651 无 39.850936 116.43 .56 .3 116.43025 39.851245 |
|-----------------------------------------------------------------------------------------------------------------------------------------|
6. | 北京市丰台区宋家庄宋庄路丰台金茂府 93442 无 39.847216 116.43571 1.42 .3 116.43609 39.847577 |
7. | 北京市丰台区宋家庄宋庄路丰台金茂府 119269 无 39.847216 116.43571 1.42 .3 116.43609 39.847577 |
8. | 北京市丰台区宋家庄宋庄路丰台金茂府 81250 集体供暖 39.847216 116.43571 1.42 .3 116.43609 39.847577 |
9. | 北京市丰台区宋家庄宋庄路丰台金茂府 76100 集体供暖 39.847216 116.43571 1.42 .3 116.43609 39.847577 |
10. | 北京市丰台区七里庄西局前街龙湖西宸原著 125560 无 39.880653 116.31206 4.11 .3 116.31588 39.87873 |
+-----------------------------------------------------------------------------------------------------------------------------------------+
与chiangcode
对应,stata还有用于根据经纬度返回地址的命令chinaaddress
,语法与chiangcode
很接近,这里不做介绍。有兴趣的同学可以自己研究一下。
转载自微信公众号 计量
经作者授权转载
文章仅代表作者观点,与本公众号无关,版权归原作者所有
图文排版:刘有于
责任编辑:张英浩
审核:王波涛
终审:顾伟男 田巍 梁龙武
猜你喜欢
扫描二维码,关注我们
都是成年人了,要记得告诉地小联你也“在看”哦~👇