Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multi-layer tiles #36

Closed
robert-claypool opened this issue Oct 30, 2019 · 7 comments
Closed

Support for multi-layer tiles #36

robert-claypool opened this issue Oct 30, 2019 · 7 comments
Assignees
Milestone

Comments

@robert-claypool
Copy link

I would like your thoughts on how to generate multi-layer tiles.

My idea is to allow requests like /{schema_name}.{table_name},{schema_name}.{table_name}/{z}/{x}/{y}.pbf and use binary concatenation of ST_AsMVT statements to produce the tile, see https://postgis.net/docs/ST_AsMVT.html

I believe the only way to do this now is via function source, for example:

CREATE OR REPLACE FUNCTION
  public.assets(z integer, x integer, y integer, query_params json)
RETURNS bytea
AS
$$
-- Prefer z,x,y inputs over z,x,y table columns.
#variable_conflict use_variable
DECLARE
  poles_mvt bytea;
  meters_mvt bytea;
BEGIN
  SELECT INTO poles_mvt
    ST_AsMVT(tile, 'public.poles', 4096, 'geom')
    FROM (
      SELECT
        ST_AsMVTGeom(shape, TileBBox(z, x, y, 3857), 4096, 64, true) AS geom
        ,"pole_number"
      FROM public.switches
      WHERE shape && TileBBox(z, x, y, 3857)
    ) AS tile
    WHERE geom IS NOT NULL;

  SELECT INTO meters_mvt
    ST_AsMVT(tile, 'public.meters', 4096, 'geom')
    FROM (
      SELECT
        ST_AsMVTGeom(shape, TileBBox(z, x, y, 3857), 4096, 64, true) AS geom
        ,"meter_number"
      FROM public.meters
      WHERE shape && TileBBox(z, x, y, 3857)
    ) AS tile
    WHERE geom IS NOT NULL;

  RETURN poles_mvt || meters_mvt;
END
$$
LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;

I have never developed in Rust, but Martin's codebase is so clean I could probably make these changes and issue a decent PR. What do you think?

@stepankuzmin
Copy link
Collaborator

Thanks for posting this, @robert-claypool!

It's planned to support multi-layered table sources and that's exactly the way I imagined that! I would gladly review PR for this.

@robert-claypool
Copy link
Author

Priorities at work have changed, and so it looks like I won't be working on this for the foreseeable future.

@stepankuzmin
Copy link
Collaborator

No problem, I'll keep this issue open and implement this in future releases.

@robert-claypool
Copy link
Author

I need this feature for an August deadline. @fielda will sponsor the work and open source it, please contact me if interested (email address is in my GitHub profile).

@stepankuzmin
Copy link
Collaborator

Hi @robert-claypool! Thanks for your patience. I've made experimental support for composite sources in #107

You can now compose table sources by listing the tables separated by a comma:

http://0.0.0.0:3000/public.red_points,public.blue_points.json
http://0.0.0.0:3000/public.red_points,public.blue_points/0/0/0.pbf

Could you please try this docker image with composite sources support and give any feedback on this?

docker pull urbica/martin:pr-107-merge

@stepankuzmin stepankuzmin linked a pull request Jul 5, 2020 that will close this issue
@sabman
Copy link

sabman commented Jul 6, 2020

Just tried it locally with two rather large layers (lines+polygons) works really well!! 🥳

martin-composite-vector-tile-2

Will do some more testing tomorrow.

@dechristopher
Copy link

This looks like it can be closed now. Thanks for the work, everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants