|
| 1 | +## PostGIS 3 瓦片提取函数 ST_TileEnvelope |
| 2 | + |
| 3 | +### 作者 |
| 4 | +digoal |
| 5 | + |
| 6 | +### 日期 |
| 7 | +2019-08-19 |
| 8 | + |
| 9 | +### 标签 |
| 10 | +PostgreSQL , PostGIS , 瓦片 |
| 11 | + |
| 12 | +---- |
| 13 | + |
| 14 | +## 背景 |
| 15 | +原文 |
| 16 | + |
| 17 | +https://info.crunchydata.com/blog/waiting-for-postgis-3-st_tileenvelopezxy |
| 18 | + |
| 19 | +With the availability of MVT tile format in PostGIS via ST_AsMVT(), 越来越多用户使用PostGIS存储并直接产生地图瓦片。 |
| 20 | + |
| 21 | +Tile coordinates consist of three values: |
| 22 | + |
| 23 | +- zoom, the level of the tile pyramid the tile is from |
| 24 | +- x, the coordinate of the tile at that zoom, counting from the left, starting at zero |
| 25 | +- y, the coordinate of the tile at that zoom, counting from the top, starting at zero |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +PostGIS 3提供了提取瓦片的函数ST_TileEnvelope,输入参数为金字塔图层的层级、x轴编号、y轴编号,瓦片空间。输出为指定x,y位置的瓦片(一个瓦片的像素为256\*256) |
| 33 | + |
| 34 | +https://en.wikipedia.org/wiki/Tiled_web_map |
| 35 | + |
| 36 | +``` |
| 37 | +geometry ST_TileEnvelope(integer tileZoom, integer tileX, integer tileY, geometry bounds=SRID=3857;LINESTRING(-20037508.342789 -20037508.342789,20037508.342789 20037508.342789)); |
| 38 | +``` |
| 39 | + |
| 40 | +这个函数默认使用Spherical Mercator坐标,https://en.wikipedia.org/wiki/Web_Mercator_projection |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +## 例子 |
| 45 | +1、使用默认坐标 |
| 46 | + |
| 47 | +``` |
| 48 | +SELECT ST_AsText( ST_TileEnvelope(2, 1, 1) ); |
| 49 | + |
| 50 | + st_astext |
| 51 | +------------------------------ |
| 52 | + POLYGON((-10018754.1713945 0,-10018754.1713945 10018754.1713945,0 10018754.1713945,0 0,-10018754.1713945 0)) |
| 53 | +``` |
| 54 | + |
| 55 | +2、使用非默认坐标 |
| 56 | +SELECT ST_AsText( ST_TileEnvelope(3, 1, 1, ST_MakeEnvelope(-180, -90, 180, 90, 4326) ) ); |
| 57 | + |
| 58 | + st_astext |
| 59 | +------------------------------------------------------ |
| 60 | + POLYGON((-135 45,-135 67.5,-90 67.5,-90 45,-135 45)) |
| 61 | +``` |
| 62 | + |
| 63 | +3、创建非默认坐标 |
| 64 | + |
| 65 | +``` |
| 66 | +geometry ST_MakeEnvelope(float xmin, float ymin, float xmax, float ymax, integer srid=unknown); |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | +## 参考 |
| 71 | +https://postgis.net/docs/manual-dev/ST_TileEnvelope.html |
| 72 | + |
| 73 | +https://info.crunchydata.com/blog/waiting-for-postgis-3-st_tileenvelopezxy |
| 74 | + |
| 75 | +https://postgis.net/docs/manual-dev/ST_MakeEnvelope.html |
| 76 | + |
| 77 | + |
| 78 | +<a rel="nofollow" href="http://info.flagcounter.com/h9V1" ><img src="http://s03.flagcounter.com/count/h9V1/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_12/viewers_0/labels_0/pageviews_0/flags_0/" alt="Flag Counter" border="0" ></a> |
| 79 | + |
| 80 | + |
| 81 | +## [digoal's 大量PostgreSQL文章入口](https://github.com/digoal/blog/blob/master/README.md "22709685feb7cab07d30f30387f0a9ae") |
| 82 | + |
| 83 | + |
| 84 | +## [免费领取阿里云RDS PostgreSQL实例、ECS虚拟机](https://free.aliyun.com/ "57258f76c37864c6e6d23383d05714ea") |
| 85 | + |
0 commit comments