13.1. Accedere ai dati

Facendo parte di un ecosistema Software Open Source QGIS è costruito su diverse librerie che, unitamente agli specifici provider, offrono la capacità di leggere e spesso scrivere molti formati:

  • Vector data formats include GeoPackage, GML, GeoJSON, GPX, KML, Comma Separated Values, ESRI formats (Shapefile, Geodatabase…), MapInfo and MicroStation file formats, AutoCAD DWG/DXF, GRASS and many more… Read the complete list of supported vector formats.

  • Raster data formats include GeoTIFF, JPEG, ASCII Gridded XYZ, MBTiles, R or Idrisi rasters, GDAL Virtual, SRTM, Sentinel Data, ERDAS IMAGINE, ArcInfo Binary Grid, ArcInfo ASCII Grid, and many more… Read the complete list of supported raster formats.

  • I formati di database includono PostgreSQL/PostGIS, SQLite/SpatiaLite, Oracle, DB2 o MSSQL Spatial, MySQL …;

  • Web map and data services (WM(T)S, WFS, WCS, CSW, XYZ tiles, ArcGIS services, …) are also handled by QGIS providers. See QGIS come client di dati OGC for more information about some of these.

  • You can read supported files from archived folders and use QGIS native formats such as QML files (QML - The QGIS Style File Format) and virtual and memory layers.

More than 80 vector and 140 raster formats are supported by GDAL and QGIS native providers.

Nota

Not all of the listed formats may work in QGIS for various reasons. For example, some require external proprietary libraries, or the GDAL/OGR installation of your OS may not have been built to support the format you want to use. To see the list of available formats, run the command line ogrinfo --formats (for vector) and gdalinfo --formats (for raster), or check Settings ▶ Options ▶ GDAL menu (for raster) in QGIS.

In QGIS, depending on the data format, there are different tools to open a dataset, mainly available in the Layer ▶ Add Layer ▶ menu or from the Manage Layers toolbar (enabled through View ▶ Toolbars menu). However, all these tools point to a unique dialog, the Data Source Manager dialog, that you can open with the dataSourceManager Open Data Source Manager button, available on the Data Source Manager Toolbar, or by pressing Ctrl+L. The Data Source Manager dialog offers a unified interface to open vector or raster file-based data as well as databases or web services supported by QGIS. It can be set modal or not with the checkbox Modeless data source manager dialog in the Settings ▶ Options ▶ General menu.

../../../_images/datasource_manager.png

Fig. 13.1 Finestra di dialogo QGIS Gestore delle sorgenti dati

Beside this main entry point, you also have the dbManager DB Manager plugin that offers advanced capabilities to analyze and manipulate connected databases. More information on DB Manager capabilities can be found in Plugin DB Manager.

There are many other tools, native or third-party plugins, that help you open various data formats.

This chapter will describe only the tools provided by default in QGIS for loading data. It will mainly focus on the Data Source Manager dialog but more than describing each tab, it will also explore the tools based on the data provider or format specificities.

13.1.1. Il Pannello Browser

Il Browser è uno dei modi principali per aggiungere rapidamente e facilmente i tuoi dati ai progetti. È disponibile come:

  • una scheda Gestore della sorgente dati, abilitata premendo il pulsante dataSourceManager Apri gestore della sorgente dati (Ctrl+L);

  • come pannello QGIS che puoi aprire dal menu Visualizza ▶ Pannelli (o kde Impostazioni ▶ Pannelli) o premendo Ctrl+2.

In both cases, the Browser helps you navigate in your file system and manage geodata, regardless the type of layer (raster, vector, table), or the datasource format (plain or compressed files, databases, web services).

13.1.1.1. Exploring the Interface

At the top of the Browser panel, you find some buttons that help you to:

  • addLayer Add Selected Layers: you can also add data to the map canvas by selecting Add selected layer(s) from the layer’s context menu;

  • refresh Refresh the browser tree;

  • filterMap Filter Browser to search for specific data. Enter a search word or wildcard and the browser will filter the tree to only show paths to matching DB tables, filenames or folders – other data or folders won’t be displayed. See the Browser Panel(2) example in figure_browser_panels. The comparison can be case-sensitive or not. It can also be set to:

    • Normal: show items containing the search text

    • Wildcard(s): fine tune the search using the ? and/or * characters to specify the position of the search text

    • Regular expression

  • collapseTree Racchiudi tutto collassa la struttura ad albero;

  • metadata Enable/disable properties widget: when toggled on, a new widget is added at the bottom of the panel showing, if applicable, metadata for the selected item.

The entries in the Browser panel are organised hierarchically, and there are several top level entries:

  1. Favorites where you can place shortcuts to often used locations

  2. Spatial Bookmarks where you can store often used map extents (see Segnalibri Spaziali)

  3. Project Home: for a quick access to the folder in which (most of) the data related to your project are stored. The default value is the directory where your project file resides.

  4. Home directory in the file system and the filesystem root directory.

  5. Connected local or network drives

  6. Then comes a number of container / database types and service protocols, depending on your platform and underlying libraries:

    • geoPackage GeoPackage

    • spatialite SpatiaLite

    • postgis PostGIS

    • mssql MSSQL

    • oracle Oracle

    • db2 DB2

    • wms WMS/WMTS

    • wms XYZ Tiles

    • wcs WCS

    • wfs WFS

    • ows OWS

    • ams ArcGISMapServer

    • afs ArcGISFeatureServer

    • geonode GeoNode

13.1.1.2. Interacting with the Browser items

The browser supports drag and drop within the browser, from the browser to the canvas and Layers panel, and from the Layers panel to layer containers (e.g. GeoPackage) in the browser.

Project file items inside the browser can be expanded, showing the full layer tree (including groups) contained within that project. Project items are treated the same way as any other item in the browser, so they can be dragged and dropped within the browser (for example to copy a layer item to a geopackage file) or added to the current project through drag and drop or double click.

The context menu for an element in the Browser panel is opened by right-clicking on it.

For file system directory entries, the context menu offers the following:

  • New –>

    • Directory…

    • GeoPackage…

    • ShapeFile…

  • Add as a Favorite

  • Hide from Browser

  • Fast Scan this Directory

  • Open Directory

  • Open in Terminal

  • Proprietà…

  • Directory Properties…

Favourites, can also be removed and renamed:

  • Rename favourite…

  • Remove favourite

For leaf entries that can act as layers in the project, the context menu will have supporting entries. For example, for non-database, non-service-based vector, raster and mesh data sources:

  • Delete File «<name of file>»…

  • Export Layer –> To File…

  • Add Layer to Project

  • Layer Properties

  • File Properties

In the Layer properties entry, you will find (similar to what you will find in the vector and raster layer properties once the layers have been added to the project):

  • Metadata for the layer. Metadata groups: Information from provider (if possible, Path will be a hyperlink to the source), Identification, Extent, Access, Fields (for vector layers), Bands (for raster layers), Contacts, Links (for vector layers), References (for raster layers), History.

  • A Preview panel

  • The attribute table for vector sources (in the Attributes panel).

To add a layer to the project using the Browser:

  1. Attiva Browser come descritto sopra. Viene visualizzato una lista ad albero con il tuo file system, i database e i servizi web. Potrebbe essere necessario collegare i database e i servizi web prima di poterli visualizzare (vedi le sezioni dedicate).

  2. Cerca il layer nell’elenco;

  3. Use the context menu, double-click its name, or drag-and-drop it into the map canvas. Your layer is now added to the Layers panel and can be viewed on the map canvas.

    Suggerimento

    Aprire un progetto QGIS direttamente dal browser

    Puoi anche aprire un progetto QGIS direttamente dal pannello del Browser facendo doppio clic sul suo nome o trascinandolo e rilasciandolo nell’area di disegno della mappa.

Once a file is loaded, you can zoom around it using the map navigation tools. To change the style of a layer, open the Layer Properties dialog by double-clicking on the layer name or by right-clicking on the name in the legend and choosing Properties from the context menu. See section Proprietà Simbologia for more information on setting symbology for vector layers.

Right-clicking an item in the browser tree helps you to:

  • for a file or a table, display its metadata or open it in your project. Tables can even be renamed, deleted or truncated.

  • for a folder, bookmark it into your favourites or hide it from the browser tree. Hidden folders can be managed from the Settings ▶ Options ▶ Data Sources tab.

  • manage your spatial bookmarks: bookmarks can be created, exported and imported as XML files.

  • create a connection to a database or a web service.

  • refresh, rename or delete a schema.

You can also import files into databases or copy tables from one schema/database to another with a simple drag-and-drop. There is a second browser panel available to avoid long scrolling while dragging. Just select the file and drag-and-drop from one panel to the other.

../../../_images/browser_panels.png

Fig. 13.2 Pannelli QGIS Browser affiancati

Suggerimento

Aggiungi layer a QGIS con un semplice drag-and-drop dal visualizzatore file del tuo sistema operativo

Puoi anche aggiungere i file al progetto trascinandoli dal proprio visualizzatore di file del sistema operativo in uso al Panello Layer o all’area di visualizzazione mappa.

13.1.2. Il DB Manager

The DB Manager Plugin is another tool for integrating and managing spatial database formats supported by QGIS (PostGIS, SpatiaLite, GeoPackage, Oracle Spatial, MSSQL, DB2, Virtual layers). It can be activated from the Plugins ▶ Manage and Install Plugins… menu.

Il Plugin dbManager DB Manager offre diverse funzionalità:

  • connect to databases and display their structure and contents

  • preview tables of databases

  • add layers to the map canvas, either by double-clicking or drag-and-drop.

  • add layers to a database from the QGIS Browser or from another database

  • create SQL queries and add their output to the map canvas

  • create virtual layers

More information on DB Manager capabilities is found in Plugin DB Manager.

../../../_images/db_manager.png

Fig. 13.3 Finestra di dialogo DB Manager

13.1.3. Strumenti di caricamento per specifici provider di dati

Beside the Browser Panel and the DB Manager, the main tools provided by QGIS to add layers, you’ll also find tools that are specific to data providers.

Nota

Some external plugins also provide tools to open specific format files in QGIS.

13.1.3.1. Caricare un layer da un file

To load a layer from a file:

  1. Open the layer type tab in the Data Source Manager dialog, ie click the dataSourceManager Open Data Source Manager button (or press Ctrl+L) and enable the target tab or:

    • for vector data (like GML, ESRI Shapefile, Mapinfo and DXF layers): press Ctrl+Shift+V, select the Layer ▶ Add Layer ▶ addOgrLayer Add Vector Layer menu option or click on the addOgrLayer Add Vector Layer toolbar button.

      ../../../_images/addvectorlayerdialog.png

      Fig. 13.4 Finestra di dialogo aggiungi vettore

    • for raster data (like GeoTiff, MBTiles, GRIdded Binary and DWG layers): press Ctrl+Shift+R, select the Layer ▶ Add Layer ▶ addRasterLayer Add Raster Layer menu option or click on the addRasterLayer Add Raster Layer toolbar button.

      ../../../_images/addrasterlayerdialog.png

      Fig. 13.5 Add Raster Layer Dialog

  2. Check radioButtonOn File source type

  3. Click on the Browse button

  4. Navigate the file system and load a supported data source. More than one layer can be loaded at the same time by holding down the Ctrl key and clicking on multiple items in the dialog or holding down the Shift key to select a range of items by clicking on the first and last items in the range. Only formats that have been well tested appear in the formats filter. Other formats can be loaded by selecting All files (the top item in the pull-down menu).

  5. Press Open to load the selected file into Data Source Manager dialog

  6. You can specify the encoding for vector file if desired

  7. Press Add to load the file in QGIS and display them in the map view. figure_vector_loaded shows QGIS after loading the alaska.shp file.

    ../../../_images/shapefileloaded.png

    Fig. 13.6 QGIS con il caricamento dello Shapefile Alaska

Nota

Because some formats like MapInfo (e.g., .tab) or Autocad (.dxf) allow mixing different types of geometry in a single file, loading such datasets opens a dialog to select geometries to use in order to have one geometry per layer.

