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

PR Validation codecov

QGIS

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

Plugin Demo

Table of Contents

Installation

  1. Open QGIS
  2. Go to PluginsManage and Install Plugins
  3. Search for “Polygons Parallel to Line”
  4. Click Install Plugin

Installation Guide

Method 2: Manual Installation

  1. Download the plugin from the QGIS Plugins Repository
  2. Extract to your QGIS plugins directory
  3. Restart QGIS and enable the plugin

Quick Start

  1. Access the Plugin: Go to ProcessingToolboxPolygons Parallel to Line
  2. Select Input Layers: Choose your polygon and line layers
  3. Configure Parameters: Set distance and angle thresholds as needed
  4. Run: Execute the algorithm to generate aligned polygons

How to Access

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:

  1. Distance Check: Calculates distance from polygon centroid to nearest line
    • If Max distance from line > 0 and distance exceeds threshold → skip polygon
  2. Vertex Analysis: Identifies the closest polygon vertex to the nearest line

  3. Segment Evaluation: Analyzes two adjacent segments of the closest vertex

  4. Angle Calculation: Computes rotation angles between line segment and polygon segments

  5. 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
  6. Output Generation: Creates rotated geometry with _rotated field indicator

Default Usage

Key Notes

Rotated Field

Configuration

Max Distance from Line

When set to 0.0, all polygons are processed regardless of distance.

Distance Configuration

Max Angle for Rotation

Angle Configuration

Rotate by Longest Segment

Longest Segment Option

Skip Multipolygons

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

Compatibility

Best Practices

⚠️ Important: Validate and fix geometry errors before running the plugin for optimal results.

  1. Prepare Data: Ensure polygon and line layers are in the same CRS
  2. Fix Geometries: Use Processing ToolboxVector geometryFix Geometries
  3. Test Parameters: Start with default settings on a small dataset
  4. Batch Process: Apply to full dataset with optimized parameters

Performance Tips

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