GIS动态矢量切片

前言

有关矢量切片以及MVT(MapBox Vector Tile)自行搜索了解,不再赘述。
接口格式 http://domain:port/map/vector/tile/{z}/{x}/{y},其中z代表缩放层级,x、y代表当前行列号


一、方法

采用postgis的函数ST_AsMVT、ST_AsMVTGeom、ST_TileEnvelope函数,实现此功能。
简单讲 ST_TileEnvelope 函数用于计算行列并返回对应的矩形范围,ST_AsMVTGeom返回图层中对应行的坐标,ST_AsMVT返回二进制的Mapbox Vector Tile数据。

函数解释

ST_AsMVT:返回一个二进制Mapbox Vector Tile

二、环境

Postresql 12.x + Postgis + Spring Boot

三、实现

MapBoxVectorTile

package com.osgeo.vectortile.domain;import lombok.Data;@Data
public class MapBoxVectorTile {private byte[] tile;
}

MapBoxVectorTileMapper

package com.osgeo.vectortile.mapper;import com.baomidou.mybatisplus.annotation.SqlParser;
import com.osgeo.vectortile.domain.MapBoxVectorTile;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;@Mapper
public interface MapBoxVectorTileMapper {@SqlParser(filter=true)MapBoxVectorTile vectorTitle2(@Param("z") Integer z, @Param("x") Integer x, @Param("y") Integer y, @Param("dpi") Integer dpi);
}

MapBoxVectorTileMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.osgeo.vectortile.mapper.MapBoxVectorTileMapper"><resultMap type="com.osgeo.vectortile.domain.MapBoxVectorTile" id="MapBoxVectorTileResult"><result property="tile" column="tile"/></resultMap><select id="vectorTitle2" resultMap="MapBoxVectorTileResult">SELECT ST_AsMVT(tiletable.*, 'gb_title', #{dpi}) as tileFROM (SELECT id,project_name                                                                               as name,approval_year                                                                              as "year",build_address                                                                              as poi,dept_id                                                                                    as dept,ST_AsMVTGeom(geo_rangeline, ST_Transform(ST_TileEnvelope(#{z}, #{x}, #{y}), 4326), #{dpi}) as geomfrom (select *from gbt_project_infowhere 1 = 1and ST_Intersects(ST_Transform(ST_TileEnvelope(#{z}, #{x}, #{y}), 4326),geo_rangeline)) ta) as tiletablewhere tiletable.geom is not null;</select>
</mapper>

MapBoxVectorTileServiceImpl

package com.osgeo.vectortile.service.impl;import com.osgeo.vectortile.mapper.MapBoxVectorTileMapper;
import com.osgeo.vectortile.service.MapBoxVectorTileService;
import com.osgeo.vectortile.utils.MapBoxVectorTileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class MapBoxVectorTileServiceImpl implements MapBoxVectorTileService {@AutowiredMapBoxVectorTileMapper mapper;@Overridepublic byte[] vectorTitle(Integer z, Integer x, Integer y) {Integer dpi = MapBoxVectorTileUtil.zoom2dpi(z);return mapper.vectorTitle2(z, x, y, dpi).getTile();}
}
package com.osgeo.vectortile.utils;import com.osgeo.vectortile.domain.TileBox;import java.util.HashMap;
import java.util.Map;public class MapBoxVectorTileUtil {private static Map<Integer, Integer> map;static {map = new HashMap<>();map.put(1, 2);map.put(2, 2);map.put(3, 2);map.put(5, 2);map.put(6, 2);map.put(7, 512);map.put(8, 512);map.put(9, 1024);map.put(10, 1024);map.put(11, 1024);map.put(12, 1024);map.put(13, 2048);map.put(14, 2048);map.put(15, 4096);map.put(16, 4096);map.put(17, 4096);map.put(18, 4096);map.put(19, 4096);map.put(20, 4096);}public static Integer zoom2dpi(Integer z) {return map.containsKey(z) ? map.get(z) : 2048;}
}

MapBoxVectorTileService

package com.osgeo.vectortile.service;public interface MapBoxVectorTileService {byte[] vectorTitle(Integer z, Integer x, Integer y);
}

MapBoxVectorTileController

package com.osgeo.vectortile.controller;import com.osgeo.vectortile.service.MapBoxVectorTileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletResponse;
import java.io.*;@RestController
@RequestMapping("/map/vector/tile")
public class MapBoxVectorTileController {@AutowiredMapBoxVectorTileService service;@GetMapping("/new/{z}/{x}/{y}")public void vectorTitle2(@PathVariable("z")Integer z, @PathVariable("x") Integer x, @PathVariable("y") Integer y, HttpServletResponse response){response.setContentType("application/x-protobuf;type=mapbox-vector;chartset=UTF-8");byte[] tile = service.vectorTitle2(z, x, y);// 输出文件流OutputStream os = null;InputStream is = null;try {is = new ByteArrayInputStream(tile);os = response.getOutputStream();byte[] bytes = new byte[1024];int len;while ((len = is.read(bytes)) != -1) {os.write(bytes, 0, len);}os.flush();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {try {is.close();os.close();} catch (IOException e) {e.printStackTrace();}}}
}

GIS动态矢量切片(MVT——MapBox Vector Tile)相关推荐

