Polygons Parallel to Line
QGIS Python Plugin by Andrii Liekariev — This plugin rotates polygons so that they become parallel to their nearest lines
Project maintained by Elfpkck
Hosted on GitHub Pages — Theme by mattgraham


Polygons Parallel to Line — QGIS Python Plugin
A QGIS processing plugin that automatically rotates polygons to align them parallel with their nearest lines based on configurable parameters.
Polygons Parallel to Line Plugin on QGIS Plugins Web Portal

Table of Contents
Installation
Method 1: QGIS Plugin Manager (Recommended)
- Open QGIS
- Go to Plugins → Manage and Install Plugins
- Search for “Polygons Parallel to Line”
- Click Install Plugin

Method 2: Manual Installation
- Download the plugin from the QGIS Plugins Repository
- Extract to your QGIS plugins directory
- Restart QGIS and enable the plugin
Quick Start
- Access the Plugin: Go to Processing → Toolbox → Polygons Parallel to Line
- Select Input Layers: Choose your polygon and line layers
- Configure Parameters: Set distance and angle thresholds as needed
- Run: Execute the algorithm to generate aligned polygons

Features
✅ Automatic Polygon Rotation: Intelligently rotates polygons to align with nearest lines
✅ Distance-based Filtering: Optional maximum distance constraint
✅ Angle Threshold Control: Configurable rotation angle limits
✅ Multigeometry Support: Handles both simple and complex geometries
✅ Rotation Tracking: Adds _rotated
field to track which polygons were modified
✅ Geometry Validation: Built-in checks for geometry integrity
Algorithm
The plugin processes each polygon using the following steps:
- Distance Check: Calculates distance from polygon centroid to nearest line
- If
Max distance from line
> 0 and distance exceeds threshold → skip polygon
-
Vertex Analysis: Identifies the closest polygon vertex to the nearest line
-
Segment Evaluation: Analyzes two adjacent segments of the closest vertex
-
Angle Calculation: Computes rotation angles between line segment and polygon segments
- Rotation Decision:
- If both angles ≤
Max angle
:
- Longest segment mode: Rotates based on longest segment (or smallest angle if equal)
- Default mode: Rotates based on smallest angle
- If only one angle ≤
Max angle
: Rotates based on that segment
- Output Generation: Creates rotated geometry with
_rotated
field indicator

Key Notes
- Rotation center is the polygon centroid
- Interior rings and duplicate vertices are ignored
- Multipolygons use the same principles as simple polygons
- The
_rotated
field indicates transformation status (boolean)

Configuration
Max Distance from Line
- Type: Float (optional)
- Range: ≥ 0.0
- Default: 0.0 (processes all polygons)
- Unit: Line layer CRS units
When set to 0.0, all polygons are processed regardless of distance.

Max Angle for Rotation
- Type: Float (optional)
- Range: 0.0 - 89.9 degrees
- Default: 89.9
- Purpose: Limits maximum rotation angle

Rotate by Longest Segment
- Type: Boolean
- Default: False
- Behavior: When both segments have valid angles (≤ Max angle), prioritizes the longest segment

Skip Multipolygons
- Type: Boolean
- Default: False
- Purpose: Excludes multipolygon geometries from processing
Usage Examples
Basic Usage
Input: Building polygons + Road centerlines
Output: Buildings aligned parallel to nearest roads
Advanced Filtering
Max Distance: 50.0 (meters)
Max Angle: 45.0 (degrees)
Result: Only buildings within 50m of roads, with rotation ≤ 45°
Requirements
- QGIS: 3.0 or higher
- Dependencies: Standard QGIS processing framework
Compatibility
- ✅ Windows
- ✅ macOS
- ✅ Linux
- ✅ All QGIS LTR versions
Best Practices
⚠️ Important: Validate and fix geometry errors before running the plugin for optimal results.
Recommended Workflow
- Prepare Data: Ensure polygon and line layers are in the same CRS
- Fix Geometries: Use Processing Toolbox → Vector geometry → Fix Geometries
- Test Parameters: Start with default settings on a small dataset
- Batch Process: Apply to full dataset with optimized parameters
- Use spatial indexes for large datasets
- Consider processing in smaller batches for very large datasets
- Test different parameter combinations on representative samples
Development
See DEVELOPMENT.md for detailed development setup and contribution guidelines.
License
Copyright (C) 2016-2025 by Andrii Liekariev
This project is licensed under the GNU General Public License v2.0.
Support
Made with ❤️ for the QGIS community