GenSimPlot is a QGIS plugin designed and developed for generating spatially optimized plots used in the simulation and analysis of geographic processes. Plugin enable to create squared, circular, rectangular, and eliptical plots maximazing overlap with the source polygons, enhancing the accuracy and representativeness of simulations.
By automating plot generation, point grid creation, and raster data extraction, GenSimPlot enhances spatial analysis workflows within QGIS, making it a versatile tool for both research and applied geographic studies.
GenSimPlot is designed to support a wide range of spatial analysis and simulation tasks, including:
GenSimPlot is developed as a QGIS plugin and requires QGIS version 3.0 or higher to run. The plugin is written in Python and uses the PyQt5 library for the user interface. The plugin is compatible with Windows, macOS, and Linux operating systems.
GenSimPlot can be installed from the QGIS Plugin Repository or by downloading the source code from the GitHub repository.
The plugin will be available in the QGIS Vector menu after installation.
The plugin is licensed under the EUPL v1.2 (European Union Public License).
The "Generate Simulation Plots" dialog provides an interface for creating simulation plots over a selected set of polygons from an input shapefile.
This tool supports generating various plot shapes — such as squares, circles, rectangles, and ellipses — with configurable positioning and placement
options to align each plot with the underlying geometry of the polygon.
This dialog enables flexible plot positioning based on attributes like the bounding box, centroid, and mean coordinates of each polygon.
Additionally, random transformations such as translations, rotations, and resizing can be applied to maximize spatial overlap with source polygons,
improving representativeness for spatial analyses.
Parameters:
Example of generated square simulation plots with optimal spatial placement for maximal overlap with source polygons:
Example of generated simulation plots optimized using the 'best' option:
The "Generate Point Grids for Simulation Plots" dialog allows users to create a regular grid of points over the bounding rectangle of each simulation plot in a selected shapefile.
The grid can be customized in density and alignment, with an option to clip points to fit precisely within the plot boundaries.
Users can select an input shapefile containing simulation plots, specify the number of points along the shorter side of the bounding rectangle to control grid density,
and define an output shapefile to store the generated points.
The grid aligns with each plot’s transformation, ensuring accurate representation within simulation plot geometries.
Parameters:
Example of a regularly spaced point grid generated within square simulation plots:
Example of a point grid generated within simulation plots optimized using the 'best' option:
The "Raster Value Statistics by Plot Points" dialog enables users to calculate summary statistics of raster values for multiple points within each simulation plot.
Users can specify an input shapefile containing simulation plots, a shapefile with points positioned inside each plot, and a raster file representing an environmental variable.
After setup, the dialog extracts raster values at each point within the plots and calculates summary statistics (minimum, maximum, and mean) for each plot.
These statistics are then stored in the simulation plot attribute table as new fields.
Parameters:
<prefix>_min
, <prefix>_max
, and <prefix>_mean
.
The "Extract Values By Centroid" dialog allows users to extract raster values at the centroids of simulation plots stored in an input shapefile.
Users can specify both an input simulation plot shapefile and a raster file, and designate an output field where the extracted raster values will be saved in the simulation plot attribute table.
This dialog simplifies the assignment of spatially relevant raster data to simulation plots, enabling efficient and accurate data integration for analysis.
Parameters:
The GenSimPlot library provides classes and functions for automating the generation of simulation plots, creation of point grids, and extraction of raster values.
These tools can be executed from the QGIS Python console or integrated into custom Python workflows for streamlined spatial analysis.
Example usage of GenSimPlotLib
classes:
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()
The GenSimPlot library provides a configurable set of hyperparameters that govern the optimization of simulation plot generation. These parameters can be adjusted to improve the spatial alignment and representativeness of the generated plots:
Hyperparameter settings can be saved to a configuration file named gensimplot.cnf, which is formatted in JSON.
These parameters can be manually adjusted within the configuration file, providing users with a convenient way to customize the simulation plot generation process.
The hyperparameters are automatically loaded during the initialization of the PlotGenerator
class.
The HTuning
class implements methods for managing the hyperparameter tuning process.
The example below demonstrates how to use the HTuning
class in GenSimPlot
to automate the hyperparameters tuning process. The procedure involves randomly selecting hyperparameter values within specified ranges
and evaluating the quality of the resulting simulation plots based on overlap statistics with the input polygons.
This process is repeated for a user-defined number of iterations. The resulting metrics, including overlap percentages and execution times,
are appended to a designated CSV file for subsequent analysis.
from htuning import HTuning
from GenSimPlotUtilities import GProgressDialog
# Initialize the progress dialog
progressDlg = GProgressDialog()
progressDlg.show()
ht = HTuning()
ht.run(
workingFolder = "C:\\data\\",
polygonShpFN = "polygons.shp",
idFieldName = "id",
outputPlotFNBase = "splots",
outputStatisticsFN = "statistics_best.csv",
progressDlg = progressDlg,
minIterations = 50,
maxIterations = 1000,
minTranslatePerc = 0.01,
maxTranslatePerc = 0.25,
minAngleLimit = 1.0,
maxAngleLimit = 45.0,
minResizePerc = 0.01,
maxResizePerc = 0.25,
position = "bounding box",
placement = "optimized",
shape = "best",
numberOfTests = 25,
)
# Close the progress dialog
progressDlg.close()