This Python module is designed for use in QGIS as a custom processing algorithm for generating hexagonal and square grids with aggregation of building data.
- Automatically fetches city boundaries, buildings, and road networks using OSMnx.
- Generates H3 hexagonal grids or regular square grids over the city area.
- Aggregates values from a specified attribute column (e.g.,
r_floors) per grid cell. - Computes normalized metrics (e.g., buildings per km², building density index).
- Applies graduated styling to output layers for effective visualization.
- Place the provided Python file into your QGIS Python scripts directory or load it manually.
- Open QGIS.
- Ensure the following Python libraries are installed in your environment:
osmnxgeopandasshapelynumpyh3
- Run the
register_algorithm()function or restart QGIS to auto-load the tool. - Open the Processing Toolbox and locate "Create Grid" under the Custom Tools section.
| Parameter | Description |
|---|---|
City Name |
Name of the city for fetching OSM data |
Grid Type |
Select between Hexagonal, Square, or Both |
Resolution |
H3 resolution (integer from 1 to 15) |
Cell Size |
Cell size in meters for square grids (optional, calculated automatically) |
Buildings Layer |
(Optional) Custom building layer to override OSM data |
Aggregation Column |
Column name for aggregation (e.g., r_floors) |
- Hexagonal Grid Output: H3-based grid layer with aggregated values.
- Square Grid Output: Regular square mesh with the same computed attributes.
Each output contains the normalized_count field, representing:
- Object count (if no aggregation column is specified),
- Average value of the specified attribute (if provided),
- Building density index (when using
r_floors).
- The algorithm loads urban geodata using OSMnx.
- It creates the grid over the city's bounding box.
- Buildings are spatially assigned to grid cells using their centroids.
- Aggregated statistics and density metrics are computed.
- Results are visualized in QGIS with automatic styling.
This plugin provides a custom QGIS Processing algorithm for generating urban blocks based on roads, buildings, waterways, natural objects and railroads infrastructure.
- Uses road geometry to define urban blocks via polygonization of road networks.
- Integrates railways and waterways into block segmentation.
- Automatically removes dead-end street segments and internal artifacts.
- Performs area-based filtering of blocks (e.g., excludes blocks without buildings).
- Aggregates building data by block (e.g., counts, average floors, FAR).
- Outputs styled block polygons.
- Copy the Python file into your QGIS Python script folder.
- Launch QGIS.
- Ensure the following Python libraries are installed:
geopandasshapelypandasosmnxnetworkx
- Call
register_algorithm()or restart QGIS to auto-load the tool. - In the Processing Toolbox, find the algorithm under Custom Tools as "Create Blocks".
| Parameter | Description |
|---|---|
Boundary Layer |
Polygon layer defining city or district boundaries |
Roads Layer |
Line layer containing road geometry |
Railroads Layer |
Line layer with rail infrastructure |
Buildings Layer |
Polygon layer with building footprints |
Waterway Layer |
Line layer of rivers, canals, etc. |
Aggregation Column |
Optional: building attribute to aggregate (e.g., r_floors) |
Target CRS |
Coordinate system for processing geometry (default: EPSG:4326) |
- A polygon layer representing urban blocks.
- Each block includes calculated values:
normalized_count: buildings per square kilometer or normalized attributefar: Floor Area Ratio (ifr_floorsprovided)
- Roads and rails are merged and split at intersections.
- Dead-end road segments are extended to improve connectivity.
- Polygons are formed by polygonizing road networks.
- Polygons without buildings or too large/small are removed.
- Waterways are buffered and subtracted from block geometry.
- Metrics are calculated per block (building count, average, FAR).
- Result layer is styled with graduated color ramp.