Skip to content

Unable to replicate output of tags-filter command #273

@fbarbe00

Description

@fbarbe00

I have been trying to replicate the output of the following bash command with pyosmium:

osmium tags-filter osm_data/aachen.osm.pbf \
w/highway w/public_transport=platform w/railway=platform w/park_ride r/type=restriction \
-o aachen-filtered2.osm.pbf

Here's my python code:

import osmium

# Define the filters for the desired tags
filters = [
    osmium.filter.KeyFilter('highway').enable_for(osmium.osm.WAY),
    osmium.filter.TagFilter(('public_transport', 'platform')).enable_for(osmium.osm.WAY),
    osmium.filter.TagFilter(('railway', 'platform')).enable_for(osmium.osm.WAY),
    osmium.filter.KeyFilter('park_ride').enable_for(osmium.osm.WAY),
    osmium.filter.TagFilter(('type', 'restriction')).enable_for(osmium.osm.RELATION)
]

# Apply filters using a ForwardReferenceWriter to maintain referential completeness
writer = osmium.ForwardReferenceWriter('aachen-filtered.osm.pbf', ref_src='osm_data/aachen.osm.pbf', overwrite=True)

fp = osmium.FileProcessor('osm_data/aachen.osm.pbf')

# Add filters to the file processor
for f in filters:
  fp = fp.with_filter(f)

# Process the file and write filtered data
with writer:
  for obj in fp:
      writer.add(obj)

I would have expected these two to result in the same output file, but that does not seem to be the case.
Here's a comparison of the osmium check-refs command for both files:

# bash command
There are 49207 nodes, 14943 ways, and 272 relations in this file.
Nodes in ways missing: 0

# python code
There are 293587 nodes, 59950 ways, and 1035 relations in this file.
Nodes in ways missing: 0

Could anyone provide an explaination for the difference, to make a working python version of the bash command?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions