国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

PostGIS 矢量瓦片

這篇具有很好參考價值的文章主要介紹了PostGIS 矢量瓦片。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。


title: PostGIS 矢量瓦片
date: 2023-08-07
author: ac
tags:

  • vector tile
    categories:
  • Database

Martin - 基于PostGIS的矢量瓦片服務(wù)器

1. 簡介

目前流行的矢量瓦片的切圖方案:

  • mapbox gl + tippecanoe :v2收費,tippecanoe是mapbox官方推薦的矢量瓦片靜態(tài)生成工具 ,適用于大數(shù)據(jù)量場景,且不頻繁更新的空間數(shù)據(jù);
  • openlayers + geoserver :開源,使用geoserver的矢量瓦片擴展,增加矢量瓦片的輸出格式;
  • maplibre+ Martin +postgis :開源,martin是矢量切片服務(wù)器,通過postgis的函數(shù)動態(tài)生成矢量瓦片。
  • maptiler:收費

mapbox v2 必須使用 access token 才能初始化 Map 對象。進行token計算,每月50000免費次數(shù)。

2. Martin

Martin是一個開源的PostGIS矢量切片服務(wù)器,可以從任何PostGIS表或視圖中創(chuàng)建MVT矢量切片,也可以從 PMTile 和MBTile文件中動態(tài)生成矢量瓦片,是使用 Rust編寫,針對切片速度和大流量進行了優(yōu)化,是極快且輕量級的切片服務(wù)器。

2.1 安裝

如果將Martin和PostgreSQL一起使用,PostGIS版本必須為v3.0+

Martin支持Linux、macOS、windows平臺和docker環(huán)境,本例采用windows環(huán)境。先從github上下載martin-Windows-x86_64 。解壓后會發(fā)現(xiàn)這兩個exe:

─martin-Windows-x86_64
  ├─martin.exe
  └─mbtiles.exe

windows平臺可以直接使用martin.exe來啟動切片服務(wù)器,可以先在命令行查看一下參數(shù):

D:\tools\vectorTileTool\martin-Windows-x86_64>martin.exe --help
Blazing fast and lightweight tile server with PostGIS, MBTiles, and PMTiles support

Usage: martin.exe [OPTIONS] [CONNECTION]...

Arguments:
  [CONNECTION]...  Connection strings, e.g. postgres://... or /path/to/files

Options:
  -c, --config <CONFIG>
          Path to config file. If set, no tile source-related parameters are allowed
      --save-config <SAVE_CONFIG>
          Save resulting config to a file or use "-" to print to stdout. By default, only print if sources are auto-detected
  -s, --sprite <SPRITE>
          Export a directory with SVG files as a sprite source. Can be specified multiple times
  -k, --keep-alive <KEEP_ALIVE>
          Connection keep alive timeout. [DEFAULT: 75]
  -l, --listen-addresses <LISTEN_ADDRESSES>
          The socket address to bind. [DEFAULT: 0.0.0.0:3000]
  -W, --workers <WORKERS>
          Number of web server workers
  -b, --disable-bounds
          Disable the automatic generation of bounds for spatial PG tables
      --ca-root-file <CA_ROOT_FILE>
          Loads trusted root certificates from a file. The file should contain a sequence of PEM-formatted CA certificates
  -d, --default-srid <DEFAULT_SRID>
          If a spatial PG table has SRID 0, then this default SRID will be used as a fallback
  -p, --pool-size <POOL_SIZE>
          Maximum connections pool size [DEFAULT: 20]
  -m, --max-feature-count <MAX_FEATURE_COUNT>
          Limit the number of features in a tile from a PG table source
  -h, --help
          Print help
  -V, --version
          Print version
2.2 使用

本例pg安裝postgis是v3.3.3.1

martin連接pg可以用connection_string(命令行參數(shù))和配置文件兩種形式。

PostgreSQL連接字符串的形式:

# martin.exe postgresql://user:password@host/db
D:\tools\vectorTileTool\martin-Windows-x86_64>martin.exe postgresql://postgres:123@127.0.0.1:5433/postgres
[2023-08-08T03:50:11Z INFO  martin] Starting Martin v0.8.7
[2023-08-08T03:50:11Z INFO  martin] Config file is not specified, auto-detecting sources
[2023-08-08T03:50:11Z INFO  martin::pg::pool] Connecting to postgresql://postgres:123@127.0.0.1:5433/postgres
[2023-08-08T03:50:11Z INFO  martin::pg::configurator] Discovered source zhujiang_river from table public.zhujiang_river with geom column (MULTIPOLYGON, SRID=4326)
[2023-08-08T03:50:11Z INFO  martin] Use --save-config to save or print Martin configuration.
[2023-08-08T03:50:11Z INFO  martin] Martin has been started on 0.0.0.0:3000.
[2023-08-08T03:50:11Z INFO  martin] Use http://0.0.0.0:3000/catalog to get the list of available sources.

