On 22.06.2014 19:02, Steve Ratcliffe wrote:
Hi Felix
well the regex commands are a bit too difficult to understand for me. So
I would need some practical help..
So I have the following
a)Key="420 m"
b)Key="420m"
c)Key="420"
d)Key="420ft"
I want it to return number only in Key3, and number plus uni in Key2. I
assume if no unit is given in value, value is "m"
so I would like to end up with
a)Key2=420m and Key3=420
b)Key2=420m and Key3=420
c)Key2=420m and Key3=420
d)Key2=420ft and Key3=128.016
The only supported conversion is m=>ft, I think because our
contours are always in feet, so I am changing the
question to match so it can be tested. We can easily add
the reverse convertion.
okay - I would have thought reverse is also implemented.
The following will work with the given values:
Key=* {
set key2='${Key|subst:"[ \t]*~>" | subst:"(?<=[0-9]+)$~>m"}';
set key3='${Key|subst:"[a-zA-Z \t]+~>"}';
}
key2 ~ '.*m' { set key3='${key3|conv:"m=>ft"}'; }
In words this:
1. First remove all spaces and tabs and set key2
2. if a digit is at the end of key2, append a 'm'
3. remove all letters and spaces from original Key and set as key3
4. if key2 ends in 'm', then apply conversion meters to feet on key3
wow - that's complicated. Well thanks I think I can use it and will try
to understand/decipher how it's written tomorrow..
With the attached StyleTester file, I get the results:
WAY 1: Line 0x2, labels=[key2=420m key3=1378, null, null, null],
res=24-24 (1/1),(2/2),
WAY 2: Line 0x2, labels=[key2=420m key3=1378, null, null, null],
res=24-24 (1/1),(2/2),
WAY 3: Line 0x2, labels=[key2=420m key3=1378, null, null, null],
res=24-24 (1/1),(2/2),
WAY 4: Line 0x2, labels=[key2=420ft key3=420 , null, null, null],
res=24-24 (1/1),(2/2),
Using regular expressions will probably lead to more problems though.
It might fail on other strings we havn't considered for example.
Perhaps a units filter that takes two arguments: a default unit when
none is specified, and the target unit.
Well something similar to the maxspeedkmh() would be quite nice and
easier (yes I know there is length() - but in this case I rather
intended to use it for ele key.)
I would guess that a filter KEYlengthinmeters() would be similar in code
to maxspeedkmh() function,
Thanks a lot,
Felix
..Steve
--
keep on biking and discovering new trails
Felix
openmtbmap.org & www.velomap.org
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev