|
1756 | 1756 | "```" |
1757 | 1757 | ] |
1758 | 1758 | }, |
| 1759 | + { |
| 1760 | + "cell_type": "markdown", |
| 1761 | + "metadata": {}, |
| 1762 | + "source": [ |
| 1763 | + "## Python in QGIS \n", |
| 1764 | + "\n", |
| 1765 | + "QGIS uses Python much like standalone geospatial libraries, but instead of opening files manually, you usually\n", |
| 1766 | + "interact with layers already loaded in the QGIS project. Geometry operations resemble those in Shapely, though they\n", |
| 1767 | + "use the `QgsGeometry` API rather than Shapely's methods. Unlike standalone scripts, the QGIS Python console provides\n", |
| 1768 | + "direct access to the current map, layers, and interface through objects such as `iface` and `QgsProject.instance()`.\n", |
| 1769 | + "Many workflows combine both worlds, using PyQGIS for project interaction and Shapely, RasterIO, NumPy, or Pandas for\n", |
| 1770 | + "specialized analysis.\n", |
| 1771 | + "\n", |
| 1772 | + "If you have QGIS installed, try below scripts in the `Python Console` (in the `Plugins` menu).\n", |
| 1773 | + "\n", |
| 1774 | + "```\n", |
| 1775 | + "layer = QgsProject.instance().mapLayersByName('roads')[0]\n", |
| 1776 | + "print(layer.name())\n", |
| 1777 | + "for feature in layer.getFeatures():\n", |
| 1778 | + " print(feature.id())\n", |
| 1779 | + " print(feature.get('name')) # attribute field\n", |
| 1780 | + " print(feature.geometry().asWkt()) # geometry\n", |
| 1781 | + "```\n" |
| 1782 | + ] |
| 1783 | + }, |
1759 | 1784 | { |
1760 | 1785 | "cell_type": "markdown", |
1761 | 1786 | "metadata": {}, |
|
0 commit comments