  1. mapbox矢量切片标准_Cesium 加载矢量切片(MapBox Vector Tile)

    矢量切片(vector tile)是当前 WebGIS 较热技术,国内的高德.百度等在线地图都使用了矢量切片技术.相较于传统栅格切片,矢量切片好处很多.简单几点就是:轻量.客户端渲染.还可加密(栅格切 ...

  2. 点、线、面生成mvt(MapBox Vector Tile)格式的瓦片总结

    矢量切片可以以三种形式呈现:GeoJSON.TopoJSON 和 MapBox Vector Tile(.mvt),矢量切片技术继承了矢量数据和切片地图的双重优势,有以下优点: 瓦片以mvt格式的存储 ...

  3. 使用Java对轨迹进行抽稀,并生成mvt(Map Vector Tile)瓦片

    Java对轨迹进行抽稀,并生成mvt线瓦片 1. 原理 2. pom依赖 3. Java对轨迹道格拉斯普克抽稀源码 4. Java生成线瓦片源码 参考 1. 原理 Java对轨迹抽稀:道格拉斯普克算法 ...

  4. GIS 矢量切片(Vector Tile)-地图定制化的时代已经悄悄来临

    文中代码可以在我的GitHub中找到: https://github.com/QingyaFan/data-visualization 前言 切片技术的简单介绍,以及传统栅格图片切片的不足 现在最流行 ...

  5. 【GISER Painter】矢量切片(Vector tile)番外一:Proj4js

    转载:https://www.cnblogs.com/escage/p/6406393.html 说明:番外篇是对正篇矢量切片(Vector tile)中提到的一些值得继续延伸的关注点继续进行探索和学 ...

  6. OpenLayers实例-Advanced Mapbox Vector Tiles-高级Mapbox矢量贴图

    Advanced Mapbox Vector Tiles-高级Mapbox矢量贴图 知识要点 (主要)使用此方法加载矢量地图可以在缩放级别时重用相同的源瓦片,一定程度上节省移动设备的带宽,网络环境不好 ...

  7. openlayer加载矢量切片

    数据是GIS的灵魂,没有数据也就谈不上GIS了,数据分为矢量数据和栅格数据,栅格数据也有一些短处,缺乏灵活性.实时性,数据完整性受损是比较突出的问题,矢量数据不同于栅格数据,比较灵活,数据完整,将两者 ...

  8. geoserver发布瓦片数据_OpenLayers教程十八:多源数据加载之矢量切片

    在看本篇文章之前,可以先看我翻译的这篇文章:不睡觉的怪叔叔:GeoServer官方教程:矢量切片 矢量切片就是将矢量数据以金字塔的组织方式,切割成一个一个描述性文件,目前矢量切片主要有以下三种格式: ...

  9. iclient加载标准规范的矢量瓦片mvt服务

    作者:yyy 前言 MVT全称是Mapbox Vector Tile,是Mapbox标准的矢量切片.SuperMap iClient产品很好的支持了MVT矢量瓦片在Web端的加载,但在平常的使用中基本 ...

最新文章

  1. centos7 升级curl版本
  2. Java批量生成数据库测试数据
  3. 如何使用易我数据恢复向导恢复数码相机删除的图片
  4. Tomcat 内存调大
  5. 大学计算机四级报名,2016下半年安徽理工大学计算机四级报名
  6. matlab2c使用c++实现matlab函数系列教程-blkdiag函数
  7. Android SurfaceView概述
  8. 利用octave求逆矩阵
  9. string与StringBuilder 性能差距到底有多大
  10. 片假名翻译软件测试,怎么写软件测试用例
  11. ceb怎么转换成word_win8.1系统将ceb文件格式转换成word的方法
  12. 【全网世界区划最全整理输出之第二部分】全世界所有国家的行政区划整理,省市信息,已按照国家,省,市排好序,可直接复制使用,第二部分到8167行,总条数:21088
  13. 运维知识讲解之电脑局域网服务器的密码设置和修改
  14. FreeRTOS -- 简介
  15. ASCII编码与UTF-8编码
  16. uploader上传
  17. linux设置网口ip地址,linux网口设置ip地址
  18. 网上购车平台其实也可以这样上私户
  19. 家庭宽带真的还有意义么?
  20. java怎么跳出for循环循环_java如何跳出for循环?

热门文章

  1. Python实现的美女颜值检测,你的颜值有几分呢?
  2. 解决c++错误:redefinition of class xxx
  3. 2008年毕业生工资大曝光
  4. 免费好用的笔记软件:有道云笔记 Mac中文版
  5. “离职演说”怎么说?
  6. red hat linux 5.8下载地址,Red Hat Enterprise Linux (RHEL) 5.8 DVD ISO下载
  7. python 调起wps 打开 excel
  8. 基于bim技术的应用软件有哪些?哪些应用软件?
  9. 图像基础——像素深度bpp和像素格式
  10. qemu下的USB直通功能介绍