[OSM-dev] How to find the way with the most relation memberships

Frederik Ramm frederik at remote.org
Sun Aug 26 23:00:39 UTC 2018


Hi,

in the course of a discussion over on talk-gb, I wanted to find out
which ways have the highest number of relation memberships. In case
someone is interested, here's how to do it with Osmium and Perl.

1. create this Perl script which reads "opl" ascii format

#!/usr/bin/perl

while(<>)
{
    next unless /boundary/;
    s/.* M//g;
    foreach (split(/,/))
    {
        my ($a,$b)=split(/@/);
        $mem{$a}++;
    }
}

$i=0;
foreach (sort { $mem{$b}<=>$mem{$a} } keys(%mem))
{
    printf "%d %s\n", $mem{$_}, $_;
    last if ($i++>100);
}

2. feed an .osm.pbf file into it:

osmium cat some-file.osm.pbf -trelation -fopl | perl myscript.pl

I ran this for England and found a small number of ways that were
actually in over 100 different (bus route) relations ;)

If you like Python, you could of course do the whole thing in one go
using the PyOsmium library

Bye
Frederik

-- 
Frederik Ramm  ##  eMail frederik at remote.org  ##  N49°00'09" E008°23'33"



More information about the dev mailing list