配置文件的形式 config.yaml:

# Connection keep alive timeout [default: 75]
keep_alive: 75

# The socket address to bind [default: 0.0.0.0:3000]
listen_addresses: '127.0.0.1:3000'

# Number of web server workers
worker_processes: 8
# Database configuration. This can also be a list of PG configs.
postgres:
  # Database connection string. You can use env vars too, for example:
  #   $DATABASE_URL
  #   ${DATABASE_URL:-postgresql://postgres@localhost/db}
  connection_string: 'postgresql://postgres@localhost:5433/postgres?sslmode=disable&user=postgres&password=123'
  
  # Same as PGSSLCERT for psql
  #ssl_cert: './postgresql.crt'
  # Same as PGSSLKEY for psql
  #ssl_key: './postgresql.key'
  # Same as PGSSLROOTCERT for psql
  #ssl_root_cert: './root.crt'

  #  If a spatial table has SRID 0, then this SRID will be used as a fallback
  default_srid: 4326

  # Maximum connections pool size [default: 20]
  pool_size: 20

  # Limit the number of table geo features included in a tile. Unlimited by default.
  max_feature_count: 1000

  # Control the automatic generation of bounds for spatial tables [default: false]
  # If enabled, it will spend some time on startup to compute geometry bounds.
  disable_bounds: false
D:\tools\vectorTileTool\martin-Windows-x86_64>martin.exe -c config.yaml
[2023-08-08T03:54:43Z INFO  martin] Starting Martin v0.8.7
[2023-08-08T03:54:43Z INFO  martin] Using config.yaml
[2023-08-08T03:54:43Z INFO  martin::pg::pool] Connecting to postgresql://postgres@localhost:5433/postgres?sslmode=disable&user=postgres&password=123
[2023-08-08T03:54:43Z INFO  martin::pg::configurator] Discovered source zhujiang_river from table public.zhujiang_river with geom column (MULTIPOLYGON, SRID=4326)
[2023-08-08T03:54:44Z INFO  martin] Use --save-config to save or print Martin configuration.
[2023-08-08T03:54:44Z INFO  martin] Martin has been started on 127.0.0.1:3000.
[2023-08-08T03:54:44Z INFO  martin] Use http://127.0.0.1:3000/catalog to get the list of available sources.

本例采用的是配置文件的形式啟動服務(wù)器,服務(wù)地址是http://127.0.0.1:3000。

從啟動的日志可以看到Martin將所連接的pg庫中的zhujiang_river表發(fā)布為數(shù)據(jù)源。

Martin 會將所有表發(fā)布為數(shù)據(jù)源(如果它們至少有一個幾何列)。如果 SRID 為 0,則必須設(shè)置默認(rèn) SRID,否則該地理列/表將被忽略。所有非幾何表列都將發(fā)布為矢量切片要素標(biāo)簽(屬性)。

PostGIS 矢量瓦片,postgresql

打開目錄可以看到已發(fā)布的數(shù)據(jù)源:
PostGIS 矢量瓦片,postgresql
PostGIS 矢量瓦片,postgresql

數(shù)據(jù)表的元數(shù)據(jù)是符合TileJSON 3.0.0標(biāo)準(zhǔn)的JSON文件。

TileJSON是表示地圖元數(shù)據(jù)的開放標(biāo)準(zhǔn)

2.3 mapbox

發(fā)布完數(shù)據(jù)源后,使用mapbox gl 來調(diào)用一下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/mapbox-gl@1.9.1/dist/mapbox-gl.js"></script>
    <link href="https://unpkg.com/mapbox-gl@1.9.1/dist/mapbox-gl.css"/>
    <style>
        #map{
            height: 100vh;
            width: 100%;
        }
    </style>
