gotcha

Author Topic: Colouring from File  (Read 1504 times)

April 08, 2018, 12:42:16 PM
Read 1504 times

Makemakean

  • Sr. Newbie

  • Offline
  • **

  • 3
Ladies and gentlemen, I'm glad to be joining this forum, and as such, I start with the very question I joined this forum to ask in the hope that someone who is more of a master of the craft than I am might help! :)

Me and a few other friends at another forum are into making graphics and maps for a variety of elections, and usually this boils down to drawing up constituencies and municipalities or provinces or whatnot, and filling these in with various shades of colour to indicate various things (say, relative party strength in terms of percentage of vote, margin with which the most popular party ranks above the second most popular, and so forth and so on).

Given any election, there is of course a huge set of data one has at one's hands, far more than is possible to display in a single graph, and to manually go through each and every constituency and change the colours for each and every set of data you want to display, it can be quite tedious work. So I was wondering, maybe there's an easier way?

Specifically, I was wondering if one somehow can give "tags" or "links" to the different objects one have in a picture one is working on in Inkscape, and then somehow "import" the colours one wants to use from say a spreadsheet, or a standard .txt file, or what not? Or, if that isn't an option, depending on how data is stored in an an .svg file, whether it is technically possible to write some sort of script in Python that goes through the different entries and changes to colour after a given algorithm?

April 08, 2018, 05:59:15 PM
Reply #1

brynn

  • Administrator

  • Offline
  • ******

  • 3,941
  • Gender
    Female

    Female
    • Inkscape Community
Welcome to the forum!

Yes, it should be possible to do that.  And probably there are a few ways to approach it.  All of those ways are over my head, so I can't give you any specifics.

But I can say that Inkscape's extensions are mostly written in Python.  So if you have the skills to code in Python, you probably will be able to make yourself an extension to do this work.  However, making an extension would primarily serve the purpose of providing this functionality to all Inkscape users.  You could also use a script (Python, or other - I'm not sure what other languages would work - over my head) only for yourselves.  Or additionally, Inkscape has commandline capabilities, so  as far as I understand, that's another way in which certain things can be automated.

Here's a guide to writing extensions, and also a link to the commandline reference:
https://inkscape.org/en/develop/extensions/
https://inkscape.org/en/doc/inkscape-man.html

I'm not clear from your description if you're using Inkscape to draw the maps.  But the info I've provided is only relative to use in an SVG, or maybe other vector format file.  I suppose it would be possible to do this in a raster file, but I expect it would be harder to do.

But I'm sure someone else will chime in with info that I omitted, or didn't state quite right.

Do you need info on drawing the maps?  That part is right up my alley!
  • Inkscape version 0.92.3
  • Windows 7 Pro, 64-bit
Inkscape Tutorials (and manuals)                      Inkscape Community Gallery                        Inkscape for Cutting Design                     



"Be ashamed to die until you have won some victory for humanity" - Horace Mann                       

April 09, 2018, 05:35:40 AM
Reply #2

Makemakean

  • Sr. Newbie

  • Offline
  • **

  • 3
Well, since posting this question yesterday, I did get the wonderful idea (which really should have struck me much earlier) to actually open one of those .svg files in an ordinary text editor, and much to my surprise, the file was saved in a very understandable and readable format, more or less demonstrating to me immediately that not just would it be possible to write a Python script for myself to accomplish this thing, it would actually be an easy thing to do.

As for making a full-on extension of this. Well, I must admit that my Python skills are those an amateur and a hobbyist, and usually when I do code it is merely for my own purposes. Kind of like how one does not need to be a professional carpenter to have use of a toolbox, so to speak. But I must admit your suggestion is tempting. One would very much like to contribute to a free- and open source software project. Tell ya what, when I've finished with the script I need for my own purposes, I shall begin looking into how one can make this into a full, proper extension!  :)

As for how I drew the map, well I did do that in Inkscape of course. As for if I need info, well, for the set of election maps I'm drawing right now, I've actually gotten all the data on the candidates and constituents and the boundaries from a very reputable and reliable source, so there's no need for any help in that department at the moment. However, if you're just talking about info on mapmaking in general (the process of tracing out coastlines and what not), I actually could use some help on a few questions of mine, mainly having to do with what are the terms of copyright one needs to be aware of, as well as questions of how many nodes one should be aiming for, and what is the reasonable size of a final image.

I'd be delighted to continue that part of the conversation in PM format if you're interested.  :)

April 09, 2018, 03:00:57 PM
Reply #3

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
Exactly :)

https://inkscape.org/en/develop/about-svg/

I like to use beautiful soup , it's a very comfortable library for parsing xml (https://www.crummy.com/software/BeautifulSoup/bs4/doc/).

April 09, 2018, 06:37:02 PM
Reply #4

Makemakean

  • Sr. Newbie

  • Offline
  • **

  • 3
I like to use beautiful soup , it's a very comfortable library for parsing xml (https://www.crummy.com/software/BeautifulSoup/bs4/doc/).

Ah, now that'll come in more than handy! Thank you very much! :)

April 09, 2018, 09:51:12 PM
Reply #5

brynn

  • Administrator

  • Offline
  • ******

  • 3,941
  • Gender
    Female

    Female
    • Inkscape Community
I'm not sure if using PM is necessary.  But we can if you like.  For now, I'll just post some general info here.  (As a bonus, it could benefit other visitors.)  If you want more details, or want to PM, of course we can do that.

....what are the terms of copyright one needs to be aware of....

If you drew the map entirely in Inkscape (and didn't put anything inside the file which might carry a restrictive license), you can choose whatever license you like.  However, I suspect I've missed your question there.

(the process of tracing out coastlines and what not)

Here's a tutorial I wrote about how to "vectorize" a raster map (targetted towards newbies).  But even if you are drawing a map without tracing a raster image, it gives details about creating and editing paths.  https://forum.inkscapecommunity.com/index.php?action=articles;sa=view;article=47

how many nodes one should be aiming for, and what is the reasonable size of a final image.

Generally you want to use as few nodes as possible.  The more nodes you use, the larger the file will be.  And when you start to approach 500 to 1000 nodes (depending on your system's RAM) you may start to see performance issues, such as Inkscape working more slowly, and even to the point of freezing and crashing, if the file becomes really large.

But there are other reasons for keeping the file "lean".  If you are planning to do other things with the file later, such as convert to other file formats, import into different software (either for editing, or such as a CNC interface), combine it with other files, or combine portions of it with other files.  Or if you are planning to use some of Inkscape's more advanced features, such as certain extensions or LPEs, the fewer nodes possible will give the best results.  (And not to confuse you, but there are a couple of odd extensions or LPEs where adding a few more nodes can be helpful.  But we're always here, if you get stuck or have questions.)

The reasonable size for a final image is not something I could guess.  It depends how large the map is (or how many maps are in the file) and what kind of tools or features you used.  Here's another tutorial (or maybe more of an article?) I wrote, about how to either avoid performance issues, or to continue working in a large file which is already having performance issues.  So that will give you a few clues about making a nice lean file.  https://forum.inkscapecommunity.com/index.php?action=articles;sa=view;article=35

PM me, if you like  :)
  • Inkscape version 0.92.3
  • Windows 7 Pro, 64-bit
Inkscape Tutorials (and manuals)                      Inkscape Community Gallery                        Inkscape for Cutting Design                     



"Be ashamed to die until you have won some victory for humanity" - Horace Mann