I would like to keep only the shapes that have no fill on this map : https://commons.wikimedia.org/wiki/File:Antarctica_in_the_World_(yellow).svg Obviously, I don't want to remove all the other ones by hand...
Is it possible to delete only the shapes that have only a fill an no stroke ? Maybe by editing the code of the file? I don't know how to do, but I know how to use regexes if necessary.
Thank you for your help.
You might use inkscape's command line but I think a custom java script is more convenient as you can immediately preview the output.
Example 1: parse from XML markup
3.1. remove elements without stroke
new XMLSerializer()Example 2: parse from XML fetched (remote) svg file
This approach requires the svg source to allow cross origin access. So the svg needs to have a appropriate CORS header or to be served from same domain.
How it works
new DOMParser()pathandpolygonelements (quite often shapes in maps can either be paths or polygons)element.getAttribute(): if a path has a fill but no stroke attribute we can remove this itemCleanup (optional)
Besides, we can remove some proprietary Adobe Illustrator metadata (used for preview images, editor settings and assets etc.).
We can also remove empty groups or unused definitions.
This way we can significantly reduce file size.
Testing: codepen example