-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_script.py
More file actions
66 lines (52 loc) · 2.44 KB
/
example_script.py
File metadata and controls
66 lines (52 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
"""
Package: GenSimPlot
File: example_script.py
Version: 2.2
Author: Milan Koren
Year: 2024
URL: https://github.com/milan-koren/GenSimPlot
License: EUPL v1.2 (European Union Public License), https://eupl.eu/
GenSimPlot Scripting Example
This script demonstrates the use of GenSimPlot to automate the generation of spatially optimized simulation plots,
creation of point grids within those plots, and extraction of raster values for environmental variables.
Example Steps:
1. Use PlotGenerator to create optimized plots from the source polygon shapefile.
2. Generate a grid of points within each simulation plot.
3. Extract raster data for each point, compute plot-level statistics, and store the results.
4. Extract additional raster values (e.g., slope) at the centroid of each plot.
The script can be executed in the QGIS Python console or in a script editor configured for QGIS.
Requirements:
- GenSimPlot plugin and libraries
- An input shapefile with polygon features (e.g., forest_stands.shp)
- One or more raster files for environmental data (e.g., a DEM and slope raster)
"""
from GenSimPlotLib import PlotGenerator, PointsGenerator, SimulationPlotVariables
from GenSimPlotUtilities import GProgressDialog
#Initialize the progress dialog
progressDlg = GProgressDialog()
progressDlg.show()
#Define input parameters
workingFolder = "c:\\data\\"
inputShp = workingFolder + "forest_stands.shp"
polygonID = "id"
plotsShp = workingFolder + "plots.shp"
pointsShp = workingFolder + "points.shp"
nPoints = 10
clipPoints = True
demRaster = workingFolder + "dem\\dem"
slopeRaster = workingFolder + "dem\\slope"
#Generate optimized simulation plots
plotGen = PlotGenerator()
plotGen.generateBestPlots(inputShp, polygonID, plotsShp, progressDlg)
#Generate a grid of points within the plots
pointsGen = SimulationPlotVariables()
pointsGen.generatePoints(plotsShp, polygonID, pointsShp, nPoints, clipPoints, progressDlg)
#Extract raster values for each point within plots and calculate plot-level statistics
rasterStats = SimulationPlotVariables()
rasterStats.valueFromPoints(plotsShp, polygonID, pointsShp, "elev", demRaster, progressDlg)
#Extract raster values for each plot centroid
rasterCentroid = SimulationPlotVariables()
rasterCentroid.valueFromCentroid(plotsShp, "slope", slopeRaster, progressDlg)
#Close the progress dialog
progressDlg.close()