如何使用`ST_AsMVTGeom`和`ST_AsMVT` [英] how to use `ST_AsMVTGeom` and `ST_AsMVT`
本文介绍了如何使用`ST_AsMVTGeom`和`ST_AsMVT`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如下表grid_cell_data
所示,我有geometryOfCellRepresentativeToTreatment
和geometryOfCellRepresentativeToBuffer
列,它们包含几何图形。
ST_AsMVTGeom
和ST_AsMVT
如PostGIS文档中所述,ST_AsMVT
采用几何列。但是当我执行以下代码时:
SELECT ST_AsMVT(grid_cell_data.geometryOfCellRepresentativeToTreatment)
AS geom
FROM grid_cell_data
我收到以下错误:
pgis_asmvt_transfn: parameter row cannot be other than a rowtype
请告诉我如何使用ST_AsMVTGeom
和ST_AsMVT
这两个函数
镜像:
推荐答案
函数ST_AsMVT
需要包含几何图形的行,而不仅仅是几何图形。使用它的一个选项是选择CTE
或subquery
中的记录,这样您就可以选择表的哪些列将被使用,例如name
和geometryOfCellRepresentativeToTreatment
:
SELECT ST_AsMVT(g) FROM (
SELECT name,geometryOfCellRepresentativeToTreatment
FROM grid_cell_data) g;
或者如果您希望使用整个记录:
SELECT ST_AsMVT(grid_cell_data)
FROM grid_cell_data
关于ST_AsMVTGeom
,您必须至少提供拼贴内容的几何图形和几何边界才能使其工作:
SELECT
ST_AsText(
ST_AsMVTGeom(
geometryOfCellRepresentativeToTreatment,
-- change to the envelope that suits your data set
ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096))))
FROM grid_cell_data;
或组合两个函数(参见documentation):
WITH j AS (
SELECT
ST_AsMVTGeom(
geometryOfCellRepresentativeToTreatment,
ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)))
FROM grid_cell_data
)
SELECT ST_AsMVT(j.*) FROM j;
演示:db<>fiddle
这篇关于如何使用`ST_AsMVTGeom`和`ST_AsMVT`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文