</head>
<body>
    <div id="map"></div>
    <script>
        
        const TIANDITU_URL = 'http://t0.tianditu.gov.cn';
        const tdtKey = "your_token";
        const tdtConfig = {
            code: 'tdt_img',
            name: '天地圖影像',
            source: {
                type: 'raster',
                tiles: [
                    `${TIANDITU_URL}/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${tdtKey}`
                ],
                tileSize: 256,
                minzoom: 0,
                maxzoom: 22
            },
            layer: {
                id: 'tdt-img-tiles',
                type: 'raster',
                minzoom: 0,
                maxzoom: 22,
                layout: { visibility: 'visible' }
            }
        }
        let map = new mapboxgl.Map({
            container:'map',
            style:{
                "version":8,
                "sources":{},
                "layers":[],
                glyphs: "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
            },
            center: [112.39747, 22.908823], // 廣東
            zoom: 8, // starting zoom 地圖初始的拉伸比例
            pitch: 0, // 地圖的角度,不寫默認(rèn)是0,取值是0-85度,一般在3D中使用
            bearing: 0, // 地圖的初始方向,值是北的逆時針度數(shù),默認(rèn)是0,即是正北
            antialias: true, // 抗鋸齒,通過false關(guān)閉提升性能
            minZoom: 3,
            maxZoom: 17.36
        });
        map.on('load', () => {
            // 天地圖底圖加載
            addLayerConfig(tdtConfig);
            addMvt();
        });
        function addLayerConfig(layerConfig){
            const {code, source,layer} = layerConfig;
            map.addSource(code, source);
            const layerParams = {
                ...layer,
                source: code
            };
            // 添加圖層
            map.addLayer(layerParams);
        }
        function addMvt(){
            map.addLayer({
                id: 'lines',
                type: 'fill',
                source: {
                    type: 'vector',
                    url: 'http://localhost:3000/zhujiang_river'
                },
                'source-layer': 'zhujiang_river',
                paint: {
                	'fill-color': 'red'
                }
            });
        }
    </script>
</body>
</html>

加載效果:

PostGIS 矢量瓦片,postgresql

3.遇到的問題

局限性:只能連接一個pg庫。

對于有分庫的系統(tǒng),可以使用Nginx來轉(zhuǎn)發(fā)。

參考文章

[1] Martin https://martin.maplibre.org/

[2] Martin Tile Server Documentation https://maplibre.org/martin/installation.html文章來源地址http://www.zghlxwxcb.cn/news/detail-643216.html