The addOgrLayer Add Vector Layer and addRasterLayer Add Raster Layer tabs allow loading of layers from source types other than File:

  • You can load specific vector formats like ArcInfo Binary Coverage, UK. National Transfer Format, as well as the raw TIGER format of the US Census Bureau or OpenfileGDB. To do that, you select radioButtonOn Directory as Source type. In this case, a directory can be selected in the dialog after pressing Browse.

  • With the radioButtonOn Database source type you can select an existing database connection or create one to the selected database type. Some possible database types are ODBC, Esri Personal Geodatabase, MSSQL as well as PostgreSQL or MySQL .

    Pressing the New button opens the Create a New OGR Database Connection dialog whose parameters are among the ones you can find in Creazione della connessione. Pressing Open lets you select from the available tables, for example of PostGIS enabled databases.

  • The radioButtonOn Protocol: HTTP(S), cloud, etc. source type opens data stored locally or on the network, either publicly accessible, or in private buckets of commercial cloud storage services. Supported protocol types are:

    • HTTP/HTTPS/FTP, with a URI and, if required, an authentication.

    • Cloud storage such as AWS S3, Google Cloud Storage, Microsoft Azure Blob, Alibaba OSS Cloud, Open Stack Swift Storage. You need to fill in the Bucket or container and the Object key.

    • service supporting OGC WFS 3 (still experimental), using GeoJSON or GEOJSON - Newline Delimited format or based on CouchDB database. A URI is required, with optional authentication.

13.1.3.2. Loading a mesh layer

A mesh is an unstructured grid usually with temporal and other components. The spatial component contains a collection of vertices, edges and faces in 2D or 3D space. More information on mesh layers at Lavorare con i dati Mesh.

To add a mesh layer to QGIS:

  1. Open the Data Source Manager dialog, either by selecting it from the Layer ▶ menu or clicking the dataSourceManager Open Data Source Manager button.

  2. Enable the addMeshLayer Mesh tab on the left panel

  3. Press the Browse button to select the file. Various formats are supported.

  4. Select the layer and press Add. The layer will be added using the native mesh rendering.

../../../_images/mesh_datasource_manager.png

Fig. 13.7 Mesh tab in Data Source Manager

13.1.3.3. Importare file di testo delimitato

Delimited text files (e.g. .txt, .csv, .dat, .wkt) can be loaded using the tools described above. This way, they will show up as simple tables. Sometimes, delimited text files can contain coordinates / geometries that you could want to visualize. This is what addDelimitedTextLayerAdd Delimited Text Layer is designed for.

  1. Click the dataSourceManager Open Data Source Manager icon to open the Data Source Manager dialog

  2. Enable the addDelimitedTextLayer Delimited Text tab

  3. Select the delimited text file to import (e.g., qgis_sample_data/csv/elevp.csv) by clicking on the Browse button.

  4. In the Layer name field, provide the name to use for the layer in the project (e.g. Elevation).

  5. Configure the settings to meet your dataset and needs, as explained below.

../../../_images/delimited_text_dialog.png

Fig. 13.8 Finestra di dialogo Testo Delimitato

13.1.3.3.1. Formattazione file

Once the file is selected, QGIS attempts to parse the file with the most recently used delimiter, identifying fields and rows. To enable QGIS to correctly parse the file, it is important to select the right delimiter. You can specify a delimiter by choosing between:

  • radioButtonOnCSV (comma separated values) to use the comma character.

  • radioButtonOffRegular expression delimiter and enter text into the Expression field. For example, to change the delimiter to tab, use \t (this is used in regular expressions for the tab character).

  • radioButtonOffCustom delimiters, choosing among some predefined delimiters like comma, space, tab, semicolon, … .

13.1.3.3.2. Record e campi

Some other convenient options can be used for data recognition:

  • Number of header lines to discard: convenient when you want to avoid the first lines in the file in the import, either because those are blank lines or with another formatting.

  • checkboxFirst record has field names: values in the first line are used as field names, otherwise QGIS uses the field names field_1, field_2

  • checkboxDetect field types: riconosce automaticamente il tipo di campo. Se deselezionato, tutti gli attributi sono trattati come campi di testo.

  • checkboxDecimal separator is comma: you can force decimal separator to be a comma.

  • checkboxRifinisci i campi: ti permette di troncare gli spazi iniziale e finali dai campi.

  • checkboxScarta i campi vuoti.

Mentre imposti le proprietà di interpretazione, un’anteprima dei dati campione viene aggiornata nella parte inferiore della finestra di dialogo.

13.1.3.3.3. Definizione geometria

