2

I need to digitize photographs and extract area information from the digitized layers. I want to use Inkscape for this. I digitized the areas as paths. I can then calculate the area using visualization → measure path → Measurement type → area. However, I have many paths organized in named layers. Is there a way to automatically extract that information using a script?

Thanks, M

  • Inkscape is based on SVG and I think it uses SVG groups as layers, so you should be able to get the layers from the SVG code pretty easily. – Cai Sep 7 '16 at 15:48
3

Inkscape layers are SVN groups. You save save an SVG file and open it in a text editor, or use the XML Editor within Inkscape Ctrl+Shift+X. A typical (abbreviated) SVG from Inkscape will look like this:

<svg:svg id="svg2">
    <svg:defs id="defs4">
    <svg:metadata>
        [...]
    </svg:metadata>
    <svg:g id="layer1" inkscape:groupmode="layer" inkscape:label="My Layer 1">
        <svg:path [...] />
    </svg:g>
    <svg:g id="layer2" inkscape:groupmode="layer" inkscape:label="My Layer 2">
        [...]
    </svg:g>
</svg:svg>

From this, you can see that:

  • Layers are just groups
  • Inkscape using a special attribute inkscape:groupmode to differentiate groups that are "layers"
  • The name you give a layer is in the inkscape:label attribute
  • If you want to select all layer in an Inkscape SVG, you want //svg:g[@inkscape:groupmode='layer'] (see gotcha below)

How you extract and use this information will depend on the scripting language.

Gotcha: Inkscape does allow nested layers, but it doesn't look like you can do that in the UI, so most users won't do it. Nesting layers can be done by manually adding the the groupmode attribute to a group. If you only want top-level layers, be sure to explicitly ask for them, such as /svg:svg/svg:g[@inkscape:groupmode='layer'].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.