到了這里,關(guān)于PostGIS 矢量瓦片的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 安裝PostgreSQL和PostGIS

    安裝環(huán)境 Windows 2019 Standard Server 安裝PostgreSQL 安裝PostgreSQL 16 安裝PostGIS 用PostgreSQL 16對應(yīng)的PostGIS https://download.osgeo.org/postgis/windows/pg16/ https://download.osgeo.org/postgis/windows/pg16/postgis-bundle-pg16x64-setup-3.4.1-1.exe 創(chuàng)建數(shù)據(jù)庫,比如gisdb 關(guān)鍵的一步: 數(shù)據(jù)庫右鍵單擊 【查詢工具】輸入以

    2024年02月19日
    瀏覽(22)
  • arcgis+postgresql+postgis使用介紹

    arcgis+postgresql+postgis使用介紹

    關(guān)于arcgis在postgresql創(chuàng)建地理數(shù)據(jù)庫我分享一下自己的經(jīng)歷: 眾所周知,arcgis如果在oracle中創(chuàng)建地理數(shù)據(jù)庫,必須要使用ArcToolbox里面的地理數(shù)據(jù)庫工具去創(chuàng)建,在里面發(fā)現(xiàn)它還可以創(chuàng)建sql_server, postgresql數(shù)據(jù)庫類型,于是我按照arcgis,pg對應(yīng)版本去弄了一下,并且復(fù)制desktop擴展

    2024年02月11日
    瀏覽(18)
  • centos7安裝 postgresql postgis pgrouting

    centos7 源碼編譯太煩了。直接yum install ...... 一、版本信息: CentOS版本:CentOS Linux release 7.9.2009 (Core) PostgreSQL版本: PostgreSQL 12.0 PostGIS版本:postgis31 二、PostgresSQL + PostGIS 安裝 1、官網(wǎng)安裝鏈接: PostgreSQL: Linux downloads? 2、升級所有包同時也升級軟件和系統(tǒng)內(nèi)核 yum -y update 3、安裝

    2024年02月12日
    瀏覽(20)
  • Postgresql 12.2 + PostGIS 3.0.1 安裝部署

    Postgresql 12.2 + PostGIS 3.0.1 安裝部署

    參考文檔: 按照該文檔安裝即可,如果遇到報錯,可以參考下文: https://blog.csdn.net/weixin_41166785/article/details/127674169 所需的安裝包 在資源里面(我看下怎么可以不用積分下載) 1、no acceptable C compiler found in $PATH 參考:https://blog.csdn.net/IT_LPF/article/details/107360501 2、library ‘xml2’

    2024年01月17日
    瀏覽(49)
  • 在Centos系統(tǒng)源碼安裝postgreSQL數(shù)據(jù)庫及postGIS擴展

    在Centos系統(tǒng)源碼安裝postgreSQL數(shù)據(jù)庫及postGIS擴展

    安裝前 PostGIS擴展通常需要安裝一些依賴項。 1.GDAL: PostGIS需要GDAL(Geospatial Data Abstraction Library)來處理地理空間數(shù)據(jù)格式。 2.GEOS: GEOS(Geometry Engine - Open Source)是一個用于處理地理空間數(shù)據(jù)的C++庫。 3.Proj: Proj是用于地圖投影的庫。 postgreSQL與postGIS插件的版本支持關(guān)系 版本對

    2024年04月27日
    瀏覽(25)
  • Windows下載安裝 PostgreSQL和PostGIS工具,并解決The pgAdmin 4 server could not be contacted:

    Windows下載安裝 PostgreSQL和PostGIS工具,并解決The pgAdmin 4 server could not be contacted:

    目錄 一、PostgreSQL下載安裝 二、PostGIS工具軟件下載 三、測試:使用paAdmin4管理數(shù)據(jù)庫 解決The pgAdmin 4 server could not be contacted:? (1)這里使用 EnterpriseDB 來下載安裝,EnterpriseDB 是全球唯一一家提供基于 PostgreSQL 企業(yè)級產(chǎn)品與服務(wù)的廠商。 下載地址:Download PostgreSQL。 根據(jù)自己

    2024年02月05日
    瀏覽(19)
  • ARM系統(tǒng)下的postgis12 和postgis13安裝

    目錄 一、環(huán)境 二、安裝 1、安裝docker 2、安裝postgis(里面包含postgres) 三、測試 四、使用 五、問題 linux的系統(tǒng)在終端輸入: uname -a? Linux host-10-208-254-221 4.19.90-2112.8.0.0131.oe1.aarch64 #1 SMP Fri Dec 31 19:53:20 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux 搞不懂是什么系統(tǒng)??? 在網(wǎng)上搜索arm下

    2024年02月02日
    瀏覽(58)
  • postgis數(shù)據(jù)庫導(dǎo)出csv表再導(dǎo)入postgis

    postgis數(shù)據(jù)庫導(dǎo)出csv表再導(dǎo)入postgis

    直接拖過去 再導(dǎo)入postgis數(shù)據(jù)庫中

    2024年02月10日
    瀏覽(21)
  • 【Unity 學(xué)習(xí)筆記】規(guī)則瓦片和動態(tài)瓦片的應(yīng)用

    【Unity 學(xué)習(xí)筆記】規(guī)則瓦片和動態(tài)瓦片的應(yīng)用

    ????????上一篇筆記記錄了瓦片調(diào)色板的應(yīng)用,瓦片調(diào)色板常用于游戲場景的繪制,可以完全按照作者的想法繪制地圖,自由度大。但是瓦片調(diào)色板也有其缺點,就是需要人一點一點地繪制。在這片筆記中,我將介紹兩種新添加的瓦片,即規(guī)則瓦片和動態(tài)瓦片,有了這兩類

    2024年02月10日
    瀏覽(18)
  • Web地圖服務(wù)規(guī)范之柵格瓦片地圖服務(wù):WMTS(WebMapTileService,網(wǎng)絡(luò)地圖瓦片服務(wù))、TMS(TileMapService,瓦片地圖服務(wù))和XYZ

    Web地圖服務(wù)規(guī)范之柵格瓦片地圖服務(wù):WMTS(WebMapTileService,網(wǎng)絡(luò)地圖瓦片服務(wù))、TMS(TileMapService,瓦片地圖服務(wù))和XYZ

    這四種地圖服務(wù)都是通過網(wǎng)絡(luò)傳輸?shù)臇鸥裢咂貓D服務(wù),這里有三個名詞需要解釋: 遙感影像、Dem等,就是圖片。 實際上,地圖服務(wù)就是一個url,且這個url滿足一定條件:基于這個url拼上固定參數(shù)或路由地址可以獲取地圖服務(wù)的元數(shù)據(jù)信息(返回結(jié)果是xml或者json);也能獲得

    2024年02月21日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包