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

Comment as TileJSON for Database View is not working #1494

Closed
Gotcha17 opened this issue Aug 31, 2024 · 11 comments · Fixed by #1507
Closed

Comment as TileJSON for Database View is not working #1494

Gotcha17 opened this issue Aug 31, 2024 · 11 comments · Fixed by #1507
Assignees
Labels
config Relates to Martin configuration

Comments

@Gotcha17
Copy link

Hey, i am trying to customize the TileJSON in order to have some additional parameters in it with my custom text.

I am running a

  • martin tiles server v0.14.2 on a ubuntu VM
  • "PostgreSQL 16.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-12), 64-bit"

and using View as the tile source.

In this views I have tried to make change via the function as described in the docs
without success.

Additionally, I have tried just to put a simple JSON formatted text into the View description e.g.:

{
    "source_name": "Some source name",
    "source_description": "Some source description"
}

without a effect.

This applies for both cases, "auto_publish" and specific configuration of the tile source via "tables" section of the config.yaml

In all cases just the "standard" generated TileJSON is displayed without any information from the view description.
There are also any errors displayed, when I am setting RUST_LOG=debug.

Do have any advise?

@CptHolzschnauz
Copy link

Hi
I wrote a little hint on
#1246 (comment)
maybe this helps. I assume the key ist in you table definition where you define the additional fields

@Gotcha17
Copy link
Author

Thanks for your fast response @CptHolzschnauz

To clarify further: I am able to configure tiles with all the properties corresponding to the views columns. all the data is perfectly served in a maplibre web app.
My goal is to add further fields into the TileJSON. This should be possible by providing a JSON object into the Description of the View on the PostgresDB. However, as described above that has not worked for me so far.

@CptHolzschnauz
Copy link

So you mean from other tables or with parameters?
My answer was for additional fields in the same table with the GEOMETRY field. So this works for you?
I assume we are doing the same stuff at the moment, you are talking about a VIEW, right? I think that is not possible, it's either from a TABLE or a FUNCTION.
What I'm trying to achieve right now is to pass parameters to a PSQL FUNCTION. For a GET it's clear but how to implement that in the map.addSource from MapLibre is not clear to me. I just asked Stepan Kuzmin from MapBox. If i get an answer i will post here and then I plan to write a beginners guide for Martin..;=)

@Gotcha17
Copy link
Author

Just to drive the point home.
This is how my redacted TileJSON looks like
image

and this is how it is suppose to look
image

I want to achieve this by executing this SQL command on my postgres db:

DO $do$ BEGIN EXECUTE 'COMMENT ON VIEW some_view IS $tj$' || $$ { "some_description": "some layer description" } $$::json || '$tj$'; END $do$;

@CptHolzschnauz
Copy link

CptHolzschnauz commented Aug 31, 2024

Ok. So you modified auto_published in the config according to the manual and it did not worked out. So I can't help you, I think I'm working on a lower level ;=)

Anyway, the manual says:
By default the description and name is database identifies about this table, and the bounds is queried from database. You can fine tune these by adjusting auto_publish section in configuration file.
TileJSON in SQL Comments

Other than adjusting auto_publish section in configuration file, you can fine tune the TileJSON on the database side directly: Add a valid JSON as an SQL comment on the table.

Martin will merge table comment into the generated TileJSON using JSON Merge patch. The following example update description and adds attribution, version, foo(even a nested DIY field) fields to the TileJSON.

DO $do$ BEGIN
    EXECUTE 'COMMENT ON TABLE table_source IS $tj$' || $$
    {
        "version": "1.2.3",
        "attribution": "osm",
        "description": "a description from table comment",
        "foo": {"bar": "foo"}
    }
    $$::json || '$tj$';
END $do$;

@Gotcha17
Copy link
Author

Yeap, this is what I did.
I can also see the comment on my VIEW via pgadmin but it has no effect on the TileJSON.
I have also confirmed that this is a valid JSON.

@nyurik do you have an insight if this feature is exclusively working for TABLE and FUNCTION objects?

@sharkAndshark
Copy link
Collaborator

Hi @Gotcha17 I tried your json commnet and it works on Martin v0.14.2.

The table

DROP TABLE IF EXISTS table_source;
CREATE TABLE table_source(gid serial PRIMARY KEY, geom geometry(GEOMETRY, 4326));

INSERT INTO table_source(geom) values (GeomFromEWKT('SRID=4326;POINT(0 0)'));
INSERT INTO table_source(geom) values (GeomFromEWKT('SRID=4326;POINT(-2 2)'));
INSERT INTO table_source(geom) values (GeomFromEWKT('SRID=4326;LINESTRING(0 0, 1 1)'));
INSERT INTO table_source(geom) values (GeomFromEWKT('SRID=4326;LINESTRING(2 2, 3 3)'));

The sql comment

DO $do$ BEGIN
    EXECUTE 'COMMENT ON TABLE table_source IS $tj$' || $$
    {
        "source_name": "Some source name",
        "source_description": "Some source description"
    }
    $$::json || '$tj$';
END $do$;

the tile json from martin
image

@sharkAndshark
Copy link
Collaborator

May I have your full comment and table structure to make a debug?

@sharkAndshark sharkAndshark added config Relates to Martin configuration needs more info labels Sep 5, 2024
@Gotcha17
Copy link
Author

Gotcha17 commented Sep 7, 2024

hey @sharkAndshark, I can confirm that this feature works fine when using a TABLE.
However, if I am using a VIEW and reproducing all steps, then a standard TileJSON is displayed as provided in my previous comment.

Can you confirm this behavior and is it intended to only support provide this feature support for TABLEs and FUNCTIONs and not for VIEWs?

@sharkAndshark
Copy link
Collaborator

I made a test on view and it didn't work. I think it's a bug here. @Gotcha17
We will fix it.

@sharkAndshark sharkAndshark self-assigned this Sep 9, 2024
@sharkAndshark sharkAndshark changed the title Modifying TileJSON from View Description is not working Comment as TileJSON for Database View is not working Sep 9, 2024
@nyurik nyurik closed this as completed in 48cce66 Oct 20, 2024
@Gotcha17
Copy link
Author

Thanks @sharkAndshark and @nyurik !

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

Successfully merging a pull request may close this issue.

3 participants