2

I have a large set of polygons in shp, each with unique string value in attribute table. Now I need each of them in separate .geojson file (one polygon = one .geojson) but with name equal to the value in table.

I've found Multipart to singleparts in default processing panel which works just fine with the iterate option enabled, but there's no way to choose name from table. I have never wrote a script for qgis but I have some basic knowledge of programming and editing code so I tried to find this script on the computer and modify it. However I can't locate the file by name.

Or maybe there is another option to write script using this ready piece? Or some plugin which allows saving to multiple files with chosen filename?

I'm using QGIS 2.18 and QGIS 3.0.

7
  • Does the singlepart conversion not conserve the attribute table (moving it to geojson)? In other words, can't you rename the files after the fact, with your favourite (scripting) language? May 24, 2018 at 20:24
  • You should edit the title. What you want to do does not have anything to do with multipart to singleparts. Something like "Split vector layer into GeoJSON files as a batch" could describe it better.
    – user30184
    May 25, 2018 at 6:16
  • @user30184 Ok, I'll change it. But still I could done what I need with "Multipart..." only if i could set my own names.
    – Krakatau
    May 25, 2018 at 7:05
  • @lynxlynxlynx That's probably should work but I'll try with batch first.
    – Krakatau
    May 25, 2018 at 7:05
  • Multipart to single parts: This algorithm takes a vector layer with multipart geometries and generates a new one in which all geometries contain a single part. For me it seems that you have many polygons and you want to save each of them as a new dataset. But perhaps I have understood wrong. I guess that you familiar with a concept of multipart geometries (multipoints, multilinestrings, multipolygons).
    – user30184
    May 25, 2018 at 7:49

1 Answer 1

1

The tool is already available at Vector -> Data Management Tools -> Split Vector Layer. Here you choose the field and destination folder and qgis will split the layer into files with name in the field.

3
  • Well, it fix the problem with name (however adding at the beginning of file name also the name of layer, but it's easy to remove e.g. in Total Commander). But it save each object into shapefile, I need .geojson.
    – Krakatau
    May 25, 2018 at 4:47
  • you can use batch convert to change to geojson
    – neogeomat
    May 25, 2018 at 4:50
  • 1
    the problem with doing that after is you will have a load of layers with truncated field names. Jun 11, 2018 at 16:18

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.