NA of Moles

QGIS + Fields2Cover

Tutorial on how to export polygons in QGIS into geojson for later use in Fields2Cover

Create a polygon layer

Open QGIS.

Create the database
Create the database

In the left side bar, right-click “SpatiaLite” and select “Create Database…”

You will be asked to save the database in a .sqlite file somewhere on your disk. In my case I called it tutorial.sqlite.

Create a new table
Create a new table

Right-click on the generated database and select “New Table…”

Create the following schema:

Custom schema
Custom schema

Save with “OK”

Double click on the newly created table to add it to your layers.

Add other layers below (eg: OpenStreetMap, orthophoto providers, etc…).

In the top menu, go to “View” -> “Toolbars” and enable “Advanced Digitizing Toolbar”

How to enable ring toolbar
How to enable ring toolbar

It should look like:

Overview of the interface with map
Overview of the interface with map

How to draw

In the layer panel, select the project layer created previously and then press on the pencil icon in the toolbar

Edit mode
Edit mode

Now you can add your outer perimeter by pressing the “Add Polygon Feature” icon.

How to add polygons
How to add polygons

The polygon will obscure everything underneath making it hard to see the obstacles. We can fix this by changing the opacity of the layer.

Right click on the layer and select “Properties”

Fix opacity
Fix opacity

In the new window, use the navigation panel to select “Symbology”.

Open the “Later Rendering” menu at the bottom and change the opacity. Save with “OK”.

Opacity Settings
Opacity Settings

In the toolbars, press the “Select Feature” and click on your previosly created area. It will change color, usually into yellow.

How to select polygons
How to select polygons

Now we can add the obstacles: select the “Add Ring” from the toolbar and trace the shape of the obstacles.

How to select obstacles
How to select obstacles

After being done with it: exit the edit mode by pressing the pencil icon again and save your obect database by pressing the Floppy Disk icon 💾.

Save icon
Save icon

To export your file:

Right click on the object layer and go to “Export” -> “Save Feature As”

Menu navigation for export
Menu navigation for export

In the new window:

Export settings
Export settings

Now that you have a “.json” file you can import in F2C with

c++
1
2
3
F2CFields fields;
f2c::Parser::importJson(std::string(DATA_PATH) + "tutorial.geojson", fields);
 

Full example

Final result:

UTM Coordinates
UTM Coordinates
EPSG:6708
EPSG:6708


Tags: