postgis函数的学习和应用

1、st_geomfromtext  st_astext

st_geomfromtext : 将wkt数据转换成geometry空间数据

st_geomfromtext('polygon ((10.02 20.01, 11.92 35.64, 25.02 34.15,
19.15 33.94, 10.02 20.01))', 4326)// (wkt, 坐标系)

st_astext: 将数据库中的空间数据转换成wkt数据,常用于空间数据的提取

select st_astext(geom) from tableName

2、st_asmvt  st_asmvtgeom

st_asmvtgeom:函数将几何图形坐标转换成MapBox VectorTile坐标空间里的几何图形

st_asmvt:函数将基于MapBox VectorTile坐标空间的几何图形转换为MVT二进制矢量切片

二个函数通常搭配使用,可以在Java后台实现动态矢量切片

以下示例实现动态矢量切片,以及后端接口如何返回空间数据属性

<select id="selectData" resultMap="BaseResultMap" parameterType="java.util.Map">
        SELECT ST_AsMVT (tile, 'points') tile FROM (
            <foreach collection="map.attribute" item="item" index="index" separator=",">
                <if test="item == 'the_geom'">
                    SELECT st_asmvtgeom (t.the_geom,st_makeenvelope(${map.xmin}, ${map.ymin},${map.xmax},${map.ymax},4326),4096,0,TRUE) AS the_geom
                </if>
                <if test="item != 'the_geom'">
                    t."${item}"
                </if>
            </foreach>
        FROM ${map.tableName} t) AS tile WHERE tile.the_geom IS NOT NULL;
</select>

前端用maptalks加载

var vt = new VectorTileLayer("id", {
   urlTemplate: "http://xxx/tiles/{z}/{x}/{y}?tableId="+ tableId,
   spatialReference: "preset-vt-3857",
   features: true,// identify点击返回features
   schema: true,// identify点击返回属性
   pickingGeometry: true,// identify点击返回Geometry
   style
});

const sceneConfig = {
   postProcess: {
     enable: true,
     antialias: {
       enable: true,
     }
   }
}
groupLayer = new GroupGLLayer(data.id, [vt], {
   sceneConfig,
   symbol: {
     polygonFill: '#f00',
     polygonOpacity: 0.5
  }
});

3、st_extent

st_extent: 获取空间数据的外包矩形

SELECT st_astext (ST_Extent (list.the_geom))
FROM tableName list // the_geom空间字段
// 返回'POLYGON(())'

4、st_buffer

st_buffer:对空间数据进行缓冲区分析,st_buffer(geom,distance)

select st_adtext(st_buffer(list.the_geom,100)) from tableName list
// list.the_geom 空间数据 'POINT(132.5346,32.456)'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

我就是你的语法糖️

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

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

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

打赏作者

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

抵扣说明:

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

余额充值