├── .gitignore ├── run.bat ├── assets └── VectorTileServer.png ├── run.sh ├── changelog.md ├── LICENSE ├── wwwroot ├── arcgis.html └── mapbox.html ├── README.md └── config └── appsettings.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | dist 3 | -------------------------------------------------------------------------------- /run.bat: -------------------------------------------------------------------------------- 1 | SET ASPNETCORE_PATHBASE=/vector 2 | SET ASPNETCORE_URLS=http://+:5000 3 | VectorTile.exe 4 | -------------------------------------------------------------------------------- /assets/VectorTileServer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beginor/vector-tile-server/HEAD/assets/VectorTileServer.png -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | export ASPNETCORE_PATHBASE=/vector 3 | export ASPNETCORE_URLS=http://+:5000 4 | 5 | ./VectorTile 6 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Vector Tile Server version history 2 | 3 | - v1.3.0 4 | - add `cacheDuration` option to vectortile set; 5 | - rebuild with .net 6.0 . 6 | - v1.2.0 7 | - Use gzip output to save server bandwith. 8 | - v1.1.0 9 | - Add cache support. 10 | - v1.0.0 11 | - initial release. 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 beginor 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /wwwroot/arcgis.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ArcGIS Javascript API Test 9 | 10 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 实时矢量切片服务器 2 | 3 | VectorTile 是一个基于 [PostGIS](http://postgis.net/) 的 [ST_AsMVT](http://postgis.net/docs/ST_AsMVT.html) 函数开发的矢量切片服务器, HTTP 请求处理基于 .Net 6 WebAPI 实现。 4 | 5 | ![Vector Tile Server](assets/VectorTileServer.png) 6 | 7 | ## 数据库需求 8 | 9 | - `PostGIS` 最低版本为 3.1.x ; 10 | - `PostgreSQL` 虽然 PostGIS 最低支持 9.6.x 版本的 PostgreSQL , 但是建议使用最新版 14.x 以获取最佳的性能; 11 | 12 | 如果有 Docker 环境, 可以直接拉取我定制的 [PostGIS](https://hub.docker.com/r/beginor/postgis) 镜像: 13 | 14 | ```sh 15 | docker pull beginor/postgis:14-3.2.2022.0207 16 | ``` 17 | 18 | 也可以拉取 PostGIS 的官方镜像: 19 | 20 | ```sh 21 | docker pull postgis/postgis:14-3.2 22 | ``` 23 | 24 | 当然, 也可以自行安装 PostgreSQL + PostGIS 。 25 | 26 | ## 空间数据要求 27 | 28 | 空间数据格式没有要求, 只要能使用 GIS 软件 (QGIS, GDAL, ArcGIS 等) 导入到数据库中即可。 29 | 30 | 空间数据的坐标系建议是 WGS84 Web Mercator (SRID 3857) , 这个是 WebGIS 的标准, 也是矢量切片服务的默认坐标系, 输出时不需要进行坐标系转换, 效率最高。 31 | 32 | 虽然 PostGIS 提供了 [ST_Transform](http://postgis.net/docs/ST_Transform.html) 函数可以进行坐标系转换, 但是却要消耗额外的性能 (v1.1.0 提供了缓存功能, 在缓存有效时间内, 只需要进行一次坐标系转换)。 33 | 34 | ## 配置说明 35 | 36 | 矢量切片服务配置保存在 `config` 目录下的 `appsettings.json` 文件中, 配置项说明如下: 37 | 38 | ```jsonc 39 | { 40 | "logging": { }, // 默认的日志输出, 不用修改 41 | "allowedHosts": "*", // 允许的主机名, 不用修改 42 | "connectionStrings": { // 数据库连接, 必须根据自己的需要进行修改 43 | // 数据库链接示例 44 | "test_db": "server=127.0.0.1;port=5432;database=test_db;user id=postgres;password=YOUR_PASS", 45 | // 可以添加多个数据库连接 46 | "test_db2": "" 47 | }, 48 | "cache": { // 全局缓存设置 49 | "enabled": true, // 启用缓存 50 | "directory": "./app_cache", // 缓存目录 51 | "duration": 86400 // 默认的缓存时间, 以秒为单位, 1 天 3600 * 24 = 86400 秒 52 | }, 53 | "vectors": { 54 | "test1": { // 配置一个矢量切片源 55 | "connectionString": "test_db", // 上面配置数据库连接串, 也可以直接写数据库链接 56 | "cacheDuration": 3600, // 该矢量切片源的缓存时间,如果未设置则使用全局默认的缓存时间 57 | "layers": [ 58 | { 59 | "name": "road", // 图层名称 60 | "minzoom": 9, // 最小缩放级别 61 | "maxzoom": 15, // 最大缩放级别 62 | "schema": "public", // 数据表所在的架构 63 | "tableName": "sr3857_road", // 图层对应的数据表名称 64 | "idColumn": "id", // 图层的ID字段, 每一行对应一个唯一的整数, 65 | "attributeColumns": "name, fclass, ref, oneway, maxspeed, bridge, tunnel, layer", // 要输出的属性字段, 不要填 * , 请合理选择要输出的字段。 66 | "geometryColumn": "geom", // 空间坐标字段 67 | "srid": 3857 // 图层保存的坐标系, 如果 srid 不是 3857 , 将会调用 ST_Transform 实时转换 68 | }, 69 | { 70 | "name": "building", // 另一个图层, 和上面的类似 71 | "minzoom": 13, 72 | "maxzoom": 17, 73 | "schema": "public", 74 | "tableName": "sr3857_building", 75 | "idColumn": "objectid", 76 | "attributeColumns": "name, height, flag, type, area_id", 77 | "geometryColumn": "geom", 78 | "srid": 3857 79 | } 80 | ] 81 | }, 82 | "test2": { /* 可以配置多个矢量切片源 */} 83 | } 84 | } 85 | ``` 86 | 87 | ## 运行 88 | 89 | Windows 系统直接运行 run.bat , Linux 系统直接运行 run.sh , 默认测试页面地址是: 90 | 91 | - 92 | - 93 | 94 | > 如果需要修改占用的端口和上下文, 请修改 run.bat 或者 run.sh 文件内的 `ASPNETCORE_PATHBASE` 以及 `ASPNETCORE_URLS` 。 95 | -------------------------------------------------------------------------------- /wwwroot/mapbox.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Mapbox Demo 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /config/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "logging": { 3 | "logLevel": { 4 | "default": "Information", 5 | "microsoft": "Warning", 6 | "microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "allowedHosts": "*", 10 | "connectionStrings": { 11 | "geo_db": "server=127.0.0.1;port=54321;database=geo_db;user id=postgres;password=your_password;" 12 | }, 13 | "cache": { 14 | "enabled": true, 15 | "directory": "./app_cache", 16 | "duration": 86400 17 | }, 18 | "vectors": { 19 | "test1": { 20 | "connectionString": "geo_db", 21 | "cacheDuration": 3600, 22 | "layers": [ 23 | { 24 | "name": "guangzhou_road", 25 | "minzoom": 9, 26 | "maxzoom": 15, 27 | "schema": "public", 28 | "tableName": "sr3857_guangzhou_road", 29 | "idColumn": "id", 30 | "attributeColumns": "name, fclass, ref, oneway, maxspeed, bridge, tunnel, layer", 31 | "geometryColumn": "geom", 32 | "srid": 3857 33 | }, 34 | { 35 | "name": "guangzhou_building", 36 | "minzoom": 13, 37 | "maxzoom": 17, 38 | "schema": "public", 39 | "tableName": "sr3857_guangzhou_building", 40 | "idColumn": "objectid", 41 | "attributeColumns": "name, height, flag, type, area_id", 42 | "geometryColumn": "geom", 43 | "srid": 3857 44 | } 45 | ] 46 | }, 47 | "l3a1": { 48 | "cacheDuration": 1800, 49 | "connectionString": "l3a1", 50 | "layers": [ 51 | { 52 | "name": "atoms_gen_44", 53 | "minzoom": 9, 54 | "maxzoom": 19, 55 | "schema": "l3a1", 56 | "tableName": "atoms_gen_44", 57 | "idColumn": "fid", 58 | "attributeColumns": "hjysgkfqbm, hjysgkfqmc, prov, city, county", 59 | "geometryColumn": "geom", 60 | "srid": 3857 61 | }, 62 | { 63 | "name": "atoms_key_high_emission_44", 64 | "minzoom": 9, 65 | "maxzoom": 19, 66 | "schema": "l3a1", 67 | "tableName": "atoms_key_high_emission_44", 68 | "idColumn": "fid", 69 | "attributeColumns": "hjysgkfqbm, hjysgkfqmc, prov, city, county", 70 | "geometryColumn": "geom", 71 | "srid": 3857 72 | }, 73 | { 74 | "name": "atoms_key_layout_sensitive_44", 75 | "minzoom": 9, 76 | "maxzoom": 19, 77 | "schema": "l3a1", 78 | "tableName": "atoms_key_layout_sensitive_44", 79 | "idColumn": "fid", 80 | "attributeColumns": "hjysgkfqbm, hjysgkfqmc, prov, city, county", 81 | "geometryColumn": "geom", 82 | "srid": 3857 83 | }, 84 | { 85 | "name": "nr_priority_land_reource_44", 86 | "minzoom": 9, 87 | "maxzoom": 19, 88 | "schema": "l3a1", 89 | "tableName": "nr_priority_land_reource_44", 90 | "idColumn": "fid", 91 | "attributeColumns": "hjysgkfqbm, hjysgkfqmc, prov, city, county", 92 | "geometryColumn": "geom", 93 | "srid": 3857 94 | }, 95 | { 96 | "name": "eco_gen_44", 97 | "minzoom": 9, 98 | "maxzoom": 19, 99 | "schema": "l3a1", 100 | "tableName": "eco_gen_44", 101 | "idColumn": "fid", 102 | "attributeColumns": "hjysgkfqbm, hjysgkfqmc, prov, city, county", 103 | "geometryColumn": "geom", 104 | "srid": 3857 105 | }, 106 | { 107 | "name": "eco_gen_space_44", 108 | "minzoom": 9, 109 | "maxzoom": 19, 110 | "schema": "l3a1", 111 | "tableName": "eco_gen_space_44", 112 | "idColumn": "fid", 113 | "attributeColumns": "hjysgkfqbm, hjysgkfqmc, prov, city, county", 114 | "geometryColumn": "geom", 115 | "srid": 3857 116 | }, 117 | { 118 | "name": "eco_redline_44", 119 | "minzoom": 9, 120 | "maxzoom": 19, 121 | "schema": "l3a1", 122 | "tableName": "eco_redline_44", 123 | "idColumn": "fid", 124 | "attributeColumns": "hjysgkfqbm, hjysgkfqmc, prov, city, county", 125 | "geometryColumn": "geom", 126 | "srid": 3857 127 | } 128 | ] 129 | } 130 | } 131 | } 132 | --------------------------------------------------------------------------------