maplibre / martin

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.
https://martin.maplibre.org
Apache License 2.0
2.16k stars 204 forks source link

Handle collisions of different json properties having the same structure #662

Open ArtOshchepkov opened 1 year ago

ArtOshchepkov commented 1 year ago

TLDR

Handle different properties of json type having the same structure.

Story

I count crime & health indicators compared to country and states. I keep my data in json in PSQL like following:

crime_indicator: jsonb =  {
 by_state: 42;
 by_country: 100500;
}
health_indicator: jsonb = {
 by_state: 22;
 by_country: 8;
}

My Martin's config describes both jsonb variables:

properties:
      crime_indicator: jsonb
      health_indicator: jsonb

Requesting the tile, I got only one indicator in the feature:

properties:
 by_state: 42
 by_country: 10050

Instead, I'd like to see both features:

properties:
  crime_indicator_by_state: 42;
  crime_indicator_by_country: 8;
  health_indicator_by_state: 22;
  health_indicator_by_country: 8;

Or actual jsons

My suggestions

  1. Optionally add prefix to json values to avoid collisions.

Other

may be connected to #550 #222

Thank you for your work!

nyurik commented 1 year ago

@ArtOshchepkov thanks for the suggestion. I wonder how widespread this is? If you are already doing it in PSQL, why not simply create an MVT-generating function instead of auto-discovering it from a table/view? If you have a function, you can implement any kind of a tile generation with any structure.

Another option might be to introduce a temporary query - i.e. the same process as done by the table auto-discovery could be parametrized -- so a user can provide a full SQL query with some well defined query parameters. This would require some thinking of how to add it to the config