Skip to main content

fastpgv

fastpgv is a lightweight Python wrapper for fast density computation for Polygon-to-Grid Visualization (PGV).

This package provides an efficient way to compute density results through a simple Python interface. Compute a density value for every pixel from weighted polygons using the C++17 SLED (Sweep-Line Edge-Difference Aggregation) algorithm.

Features

  • One Python interface: fastpgv.run(weighted_polygons, resolution).
  • Weighted polygons with explicit vertex coordinates.
  • The polygons should be non-overlapping.
  • C++ computation backend with the Python interface.

Installation

From the fastpgv/ source directory:

python -m pip install .

After version 0.1.0 is successfully published to production PyPI:

python -m pip install fastpgv==0.1.0

Publication is pending. The prepared wheel is for CPython 3.12 on macOS 11+ Apple Silicon (arm64). Other environments need to build the source distribution with a C++17 compiler. Cross-platform wheels are not included in this release.

Requirements

  • Python 3.10 or newer.
  • NumPy, installed automatically by pip.
  • A C++17 compiler for source builds. pip installs the Python build dependencies.

Java, DuckDB, APRIL, Boost, and the original benchmark repository are not required.

Quick Example

import fastpgv

# Polygons contain ordered vertex coordinates, not just identifiers.
polygon_a = {
    "type": "Polygon",
    "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]],
}
polygon_b = {
    "type": "Polygon",
    "coordinates": [[[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]],
}

density = fastpgv.run(
    [(polygon_a, 2.0), (polygon_b, 3.0)],
    resolution=(2, 1),
)
print(density)
# [[2. 3.]]

Inputs and Output

Both arguments are required:

Argument Meaning
weighted_polygons Nonempty iterable of (geometry, weight) pairs
resolution Positive integer (X, Y): columns and rows

Geometry must contain ordered vertices as a GeoJSON Polygon or MultiPolygon dictionary, or expose __geo_interface__ (for example, a Shapely polygon). Consecutive vertices define edges automatically; open rings are closed internally. No separate edge input is required or accepted. The first ring is the exterior; additional rings are holes. MultiPolygon components share one weight.

Weights must be explicit finite numbers. Negative and zero weights are supported. The supported use case is non-overlapping polygonal inputs: interiors must not overlap, but shared edges and vertices are allowed. Overlaps are not automatically checked; validate this requirement before calling run. The grid covers the combined minimum bounding rectangle of all supplied geometries, including zero-weight ones.

run returns a numpy.ndarray directly, with dtype float64 and shape (Y, X). density[v, u] is the value of the pixel in row v and column u. Row zero is the top row at y_max; columns run from x_min to x_max.

The function returns data directly; it does not write files or render a visualization.

Notes

  • Each pixel value is the sum of weight * polygon_pixel_intersection_area: weighted area, not area-normalized density.
  • Coordinates are planar, with no CRS transformation or geodesic calculation. Project geographic coordinates first when metric areas are required.
  • Supply valid polygon topology. Ring orientation is corrected, but invalid holes and self-intersections are not repaired. Empty input is rejected.
  • Numerical tests use absolute tolerance 1e-9 or relative tolerance 1e-12. Floating-point results can differ across platforms; extreme coordinates or weights may require rescaling and application-specific error analysis.
  • The complete output array requires 8 * X * Y bytes, plus polygon-edge and working storage. Choose a resolution that fits available memory.

License and Further Information

MIT licensed, by SLED contributors.

The source archive includes PUBLISHING.md (build and upload instructions), PORTING.md (implementation provenance), and THIRD_PARTY_NOTICES.md (dependency notices).

Release files for fastpgv 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastpgv 0.1.0
File Size Uploaded
fastpgv-0.1.0.tar.gz 17.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastpgv 0.1.0
File Interpreter ABI Platform
fastpgv-0.1.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details

Total release size: 113.2 kB

Release files / fastpgv-0.1.0.tar.gz

Download URL fastpgv-0.1.0.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2db42e68638a80716d69fa322b0d9d886a33987d1d75f4c47d0e256af85cec8d
BLAKE2b-256 checksum
How to use checksums
295d4ea562932c1df295e204e705b778c3554b60019a564705f0521908afbab9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / fastpgv-0.1.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL fastpgv-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Size 96.0 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fec57c8eab9ca09bfcf186e59ebc2ed357a15386f4816011d961277b6216730e
BLAKE2b-256 checksum
How to use checksums
af8d9d3ff6f6e0d1d1a677c0238e75c83eba343eda210a77ef2dfef5de4c0d56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release history Release notifications | RSS feed

0.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page