- 根据按行政区划范围下载瓦片
- 支持谷歌、天地图、矢量切片,以及各类
x={x}&y={y}&z={z}
形式的瓦片 - 支持标准 Mapbox 瓦片信息解析
- 能够运行用印象地图下载工具的设备一台。
- 数据库和下载工具可分开为两个服务器部署,也可放在一起。
- 操作系统,Windows 和 Linux 均可。
具体步骤略,请自行部署 MongoDB 数据库。 版本无限制,近期可用版均可。
具体步骤略,请自行部署 PostgreSQL+PostGIS 数据库。 版本:8.x 以后版本均可。
具体步骤略,请自行部署 Nodejs 运行环境。 版本请使用 LTS 版,8.xLTS、10.xLTS、12.xLTS 均可。
具体步骤略,请自行部署 Python 运行环境。 版本为:Python3.6 及更新 3.x 版本。
联网状态下,执行以下命令:
cd vector_tile_download_parser
npm i
如果下载速度慢,可切换为国内源:
npm config set registry https://registry.npm.taobao.org
# 配置后可通过下面方式来验证是否成功
npm config get registry
# 或npm info express
在 config/config.default.js
中配置相关瓦片地址信息,如果需要下载天地图,请注册天地图并使用 服务端
token。
//config/config.default.js
const userConfig = {
tile_urls: {
google_image: `http://ditu.google.cn/maps/vt/lyrs=s&x={x}&y={y}&z={z}`, //谷歌影像地址
tdt_image: `https://t1.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=tianditu_token`, //天地图地址
vector_tile: `http://mvt_host/{z}/{x}/{y}.pbf`, //矢量切片地址
},
};
//config/config.default.js
const userConfig = {
python_cover_host: "http://127.0.0.1:5004",
};
//config/config.default.js
const userConfig = {
mongo_config: "mongodb://127.0.0.1:27017/vector_tile",
sequelize: {
dialect: "postgres",
host: "127.0.0.1",
port: 5432,
database: "quhua_data",
username: "postgres",
password: "postgres",
}
}
npm start //正式启动
npm run debug //以调试模式启动,可查看输出
访问以下地址,测试能否正常返回内容。
http://127.0.0.1:7001/
联网状态下,执行以下命令,安装 Python 依赖包:
cd vector_tile_download_parser
pip install -r requirements.txt
# cover_server.py
SQLALCHEMY_DATABASE_URI = 'postgres+psycopg2://postgres:[email protected]/quhua_data' #PostgreSQL数据库连接
myclient = pymongo.MongoClient("mongodb://127.0.0.1:27017/tile_downloader") #MongoDB数据库连接
quhuaTable = 'data_xian'
if len(area_code) == 6:
quhuaTable = "data_xian" # 县边界
elif len(area_code) == 4:
quhuaTable = "quhua_shi" # 市边界
elif len(area_code) == 2:
quhuaTable = "quhua_sheng" # 省边界
python cover_server.py
访问以下地址,测试能否正常返回内容。
http://127.0.0.1:5004/
导入带有区划代码的区划编辑数据,并且区划代码字段名称为:code
。
区划边界数据命名规则:
"data_xian" # 县边界
"quhua_shi" # 市边界
"quhua_sheng" # 省边界
如果不符合规则,可在上述 Python 代码中修改。
以下载海淀区
范围内的14级
的谷歌
遥感影像
为例,:
area_code
为110108
- 下载级别为
14
级 - 下载内容为:
google_image
,需要与上述第三章中配置的信息一致。 tile_type
是指下载的是影像
还是矢量
。
http://127.0.0.1:7001/cover?area_code=110108&zoom=14&collection=google_image&tile_type=image
以上命令执行后,会在 MongoDB
数据库中创建名字为 google_image
的表(collection
)。
以上述准备的下载任务为例,访问以下地址即可开启下载任务:
- 下载的
collection
为:google_image
,需要与上述创建任务的collection
一致。
http://127.0.0.1:7001/start_download?collection=google_image
以上命令执行后会自动下载未下载的影像,直到所有下载任务完成。
以上瓦片下载完成后,可对下载的瓦片调用,使用 QGIS 等工具查看预览,配置内容如下:
http://127.0.0.1:7001/wmts?collection=google_image&x={x}&y={y}&z={z}