Skip to content

Automatic label point layer from Multipolygon layer using ST_PointOnSurface on the fly #1143

Answered by sharkAndshark
IncidGeo asked this question in Q&A
Discussion options

You must be logged in to vote

Postgres function which takes z integer (or zoom integer), x integer, y integer as arguments and return bytea will be added as vector tile source.

You need to create a database function like this:

CREATE OR REPLACE
    FUNCTION my_points(z integer, x integer, y integer)
    RETURNS bytea AS $$
DECLARE
  mvt bytea;
BEGIN
  SELECT INTO mvt ST_AsMVT(tile, 'my_points', 4096, 'geom') FROM (
    SELECT
      ST_AsMVTGeom(
          ST_Transform(ST_PointOnSurface(geom) , 3857),
          ST_TileEnvelope(z, x, y),
          4096, 64, true) AS geom
    FROM some_multipolygon_table
    WHERE geom && ST_Transform(ST_TileEnvelope(z, x, y), 4326)
  ) as tile WHERE geom IS NOT NULL;

  RETURN mvt;
END
…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
4 replies
@IncidGeo
Comment options

@sharkAndshark
Comment options

Answer selected by IncidGeo
@sharkAndshark
Comment options

@IncidGeo
Comment options

Comment options

You must be logged in to vote
3 replies
@IncidGeo
Comment options

@nyurik
Comment options

@sharkAndshark
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants