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

Adding specific AND filters on tags #273

Open
willieCzito opened this issue Jun 9, 2021 · 1 comment
Open

Adding specific AND filters on tags #273

willieCzito opened this issue Jun 9, 2021 · 1 comment

Comments

@willieCzito
Copy link

Context

Here is an idea for improving imposm. I want to be able to apply specific filters to specific tags.

For example, I would like to map all data about oil tanks in one single table. This is how I am currently doing:

{
  "tags": {
    "load_all": true
  },
  "tables": {
    "oil_tank": {
      "type": "geometry",
      "columns": [
        {
          "type": "id",
          "name": "osm_id",
          "key": null
        },
        {
          "type": "geometry",
          "name": "geometry",
          "key": null
        },
        {
          "type": "mapping_value",
          "key": null
        },
        {
          "type": "hstore_tags",
          "name": "other_tags",
          "key": null
        }
      ],
      "filters": {
        "reject": {
          "content": ["water", "wastewater", "sewage", "manure", "hot_water"]
        }
      },
      "type_mappings": {
        "polygons": {
          "man_made": [
            "gasometer",
            "storage_tank"
          ]
        },
        "points": {
          "man_made": [
            "gasometer",
            "storage_tank"
          ]
        }
      }
    }
  }
}

The problem here is about using a reject filter instead of an accept one. So, if a new content tag is added for storage tanks, for something else than oil, then my results will be false. So this solution is not ideal.

On the other hand, if I'm using an accept filter, this will force both rows with {"man_made" : "storage_tank"} and {"man_made" : "gasometer"} to have a content tag corresponding to my list, but for gasometer no such tag exists...

Expected Behavior

What I want is to be able to choose a filter accept for rows having {"man_made" : "storage_tank"} like this: {"content": ["fuel","natural_gas","hydrocarbons", "gas", "LNG", "LPG", "oil"], and no filter on content for {"man_made" : "gasometer"}.

The goal being to be able to aggregate data from both storage tanks and [gasometers](wiki page) in one single table, applying different filters according to some tag value.

Possible Fix

What I imagine is something like the following, but there might be a better way.

{
  "tags": {
    "load_all": true
  },
  "tables": {
    "oil_building": {
      "type": "geometry",
      "columns": [
        {
          "type": "id",
          "name": "osm_id",
          "key": null
        },
        {
          "type": "geometry",
          "name": "geometry",
          "key": null
        },
        {
          "type": "mapping_value",
          "key": null
        },
        {
          "type": "hstore_tags",
          "name": "other_tags",
          "key": null
        }
      ],
      "type_mappings": {
        "polygons": [
          {
            "man_made": "gasometer"
          }, //OR
          {
            "man_made": "storage_tank", // AND
            "content": ["fuel","natural_gas","hydrocarbons", "gas", "LNG", "LPG", "oil"]
          }
        ],
        "points": [
          {
            "man_made": "gasometer"
          }, //OR
          {
            "man_made": "storage_tank", //AND
            "content": ["fuel","natural_gas","hydrocarbons", "gas", "LNG", "LPG", "oil"]
          }
        ]
      }
    }
  }
}

And maybe there's already a way to do this but I couldn't find one in the documentation.

@ImreSamu
Copy link
Contributor

ImreSamu commented Jun 9, 2021

The goal being to be able to aggregate data from both storage tanks and [gasometers](wiki page) in one single table,
applying different filters according to some tag value.

my recommendation as a workaround:

  • create 2 simple tables ( in imposm3 )
  • AND create a wrapper SQL view ( UNION ALL ) as postprocessing. ( in SQL )

see an example: #217 (comment) just replace : "green" --> storage_tank ; "red"--> gasometer

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

No branches or pull requests

2 participants