本文首发于:获取中国指定行政区域内所有POIS(兴趣点)的方法xugongli.github.ioGitHub项目源码github.com
早在2017年5月,曾经在知乎上写过一篇文章获取一个城市全部道路名的方法总结,总结了下当时对如何获取一个城市全部道路名的探索。
当时提出了两个方法,其中之一为:从高德地图获取该城市的行政区域边界经纬度并转化为百度经纬度坐标
根据转换后的经纬度坐标找到经纬度中最大值点和最小值点,生成该多边形区域的外切矩形。
3. 把外切矩形分成若干个小矩形。注:目百度地图web api接口的限制,一次最多只能返回某一个矩形区域内的400条数据,所以要把外包矩形分成若干个小矩形
4. 利用百度地图Place Api接口,在该矩形区域以“道路”为关键字在每个矩形区域内搜索。并存储获取到的道路名和经纬度。
不过当时在使用这个方法的过程中遗留了下面三个问题:获取一个城市的经纬度边界后,只生成了该多边形的外包矩形,无法准确判断获取的点是否在这个多边形区域内,而且如果一个城市如果区域为狭长形,如上图示的内蒙古自治区,这个矩形内的大部分区域其实都是非目标区域,而且这样采集下来耗时会非常久
因为未能解决如何判断一个点是否在一个凹多边形内的问题,所以必须对采集到的所有兴趣点进行存储,而且无法根据经纬度判定其是否在指定的行政区域内
切割矩形时无法预测切割后的小矩形区域内的兴趣点数量是否小于400,精度设置需要经过多次采集后根据采集结果来评估,比较耗时<