#9784 closed enhancement (fixed)
md5 hashcode in mapcss
Reported by: | Klumbumbus | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | 14.03 |
Component: | Core mappaint | Version: | |
Keywords: | mapcss | Cc: |
Description
Is there a possibility to implement a function in mapcss which generates a md5 hashcode of a string?
Why I need such a or a similar function:
You may know the mappaint style Coloured Streets. Streets, buildings and address nodes with the same street name are highlighted in the same colour. (See example on Styles/Coloured_Streets). It is one of the most useful mappaint styles for JOSM in my opinion.
Currently it works this way: it uses the first character of the value of the "addr:street" key (resp. "name" for highways) to evaluate the colour. This has some disadvantages.
With a hashcode function this mappaint style could get a huge improvement. By using the first and/or last number of the hashcode of the street name instead of the street name itself, the following improvements result:
- different streets with the same first letter, which are near to each other are displayed in different colours
- typos in "name" and "addr:street" are displayed
- it works worldwide, also in countries, where a lot of streets start and end with the same letter (france, russia,...)
- it works for all unicode characters and not every single unicode character needs to added manually to the mappaint style code
If there is already a possibility to generate something like a hashcode of a (unicode) string, please tell me, otherwise could you please implement such a function?
Attachments (0)
Change History (23)
comment:1 by , 11 years ago
Component: | External mappaint style → Core mappaint |
---|---|
Keywords: | mapcss added |
comment:2 by , 11 years ago
follow-up: 4 comment:3 by , 11 years ago
Security of the hash function is not an issue in this case. But performance might be important.
A simple CRC32 checksum should be quite fast.
We may also need some kind of integer operations in mapcss to construct the color from the hash value.
comment:4 by , 11 years ago
Replying to bastiK:
Security of the hash function is not an issue in this case. But performance might be important.
For this application. Who knows for what purpose such a function will be used in future.
A simple CRC32 checksum should be quite fast.
We may also need some kind of integer operations in mapcss to construct the color from the hash value.
Propably CRC32 is a good choice. Nobody expects security from it and it is fast.
Or use a CRC24, it already has the right number of bits for a color. :-)
comment:6 by , 11 years ago
Try a style like this:
way[building]["addr:street"] { color: hsb_color(CRC32_checksum(tag("addr:street"))/4294967296.0, 0.9, 0.7); width: 10; } way[highway] { color: hsb_color(CRC32_checksum(tag("name"))/4294967296.0, 0.9, 0.7); width: 10; }
Please close ticket, if this does the job for you.
comment:7 by , 11 years ago
If you need a second "random" value, you can do
CRC32_checksum(concat(tag("name"), "x"))
comment:9 by , 11 years ago
Milestone: | → 14.03 |
---|
comment:10 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
It works fine. I'm about to edit the Coloured Streets style and I will release it as soon as the next stable version of JOSM is published.
Big thanks again!
comment:11 by , 11 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I just noticed, that CRC32_checksum() doesn't work correct for special characters like in the greek or russian alphabet. CRC32_checksum(Я) returns a hashcode of 1684325040. The same for Ш, И, Δ, Ω, ... They all return the same hashcode in JOSM, while on http://www.crc32generator.de/ they all return different hashcodes.
Some other special characters work well e.g. Æ, (although it is not the same hashcode as on http://www.crc32generator.de/).
comment:12 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
The PHP implementation likely differs from Java's one.
comment:13 by , 11 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
@Don-Vip:
"They all return the same hashcode in JOSM" --> That should not happen I think. Probably you do not compute the hash over the binary, but over the string and these strings are first converted into a 8bit text before hashing? That would yield to unexpected results for any non-latin texts. The hashing should be done over utf-8 instead.
comment:14 by , 11 years ago
For the Coloured Streets style we need a hashcode implementation, which can handle all unicode characters.
comment:15 by , 11 years ago
Sorry read too fast, indeed the getBytes() call should be replaced by getBytes(UTF8).
comment:18 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
It seems it works now correct. Thanks for the fix.
comment:19 by , 11 years ago
Not that you wonder - I splitted your description for the style properly into a German and an English page. This wiki has support for this :-)
follow-up: 22 comment:21 by , 11 years ago
P.S. Tell us, when we can deleted the "alternate" style page.
follow-up: 23 comment:22 by , 11 years ago
Replying to stoecker:
P.S. Tell us, when we can deleted the "alternate" style page.
You can delete now the alternative style page Styles/Coloured_Streets_alternative_version.
You can also delete the following pictures on Styles/Coloured_Streets
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/Help_street.jpg
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/ColourTableColouredStreets.png
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/ColouredStreets_1.011to2.0.gif
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/JOSM_internal_compared_to_ColouredStreets2.0.gif
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/exampleColouredStreets2.0.jpg
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/JOSM_internal_compared_to_Coloured_Streets3.0.gif
Normal registered user is not allowed to delete pictures, or did I fail to see the delete button?
comment:23 by , 11 years ago
Replying to Klumbumbus:
You can delete now the alternative style page Styles/Coloured_Streets_alternative_version.
You can also delete the following pictures on Styles/Coloured_Streets
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/Help_street.jpg
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/ColourTableColouredStreets.png
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/ColouredStreets_1.011to2.0.gif
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/JOSM_internal_compared_to_ColouredStreets2.0.gif
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/exampleColouredStreets2.0.jpg
- http://josm.openstreetmap.de/attachment/wiki/Styles/Coloured_Streets/JOSM_internal_compared_to_Coloured_Streets3.0.gif
Done.
Normal registered user is not allowed to delete pictures, or did I fail to see the delete button?
Delete is final in trac, so no.
If we implement such, then a newer one, e.g. sha256 or sha1.