Skip to content

Commit 2902fdf

Browse files
authored
add section on python in qgis (#244)
1 parent 44b4bd1 commit 2902fdf

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

workshop/jupyter/content/notebooks/04-vector-data.ipynb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,31 @@
17561756
"```"
17571757
]
17581758
},
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+
},
17591784
{
17601785
"cell_type": "markdown",
17611786
"metadata": {},

0 commit comments

Comments
 (0)