The practice of using ingenuity, or how to turn a routine into a pleasure

    As you know, any task has at least two solutions. And very often the most direct solution, which is called “head-on”, is not the best. Many of us, however, don’t really bother about this (which is a sin to conceal - in some cases I myself do the same thing, despite all the motivations and nuts in my head “it’s impossible”) and solve the problem as it is seen , and not as it could be. So, by the nature of my activity, I recently had a bit of a frankly boring routine, which I do not particularly respect and in most cases try to avoid. What to do in this case?

    It so happened that one of the projects had a rather interesting task - to make a page with a map broken down by regions of the country, in addition to all other charms, even when you hover the mouse over a certain area, it should visually stand out from the rest of the regions. In principle, everything is quite simple and there shouldn’t be any pitfalls - we take a regular tag, fill it with the necessary polygons, hang up a processor on the polygons that will show an alternative image of the area ... In general, everything is pretty 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 (and there were about 20 of them, by the way), you need to sit in gimp'e / photoshop for more than one or two minutes, meticulously collecting the coordinates of the boundaries of each polygon for the region on the map. The lesson, I tell you, is not very pleasant. Just thinking at what time it would pour out was enough for me to start looking for workarounds and try to find some alternative solution. And just at that moment, the quick-launch icon of the Inkscape vector editor caught my eye ...

    The plan matured very quickly. Inkscape itself saves all of its creations in a wonderful svg format, getting data from which is not a big problem - fortunately, libraries for working with it are enough for Python'a and for other languages. The further algorithm of actions turned out to be insanely simple - take a map, convert using Inkscape to svg, get the coordinates of the polygons and use them for the purpose already in the polygon map.

    However, there is only PNG on hand, the maximum is PSD. And this is not a vector. Having rummaged through the forums, I still found a wonderful service for tracing raster graphics in Vecton - http://vectormagic.com. Honestly, I was delighted when I found such a wonderful and useful thing. I think in the very near future I will try to do a large-scale review, since either I did not find analogues or they are not at all. The only thing that can upset is only 2 free traces per 1 mailbox. But for my task, one download was enough. Fortunately, the trace parameters are configurable, and at the output you can get a pretty high-quality vector drawing all in the same svg.

    As a result, quickly scribbled the parser of the svg-file with my heel in Python, and laden the little things of the vector map in Inkscape, I got the coveted coordinates with fairly high accuracy, which was even a little in abundance for each polygon.

    After completing work on the map, while finishing my morning coffee, I tried to imagine on my fingers how long it would take me both solutions. In the case of the first option - about 20-25 minutes for each area, but multiplying by 20 - something comes out about 8 hours. A whole working day could be spent doing utter 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 it was possible to turn a boring and not interesting, routine and exhausting work into a little research of svg and pure pleasure from programming.

    So, just refusing to go the beaten and well-known road, I managed to win almost 6 hours of my own life at work.

    Have you ever had examples of custom solutions for everyday things? Tell me, it’s interesting to know.

    Z.Y. Since the Inkscape team using astral magic, shamanism and midnight tambourines guys invented “their svg” with chess and poetesses, he suddenly died when I tried to open the svg file downloaded from vectormagic. However, the pdf2svg converter built into Inkscape works great - that's how it was possible to normally import the image obtained during tracing.

    Also popular now: