QGIS2web layer search for multiple layers without coding

Continuing the explanation of the ways, where we can upgrade the QGIS2web plugin manually, I would like to explain how to expand the search range in this plugin for more than 1 layer. The plugin supports the option for 1 layer only, but if you need more, coding is required. My goal is to show another way (although a bit longer I guess) to make our search tool more effective for people, who are not clued up with any programming knowledge.
My project includes 65 separate layers exactly. I want 10 of them to be researchable by a single object included (Pic. 1).

QGIS layer panel

Pic. 1 All my layers in the layer panel with 10 selected for the search bar.

In QGIS2web plugin settings, you can include only 1 layer in the search tool (Pic. 2).

QGIS2web layer search

Pic. 2 The layer search settings in the QGIS2web plugin.

We need to have 10 layers instead of 1 here.  In this event, we should follow the steps below, which will lead us to achieve our goal.
1. Save (Export) each layer as the .csv file with proper geometry – the export itself is not difficult, because we literally move out the data attribute table into the Excel file.

QGIS export layer to csv file

Pic. 3 Export layer to .csv file, where: 1 – right-clicking on our layer and selecting “Export“; 2 – Export as .csv option, with the important layer geometry options AS_WKT; 3 – our created layer appears as a new in the layer panel.

However, we have to remember geometry, as I mentioned above. This is driven by layer type. In all the layers we have shapes. It means, that they include more than 1 coordinate (each node/corner is defined by coordinates). Next, we should save our file and repeat this process for all layers, we want to have searchable. Make also sure, that the new layer CRS matches your project.

2. When all your layers have been downloaded you should open one of them and start building your big .csv file, where you will add up all other layers. The first file you open, save it under another name, and start to work on it. Since all of your new layers are opened in QGIS, you will get an alert, that the .csv file you opened is read-only.

QGIS merging CSV files

Pic. 4 Merging .csv files after export, where: 1 – first file; 2 – second file; 3 – merged file; 3a – ID name changed optionally; 3b – fid correct autofill.

Merging .csv files is not a big deal either. We should just remember a couple of important steps. The first one is our “fid” column, which is unique for every single record. We have to drag down the column range covering our 1st file (Pic 4, 3b) and apply the autofill for all our elements. Another thing is the optional name of our ID. If it’s repeatable it’s good to provide some special string, which will make them easy to find (Pic. 4, 3a). Black and red bounds indicate the column, which will be used for our search. It’s the ID column from our first file, which will be applicable also to the stuff from the next files at the bottom. Carry on this process for all your .csv files downloaded. Make this way one big .csv file including data from all your layers (especially the ID column). Make sure, that the column layout is the same (if not, shift them or trim down some stuff) and object coordinates are provided (in my case X and Y). If not, they won’t be visible on our map.
When you have done so, then there might be a necessity to organize your data, namely, place it alphabetically. In this event, you can select a whole ID column and next choose “Data” from your main Excel bar, where you can click one of the “AZ” options and order your data properly. When the toll asks you, please “Expand the selection”, which will be applicable to our all records (Pic. 5).

CSV file ordering data

Pic. 5 Putting our .csv data in the correct order by Excel “Data” tools.

Now, as you can see, there is a common error in the image above. I selected the entire column with their name. We can’t do that. We should switch off the very first row, which includes the names of our columns (Pic. 6).

CSV file correct organizing

Pic. 6 The correct organization of our .csv data, where the first row with column names is not included.

3. Next, the most important step is the import our .csv file to our QGIS project. From our main bar, we should choose the “Layer” and next add our layer as per the instruction below (Pic. 7).

QGIS adding new csv layer

Pic. 7 Adding our .csv file to QGIS, where: 1 – the “Add comma-delimited layer selection”; 2 – Data source manager window with the most important “geometry definition” bringing us an answer, why the WKT geometry type was important earlier (2b)(Pic. 3 ); 3 – Our layer visible in QGIS, which overlaps the existing objects means that everything is correct (3b); 4 – the data attribute table reflecting exactly our stuff from the .csv file.

Our layer should be instantly visible. All objects should exactly overlap the previous ones being earlier in the same place. It means, that everything is correct.

4. We don’t want this layer to be visible. We need to style it a bit. Namely, switch off any symbols related to this layer and make it invisible on our map (Pic. 8).

QGIS making layer invisible

Pic. 8 Making our layer invisible. By selecting the “No symbols” option (1) our shape turns colorless (2) and the layer itself becomes invisible.

When the shape next to our layer is colorless, it means, that layer is invisible to us.

5. The last step is setting the QGIS2web plugin, where we should make two steps. First of all, switch off the layer we created, although not completely! We don’t need it visible and it’s pop-ups at once (Pic. 9).

QGIS2web layer switching off

Pic. 9 Switching off our layer in the QGIS2web plugin and keeping it still available on the map at once.

Another, the most important step is setting the “Layer search” option, which we know already from the very beginning of this article (Pic. 2). In this case, we should select our newly imported layer and next, certainly, the column, which we want to base our search on (Pic. 10). It will be the ID column discussed previously (Pic. 4).

QGIS2web search layer selection

Pic. 10 Our multiple-layer search options in QGIS2web are ready. We should pick up the proper column from our newly imported layer (1) and apply it to our project (2).

Finally, we can enjoy our interactive map, on which we are able to find objects belonging to 10 layers instead of 1.

QGIS2web multiple layer search

Pic. 11 Multiple layer search option in QGIS2web plugin.

Mariusz Krukar


  1. Add search option
  2. https://gis.stackexchange.com/questions/146835/export-attribute-table-values-to-csv

My questions:

  1. https://gis.stackexchange.com/questions/378939/qgis2web-layer-search-for-more-than-1-layer






You may also like...