3

Problem

In QGIS, one sometimes needs some layers with dummy data just to test something: the functionality of an expression, the syntax of an SQL query in a virtual layer, creting quickly an animation etc. For this, one first has to creat one or more new layer(s) what is a bit cumbersome: Menu Layer > Create Layer > Choose layer type > define saving path > set Geometry type > choose CRS etc. When created, the layer is still empty and you have to start adding geometries, then, depending on use case, create some attributes and fill in random values....

So it takes a whole while to create a simple line or polygon layer with a few features, including geometries and/or attributes. For point layers, there is an easier option as you can use Menu Vector > Research Tools > Random Points in Extent... But still, you have to define the extent, number of points etc. and create attributes.

Question

Is there an easy solution to create point, line and polygon layers at once without making all these settings manually? Something as easy as creating random points. Ideally, I would just like to run a single command to get a layer of each type so that I can use all the geometries I need. Layers should be, of course, geometrically and topologically correct.

Options

Optionally, it would be great if there could be created single part as well as multipart geometries. Even better would be to not only have the geometries, but also some (random) attributes of different types (integer,decimal, text, ...).

5
  • Why don't you download an extract of OSM from extract.bbbike.org, you would have a mix of geometries and attributes to the extent you set?
    – Hornbydd
    Commented Nov 20, 2023 at 10:01
  • That would be an option for the geometries, but probably difficult to find features with all different kind of attribute values consistently filled. It would also not be possible to define other CRS than what OSM uses.
    – Babel
    Commented Nov 20, 2023 at 10:35
  • For world scope, I can suggest using the QGIS's Easter eggs. Maybe it can help
    – Taras
    Commented Nov 20, 2023 at 11:10
  • @Taras for polygons yes, not for lines/points
    – Babel
    Commented Nov 20, 2023 at 11:33
  • points also yes! check this contributors
    – Taras
    Commented Nov 20, 2023 at 16:02

1 Answer 1

3

Short answer

You can create a model to create a point, line and polygon layer at once that have correct geometries and topology. You can download the model from here: https://drive.switch.ch/index.php/s/5uVZmn1m4wa9Sxh

Running the model in the "luxury" variant, creating singlepart and multipart geometries twice: as temporyry scratch layer as well as permanent Geopackage layer: enter image description here

Output of the model with single- and multiple part geometries, as temporary scratch layers (grouped together, see red outline) as well as permanent Geopackage layers. See also the singlepart point layer with randomly created attributes: enter image description here

Running the model and output

The model works for newer QGIS versions since 3.24. Grouping the output temporary scratch layers together in a group only works since 3.32.

When you add the model to the toolbox and configure Menu Settings > Options > Processing > Menus, you can add a button in the toolbar. Then creating several layers with different geomtry types and attributes becomes as easy as clicking on a button:

enter image description here


What the model does and optional settings

Apart from the different geometries, the model also automatically adds attributes with random values in integer, decimal (real), text (string), date and datetime format (based on default settings, but there are optional parameters where you can also define to limit the range/precision/length of the random values if needed).

If you use default values in the model, you can just run it without taking care about any paramenters - but you still can, if you want, change the defaults, e.g. extent, CRS or number of points created (no. of polygons will be the same). In the model's help (on the right side of the dialog window when you run it), there is a detailed description of each setting you can make.

Add the model to the toolbox so you can run it by double clicking there. See the dialog window with a lot of options (e.g. the create also multipart geometries or to save the files to disk), but you can also simply ignore all and just run the model with default values: enter image description here

Running the model in default mode

Otherwise just run the model as it is and it creates:

  1. 122 Random points in a pre-defined extent in Switzerland in EPSG:3857 (change these defaults if you want other number of points, extent, CRS).

  2. 122 polygons: voronoi polygons, based on the points.

  3. A number of 3 to 5 lines (depending on the no. of random points).

  4. All layers include the mentioned 5 attribute types with random values.

  5. By default, the model creates singlepart features only. In the advanced settings, check the box Create multipart layers, then each layer will be created as multipart layers (with some of the singlepart featers aggregated to multipart features).

  6. If you define a valid filepath to a folder in advanced settings, all layers will be created not only as temporary scratch layers, but saved to disk as permanent Geopackage layers as well.

Here is the edit mode of the model: enter image description here

2
  • 2
    This is great work but I have to be annoying here. The link will probably be dead in 5 years and then this Q&A kinda lost its point. Have you considered making this a QGIS plugin instead or publishing it at plugins.qgis.org/models/… ? Commented Nov 20, 2023 at 17:52
  • Hm, have never done so... If someone else has the ambition to do so, no problem, I would be glad. Still, I guess that some incompabilities can occur as well with a plugin: gis.stackexchange.com/q/384299/88814
    – Babel
    Commented Nov 20, 2023 at 18:35

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.