Skip to main content

A Python library implementing a method for splitting a polygon into regions

Project description

polysplit

A lightweight library for splitting polygons into regions based on proximity of points.
License: MIT issues codecov Build Status

Overview

Map quantization is the procedure of dividing a continuous map into a number of discrete regions. The simplest approach that has been used for hundreds of years is to overlap the map with a square grid. However, this approach ignores the geographical features of the map, making it suboptimal for certain applications. With this project, I would like to propose a novel algorithm that organically divides any given map into regions based on the relative travel time between different areas.

In its simple form, the proposed algorithm could be applied to a map (a polygon) with intraversible obstacles (holes). It works in 2 stages. In the first stage, the map is overlayed with a fine grid of $N$ points. Then, we calculate the shortest path (around the obstacles) betweeen every pair of points and construct the $N \times N$ distance matrix. In the second stage, we apply the k-medoids algorithm to the set of points, using the matrix from stage I as a distance function, and retrieve a set of $M$ centers. Finally, we construct a Voronoi graph around the centers, creating the regions.

Installation

pip install polysplit

Sample usage

import polysplit
from shapely.geometry import Polygon

# Create a polygon with a hole
outer_coords = [(0, 0), (0, 1), (1, 1), (1, 0)]
hole_coords = [(0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4)]
polygon = Polygon(outer_coords, [hole_coords])

# Split the polygon
regions = polysplit.polysplit_main(polygon, k=5, num_points=100, plot=True)
print(regions)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polysplit-0.1.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

polysplit-0.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file polysplit-0.1.1.tar.gz.

File metadata

  • Download URL: polysplit-0.1.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for polysplit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 68ded0dd72589d9c1762e4ada3b7cd27e9551bc7ad97c27dd469c5f9740b5644
MD5 f6be156f0bf8ca2191e2dd61bc310eda
BLAKE2b-256 54ab41e42fd0820c824cce2acb318a63e2e55c90f31e7b48ec18da5c26b8ef90

See more details on using hashes here.

File details

Details for the file polysplit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: polysplit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for polysplit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bfdeae58882598ae32a33444b55d03235a31f8b7419f274bb4a27cddb5d913f8
MD5 b912cbb8b26e58892786ddb49e13f702
BLAKE2b-256 e8b92692056cf5faaf17f3dffc79985b6fd62b75c8907def1bee91af7773acdd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page