📜 ⬆️ ⬇️

Practicing savvy, or how to turn routine into pleasure

As you know, any task has at least two solutions. And very often the most direct decision, as they say, “head on” is not the best. Many of us, however, do not particularly bother about this (what a sin to conceal - in some cases I do the same myself, in spite of all the motivations and nuts in my head “so it’s impossible”) and solve the problem as it can be seen , and not as it would be possible. So here, in the nature of my work, I recently started a little bit of a tedious routine that I don’t read much and in most cases I try to avoid. How to be in this case?

It so happened that on one of the projects a rather amusing task came across - to make a page with a map divided by regions of the country, in addition to all other charms, it also had to visually stand out from the rest of the regions when you hover the mouse over a certain area. In principle, everything is quite simple and there should be no pitfalls - we take an ordinary tag, fill it with the necessary polygons, hang up a handler on the polygons, which will show an alternative image of the area ... In general, everything is rather prosaic, except for one “But” - the map is quite detailed, without any hint of vector formats.

It turns out that in order to get the coveted coordinates of each region (there were about 20 of them, by the way) - you need to spend more than one or two minutes in gimp / photoshop, meticulously collecting the coordinates of the boundaries of each polygon for the region on the map. Lesson, I tell you, is not very pleasant. One thought at what time it would pour out was enough for me to start looking for workarounds and trying to find some alternative solution. And at that very moment the quick launch icon of the vector editor Inkscape came across ...

The plan matured very quickly. By itself, Inkscape saves all its creations in a wonderful svg format, getting data from which does not constitute a big problem - good, there are enough libraries for working with it both for Python and for other languages. The further algorithm of actions turned out to be insanely simple - take the map, convert it to svg using Inkscape, get the coordinates of the polygons and use them as intended in the map of the polygons.
')
However, on the hands there is only PNG, maximum - PSD. And this is not a vector. Having rummaged through the forums, I did find a wonderful service of tracing raster graphics to vector - http://vectormagic.com . Honestly, I was delighted when I found such a wonderful and useful thing. I think that in the very near future I will try to make a large-scale review, since either I did not find any analogues or not at all. The only thing that can disappoint is only 2 free traces to 1 mailbox. But for my task one load was enough. Fortunately, the tracing parameters are configurable and at the output you can get a fairly high-quality vector drawing all in the same svg.

As a result, I quickly scribbled on the Python with a heel of the svg-file parser and having edited the small details of the vector map in Inkscape, I received the coveted coordinates with a sufficiently high accuracy, of which there was even a little in excess for each polygon.

After completing the work on the map, finishing my morning coffee, I tried to imagine on my fingers how much time I would have spent on both decisions. In the case of the first option - about 20-25 minutes for each region, and multiplying by 20 - something turns out about 8 hours. The whole working day could be spent engaging in complete horror and indecency. And so, it turns out, 15-20 minutes of brainstorming and about 2 hours of work to complete the entire task. But the most important thing, in my humble opinion, is that the boring and not interesting, routine and exhausting work was turned into a small study of svg and the purest pleasure from programming.

So, just by refusing to walk the beaten and well-known road, we managed to win almost 6 hours of our life from work.

Have you ever had examples of non-standard solutions for everyday things? Tell interesting to know.

ZY Since the team of Inkscape using astral magic, shamanism and midnight tambourines, the guys invent "their svg" with chess and poetess, he suddenly died when I tried to open the svg-file downloaded from vectormagic. However, the pdf2svg converter built into Inkscape works fine - this is exactly how we managed to properly import the image obtained during the tracing.

Source: https://habr.com/ru/post/85282/


All Articles