Una volta che il file è stato interpretato, imposta Definizione della Geometria a:

  • radioButtonOnPoint coordinates and provide the X field, Y field, Z field (for 3-dimensional data) and M field (for the measurement dimension) if the layer is of point geometry type and contains such fields. If the coordinates are defined as degrees/minutes/seconds, activate the checkboxDMS coordinates checkbox. Provide the appropriate Geometry CRS using the setProjection Select CRS widget.

  • radioButtonOnWell known text (WKT) option if the spatial information is represented as WKT: select the Geometry field containing the WKT geometry and choose the approriate Geometry field or let QGIS auto-detect it. Provide the appropriate Geometry CRS using the setProjection Select CRS widget.

  • Se il file contiene dati non spaziali, attiva radioButtonOn Nessuna geometria (solo tabella attributi) e verrà caricato come una normale tabella.

13.1.3.3.4. Impostazioni layer

Puoi anche attivare:

  • checkboxUse spatial index to improve the performance of displaying and spatially selecting features.

  • checkboxUse subset index to improve performance of subset filters (when defined in the layer properties).

  • checkboxControlla file per controllare le modifiche al file da parte di altre applicazioni mentre QGIS è in esecuzione.

At the end, click Add to add the layer to the map. In our example, a point layer named Elevation is added to the project and behaves like any other map layer in QGIS. This layer is the result of a query on the .csv source file (hence, linked to it) and would require to be saved in order to get a spatial layer on disk.

13.1.3.4. Importare file DXF o DWG

DXF and DWG files can be added to QGIS by simple drag-and-drop from the Browser Panel. You will be prompted to select the sublayers you would like to add to the project. Layers are added with random style properties.

Nota

For DXF files containing several geometry types (point, line and/or polygon), the name of the layers will be generated as <filename.dxf> entities <geometry type>.

Per mantenere la struttura del file dxf/dwg e la sua simbologia in QGIS, puoi utilizzare lo strumento dedicato Progetto ▶ Importa/Esporta ▶ Importa layer da DWG/DXF…. che ti permette di:

  1. importare oggetti dal file DWG/DXF in un database di GeoPackage.

  2. add imported elements to the project.

In the DWG/DXF Import dialog, to import the drawing file contents:

  1. Inserisci la posizione del Target package, cioè il nuovo file GeoPackage che memorizzerà i dati. Se viene fornito un file esistente, allora verrà sovrascritto.

  2. Specifica il sistema di riferimento delle coordinate dei dati del file DWG/DXF.

  3. Seleziona checkbox Espandi riferimenti blocco per importare i blocchi nel file di disegno come oggetti normali.

  4. Scegli checkbox Usa curve per trasformare i layer importati in un tipo di geometria curva.

  5. Use the Import button to select the DWG/DXF file to use (one per geopackage). The GeoPackage database will be automatically populated with the drawing file content. Depending on the size of the file, this can take some time.

After the .dwg or .dxf data has been imported into the GeoPackage database, the frame in the lower half of the dialog is populated with the list of layers from the imported file. There you can select which layers to add to the QGIS project:

  1. Nella parte superiore, imposta un Nome gruppo per raggruppare i file di disegno nel progetto.

  2. Check layers to show: Each selected layer is added to an ad hoc group which contains vector layers for the point, line, label and area features of the drawing layer. The style of the layers will resemble the look they originally had in *CAD.

  3. Choose if the layer should be visible at opening.

  4. Checking the checkbox Merge layers option places all layers in a single group.

  5. Premi OK per aprire i layer in QGIS.

../../../_images/dwg_dxf_import_dialog.png

Fig. 13.9 Finestra di dialogo per importazione file DWG/DXF

13.1.3.5. Importare vettori OpenStreetMap

The OpenStreetMap project is popular because in many countries no free geodata such as digital road maps are available. The objective of the OSM project is to create a free editable map of the world from GPS data, aerial photography and local knowledge. To support this objective, QGIS provides support for OSM data.

Using the Browser Panel, you can load an .osm file to the map canvas, in which case you’ll get a dialog to select sublayers based on the geometry type. The loaded layers will contain all the data of that geometry type in the .osm file, and keep the osm file data structure.

13.1.3.6. SpatiaLite Layers

addSpatiaLiteLayer La prima volta che carichi i dati da un database di SpatiaLite, inizia da:

  • clicking on the addSpatiaLiteLayer Add SpatiaLite Layer toolbar button

  • selecting the addSpatiaLiteLayer Add SpatiaLite Layer… option from the Layer ▶ Add Layer menu

  • or by typing Ctrl+Shift+L

This will bring up a window that will allow you either to connect to a SpatiaLite database already known to QGIS (which you choose from the drop-down menu) or to define a new connection to a new database. To define a new connection, click on New and use the file browser to point to your SpatiaLite database, which is a file with a .sqlite extension.

QGIS supporta anche viste modificabili in SpatiaLite.

13.1.3.7. GPS

Loading GPS data in QGIS can be done using the core plugin GPS Tools. Instructions are found in section Plugin GPS.

13.1.3.8. GRASS

Working with GRASS vector data is described in section Integrazione con GRASS GIS.

13.1.4. Formati QGIS personalizzati

QGIS proposes two custom formats:

  • Temporary Scratch Layer: a memory layer that is bound to the project (see Creare un nuovo vettore temporaneo for more information)

  • Layers virtuali: un layer risultante da una query su altro(i) layer(s) (per ulteriori informazioni, vedi Layers virtuali)

13.1.5. QLR - QGIS Layer Definition File

Le definizioni del layer possono essere salvate come Layer Definition File (QLR - .qlr) usando :menuselection:` Esporta -> Salva come file di definizione layer…` nel menu contestuale del layer.

Il formato QLR consente di condividere layer QGIS «completi» con altri utenti QGIS. I file QLR contengono collegamenti alle fonti dati e tutte le informazioni di stile QGIS necessarie per lo stile del layer.

I file QLR sono mostrati nel Pannello Browser e possono essere usati per aggiungere layer (con i relativi stili salvati) al Pannello Layer. Puoi anche trascinare e rilasciare i file QLR dal file manager di sistema nell’area della mappa.

13.1.6. Connessione a web services

With QGIS you can get access to different types of OGC web services (WM(T)S, WFS(-T), WCS, CSW, …). Thanks to QGIS Server, you can also publish such services. Chapter Lavorare con i dati OGC contains descriptions of these capabilities.

13.1.6.1. Using XYZ Tile services

XYZ Tile services can be found in the XYZ Tiles top level entry in the Browser. By default, the OpenStreetMap XYZ Tile service is configured. You can add other services that use the XYZ Tile protocol by choosing New Connection in the XYZ Tiles context menu (right-click to open). figure_xyz_tiles_openstreetmap shows the dialog with the OpenStreetMap XYZ Tile service configuration.

../../../_images/xyz_tiles_dialog_osm.png

Fig. 13.12 XYZ Tiles - OpenStreetMap configuration

Configurations can be saved (Save Connections) to XML and loaded (Load Connections) through the context menu. Authentication configuration is supported. The XML file for OpenStreetMap looks like this:

<!DOCTYPE connections>
<qgsXYZTilesConnections version="1.0">
  <xyztiles url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
   zmin="0" zmax="19" password="" name="OpenStreetMap" username=""
   authcfg="" referer=""/>
</qgsXYZTilesConnections>

Once a connection to a XYZ tile service is set, right-click over the entry to:

  • Edit… the XYZ connection settings

  • Delete the connection

  • Export layer… ▶ To File, saving it as a raster

  • Add layer to project: a double-click also adds the layer

  • View the Layer Properties… and get access to metadata and a preview of the data provided by the service. More settings are available when the layer has been loaded into the project.

Examples of XYZ Tile services:

  • OpenStreetMap Monochrome: URL: http://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png, Min. Zoom Level: 0, Max. Zoom Level: 19.

  • Google Maps: URL: https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}, Min. Zoom Level: 0, Max. Zoom Level: 19.

  • Open Weather Map Temperature: URL: http://tile.openweathermap.org/map/temp_new/{z}/{x}/{y}.png?appid={api_key} Min. Zoom Level: 0, Max. Zoom Level: 19.

13.1.7. Handling broken file paths

When the path to a data source is wrong, QGIS opens the Handle Unavailable Layers dialog. You can double-click in the Datasource field or click Browse to fix the path. It is possible to continue working with your project with the broken path by clicking Keep Unavailable Layers. Your layer is then displayed in the Layers panel, but without any data until you fix the path using the indicatorBadLayer Unavailable layer! icon next to it in the Layers panel, or Change Data Source… in the layer contextual menu. Another possibility is to deleteSelected Remove Unavailable Layers. As the last step, click Apply changes.

When a layer path has been fixed, QGIS scans through all other broken paths and tries to auto-fix those that have the same broken file path.