按特定区域名称采样地理数据集的脚本
geo-sampling的Python项目详细描述
地理采样
假设你想了解一个城市每公里街道的平均坑洞数。或者估计类似的数量。要估计数量,需要对街道上的位置进行采样。这个软件包可以帮助您对这些位置进行采样。特别是,该软件包实现了以下采样策略:
sampling frame:从OpenStreetMap获取感兴趣区域的所有街道。为此,该软件包首先以esri格式从http://www.gadm.org/country下载该地区所在国家的行政边界数据。行政数据分为多个级别,例如,城市嵌套在国家中的州中。用户可以选择城市或州,但不能选择城市的一部分。然后这个包使用pyshp package为站点http://extract.bbbike.org构建一个url,我们可以从中下载osm数据。
抽样设计:
- For each street (or road), starting from one end of the street, we split the street into .5 km segments till we reach the end of the street. (The last segment, or if the street is shorter than .5km, the only segment, can be shorter than .5 km.)
- Get the lat/long of starting and ending points of each of the segments. And assume that the street is a straight line between the .5 km segment.
- Next, create a database of all the segments
- Sample rows from the database and produce a CSV of the sampled segments
- Plot the lat/long — filling all the area within the segment. These shaded regions are regions for which data needs to be collected.
数据收集:在突出显示的段上收集数据。
先决条件
有几个依赖项需要从windows上的源代码构建,因此您可能需要安装Microsoft Visual C++ Compiler for Python 2.7。
安装
准备工作目录。我们建议您安装在python虚拟环境中。
mkdir geo_sampling cd geo_sampling virtualenv -p python2.7 venv . venv/bin/activate
将python包pip和setuptools升级到最新版本。
pip install --upgrade pip setuptools
从pypi安装地理采样包。
pip install geo-sampling
下载
截至2018年2月4日,该软件包已被下载3000多次(见saved BigQuery)。
许可证
脚本在MIT License下发布。