Re: [OSM-dev] QA, check for tag change

2019-10-03 Thread Yves
Osmfilter works well in that respect.
But I notice that Osmium is a tool I should definitely consider.
Yves ___
dev mailing list
dev@openstreetmap.org
https://lists.openstreetmap.org/listinfo/dev


Re: [OSM-dev] QA, check for tag change

2019-10-03 Thread Sarah Hoffmann
On Wed, Oct 02, 2019 at 09:30:26PM +0200, Frederik Ramm wrote:
> Hi,
> 
> On 10/2/19 20:36, yves wrote:
> > What would be a cheap way to find ways that once were highway=* and are
> > now a piste:type=nordic but no more a highway=* ?
> 
> Define "cheap" ;)
> 
> I usually tackle issue like this with a contraption of history file,
> osmium, and a script in a programming language of choice (for easy cases
> even shell script works).
> 
> The first step is to have osmium convert the history file into "OPL"
> format which gives you one ascii text line for every version of an
> object, neatly sorted by type, ID, and version:

If I may add to that: I would first filter the history file for
the intersting data (i.e. ways with piste:type=nordic) with 'osmium tags-filter'
before doing anything else. The resulting file should be much more
managable.

Sarah

___
dev mailing list
dev@openstreetmap.org
https://lists.openstreetmap.org/listinfo/dev


Re: [OSM-dev] QA, check for tag change

2019-10-02 Thread yves

Le 02.10.19 à 21:30, Frederik Ramm a écrit :

Define "cheap" ;)


"cheap" == "don't have to learn perl to work" ;)

After I typed 'import' I though about looking again at what 
osm-history-importer offers, and it seems I just need that + sqls.


Thanks for your snippets, they will give me inspiration.

Yves


___
dev mailing list
dev@openstreetmap.org
https://lists.openstreetmap.org/listinfo/dev


Re: [OSM-dev] QA, check for tag change

2019-10-02 Thread Frederik Ramm
Hi,

On 10/2/19 20:36, yves wrote:
> What would be a cheap way to find ways that once were highway=* and are
> now a piste:type=nordic but no more a highway=* ?

Define "cheap" ;)

I usually tackle issue like this with a contraption of history file,
osmium, and a script in a programming language of choice (for easy cases
even shell script works).

The first step is to have osmium convert the history file into "OPL"
format which gives you one ascii text line for every version of an
object, neatly sorted by type, ID, and version:

osmium cat somefile.osh.pbf -tway -fopl

From there, the following Perl script would for example solve your problem:

#!/usr/bin/perl

use strict;

my $lastid;
my $was_highway;
my $lost;

while(<>)
{
/^w(\d+) .*T(\S+)/ or next;
my ($id, $tags) = ($1, $2);
my $piste = ($tags =~ /piste:type=nordic/);
if ($id eq $lastid)
{
$lost = ($piste && $was_highway && $tags !~ /highway=/);
}
else
{
print "way $lastid lost its highway tag\n" if ($lost);
$lastid = $id;
undef $was_highway;
undef $lost;
}
$was_highway = $was_highway || ($tags =~ /highway=/);
}

save that in foo.pl and simply do a

osmium cat somefile.osh.pbf -tway -fopl | perl foo.pl

You will find that it is a bit rough around the edges, e.g. it doesn't
correctly handle deleted objects and disregards the very last way in the
file, but it works *in general*.

Bye
Frederik

PS: Slightly more sophisticated Perl snippets from some of my scripts
lying around include

while(<>)
{
my $part;
my @parts = split(/ /, $_);
my $obj = shift(@parts);
foreach (@parts)
{
$part->{substr($_,0,1)}=substr($_,1);
}

(this splits the OPL line into a hash that you can then access with
$part->{'v'} for the version, $part->{'T'} for the tags etc.etc.) and

my @tags = split(/,/, $part->{'T'});
my $tag;
foreach (@tags)
{
/(.*)=(.*)/;
$tag->{$1}=$2;
}

which further splits the "tags" part into a hash with tags so that you
can then write code like "if defined $tag->{'highway'}" etc.


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

___
dev mailing list
dev@openstreetmap.org
https://lists.openstreetmap.org/listinfo/dev