17.基于java+postgis的矢量瓦片

postgres12.0+postgis3.0以上版本

1.传入参数

layerName表名
zoom 级别
row 行号
col 列号

2.sql源码

 SELECT
        ST_AsMVT (tile,#{layerName},4096,'geom') tile
        FROM
        (
        SELECT
        st_asmvtgeom (geom,
        ST_TileEnvelope(${zoom}, ${row}, ${col},st_makeenvelope (-180,-270,180,90, 4326)),
        4096,
        0,
        TRUE
        ) AS geom
 		<if test="cols != null and cols != ''">
           ,${cols}
        </if>
        FROM
        ${layerName} 
        ) AS tile
        WHERE
        tile.geom IS NOT NULL;

3.调用

List<Map> mpas = tileMapper.vectorTitle(tileParam);
byte[] dd = (byte[]) mpas.get(0).get("tile");
return dd;

postgres12.0+postgis3.0以下版本

1.传入参数

layerName表名
zoom 级别
row 行号
col 列号

2.数据转换

     /**
     * 瓦片获得范围
     **/
    public TileBox tile2boundingBox(final int row, final int col, final int zoom, String layerName) {

        TileBox bb = new TileBox();
        double[] xyArr=  getExtent(zoom,row,col);
        bb.setYmax(xyArr[3]);
        bb.setYmin(xyArr[1]);
        bb.setXmin(xyArr[0]);
        bb.setXmax(xyArr[2]);
        bb.setLayerName(layerName);
        return bb;
    }

    public static double[] getExtent(int z,int x,int y){

        double n = Math.pow(2, z);
        double lon_min = (x / n) * 360.0 - 180.0;
        double lat_min = 90.0 - (((y + 1) / n) * 360.0);
        double lon_max = ((x + 1) / n) * 360.0 - 180.0;
        double lat_max = 90.0 - ((y / n) * 360.0);
        double[] xyArr={lon_min,lat_min,lon_max,lat_max};
        return xyArr;
    }

3.sql源码

     SELECT
        ST_AsMVT (tile,#{layerName},4096,'geom') tile
        FROM
        (
        SELECT
        st_asmvtgeom (t.geom,
        st_makeenvelope (${Xmin}, ${Ymin}, ${Xmax},${Ymax}, 4326),
        4096,
        0,
        TRUE
        ) AS geom
     
        FROM
        ${layerName} t
        ) AS tile
        WHERE
        tile.geom IS NOT NULL;

4.调用

        TileBox tileBox = tile2boundingBox(row, col, zoom, layerName);
        List<Map> tiles = tileMapper.getSimpleTile(tileBox);
        byte[] dd = (byte[]) tiles.get(0).get("tile");
        return dd;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫雪giser

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值