7

I imported two layers to my Project (one is a shapefile from natural earth, the other is built out of lon/lat Points in a csv-data-file) QGIS fits the two graphics perfect together. Now my goal is to export this as an svg-file. This works fine, too.

Is there a way to store id-names for the paths and objects in the svg-file?

The ids should be based on the underlying attribute-tables of each layer. I have to do this automatically because of the amount of data-points. I read something about layer splitting. But I cannot even find the names of layers in my svg output file so I guess this will not help me. If there is no way to manipulate the svg directly, can it be done with a workaround? (I think about putting shapefiles with all informations together and transforming it to svg in another way?)

I am using QGIS 2.18.17 Las Palmas

I want to identify the polygons in the underlying svg data, like i have a polygon in my Image, and I open the svg-file with a text Editor, I want to have <path id="USA"><\path>. I want to have the Information stored in the metadata of the vector-graphic, but I don't want to see the data in the picture. Afterwards I want to adjust the file to fit into html and therefore I have to be able to identify single parts of the picture.

5
  • Are you exporting directly from the map canvas, or from the print composer? If you use the print composer you can add an attribute table to the exported image.
    – csk
    Commented Feb 14, 2019 at 22:45
  • Hi! I use the use the print composer. your suggestion is helpful to see the Information in the picture, but i want to identify the polygons in the underlying svg data, like i have a polygon in my Image, and i open the svg-file with a text Editor, i want to have <path id="USA"><\path>. I want to have the Information stored in the metadata of the vector-graphic, but I dont want to see the data in the picture. Afterwards I want to adjust the file to fit into html and therefore I have to be able to identify single parts of the picture… hope my description works. Thanks in advance
    – Lukas
    Commented Feb 15, 2019 at 11:10
  • I've never heard of any feature like that in QGIS.
    – csk
    Commented Feb 15, 2019 at 18:14
  • Oh thats sad. Perhaps it is possible to change the color of the single polygons in the picture by a matching in the attribute table. Then I can identify the polygons by the color used in hfill. Do you know if this works?
    – Lukas
    Commented Feb 16, 2019 at 12:00
  • That's called a categorized style, it's explained in the QGIS manual as well as in many tutorials, for example: qgistutorials.com/en/docs/basic_vector_styling.html
    – csk
    Commented Feb 19, 2019 at 17:01

2 Answers 2

3

So I found a solution for my problem:

  1. import the layers you need as usual
  2. split the layers by the attribute you want to have as an id
  3. re-import the splitted layers (so layer names will be ids)
  4. use add-in simple svg to export as svg
  5. be happy :)

Best regards to all readers

1

The approach lukas suggested didn't work for me because the simple svg plugin export included the layer IDs in the output but it lost the vector aspect of the layers and just had it as one image element.

The solution I used was similar, but using an extra step during the print composer SVG export, not using the plugin:

QGIS 3.18

  1. Import the layers you need as usual.

  2. Select Vector.Data Management Tools.Split Vector Layer.

  3. Select the attribute you want included as the "Unique ID field".

  4. Create a folder to save all the new GIS files in and enter that as the Output Directory and click Run.

  5. Remove the original layer.

  6. Drag-drop all the new files to add them as new layers.

  7. NOW. When you go to the print composer and select Export as SVG...

  8. Select "Export map layers as SVG groups"

And when you are done, you will end up with an SVG that has every separate item with that attribute as a separate element with the attribute value in the id, for example:

<g id="Map 1: NAME_Saskatchewan" inkscape:groupmode="layer" stroke="black" stroke-linejoin="bevel" stroke-linecap="square">
...
</g>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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