Skip to content
python 后台连接postgis 返回矢量切片,前端mapboxgl加载显示 50万点数据,秒级显示
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
image
README.md
Util.py
tilesOnline.py

README.md

postgis-stMvt

python 后台连接postgis 返回矢量切片

使用

  • 在tileOline.py中配置自己的postgis连接参数
      Dbpool = psycopg2.pool.SimpleConnectionPool(
         1,
         100,
         dbname='GISMVT',
         user='postgres',
         host='localhost',
         password='admin',
         port='5432')
    
  • 重要的查询语句
   // 传 source-layer 和 tableName参数动态获取
   query = "SELECT  ST_AsMVT( tile , '" + sourceLayer + "' , 4096 , 'geoms' ) tiles FROM ( SELECT   ST_AsMVTGeom( w.geoms , ST_Transform( ST_MakeEnvelope ( %s,%s,%s,%s,4326),3857),4096,256,true) AS geoms ,w.* FROM (SELECT  ST_Transform(geom,3857) geoms , * FROM public." + tableName + "  ) w ) AS tile ;"
  
  • mapbox前端加载代码
  this.map.addLayer({
                 "id":"PostGIS",
                 "type":"circle",
                 "source":{
                     "type":"vector",
                     "tiles":[window.origin+"/mapserver/tiles/{z}/{x}/{y}"],
                 },"source-layer":"fills",
                 "paint":{
                     "circle-opacity":1,
                     "circle-radius":2,
                     "circle-color":"#00f"
                 },
                 "layout":{
                     "visibility":"none"
                 }
             });

结果

image
image

You can’t perform that action at this time.