Mobile app version of vmapp.org
Login or Join
Hamaas979

: Automatic extraction of layer information in Inkscape I need to digitize photographs and extract area information from the digitized layers. I want to use Inkscape for this. I digitized the areas

@Hamaas979

Posted in: #Inkscape #Script

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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamaas979

1 Comments

Sorted by latest first Latest Oldest Best

 

@Smith574

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'].

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme