Accessing layer metadata
Layer metadata is, by definition, data about the layer. Metadata includes information such as the extents of the layer, the coordinate reference system (CRS), the number of features, the data source, and much more. Metadata is an important tool for GIS analysts to understand a dataset. QGIS also uses metadata to properly configure the map, run queries, and perform other management functions. Metadata such as the extents and number of features can be extracted automatically from the data. Other metadata such as the CRS, source, and production methods must be added by the person or software that generates the data. PyQGIS has a method to return layer metadata as an HTML document. To programmatically extract a single metadata attribute, you must parse the HTML. In this recipe, you'll extract the layer capabilities from a layer, which tell you if the layer can be edited within PyQGIS. Although there are dozens of ways to parse HTML in Python, you will use some simple...