Metadata-Version: 2.4
Name: sidewalkreator
Version: 0.1.0
Summary: Headless OSM Sidewalkreator - generate sidewalks from OSM data without QGIS GUI
Author-email: Kaue Vestena <kauemv2@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/kauevestena/headless_sidewalkreator
Project-URL: Source, https://github.com/kauevestena/headless_sidewalkreator
Project-URL: Tracker, https://github.com/kauevestena/headless_sidewalkreator/issues
Keywords: osm,geopandas,osmnx,sidewalks,gis,urban_mobility_studies,vector data
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: GIS
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: geopandas>=1.0
Requires-Dist: osmnx>=1.4
Requires-Dist: shapely>=2.0
Requires-Dist: scipy>=1.10
Requires-Dist: pyogrio>=0.7.2
Requires-Dist: pyproj>=3.6
Requires-Dist: rtree>=1.0
Requires-Dist: pandas>=1.5
Requires-Dist: networkx>=3.0
Requires-Dist: duckdb>=1.0.0
Requires-Dist: pmtiles>=3.0.0
Requires-Dist: mapbox-vector-tile>=2.0.0
Requires-Dist: mercantile>=1.2.1
Requires-Dist: tqdm>=4.66
Requires-Dist: requests>=2.30
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Provides-Extra: performance
Requires-Dist: matplotlib>=3.7; extra == "performance"
Requires-Dist: pyarrow>=14.0; extra == "performance"
Dynamic: license-file

# sidewalkreator

A lightweight tool for generating sidewalks from OSM data.

This repository contains a headless (CLI / library) version of the QGIS plugin
OSM Sidewalkreator.

## Installation

Python 3.11 or newer is required; CI tests Python 3.11–3.14 on Linux.
The distribution name is `sidewalkreator`; the Python import remains
`headless_sidewalkreator`. Version 0.1.0 is being prepared for its first PyPI
release. Until published, install from a checkout with `python -m pip install .`.
After publication:

```bash
python -m pip install sidewalkreator
sidewalkreator --help
```

Generated geometry is a mapping starting point requiring review, not a verified
production pedestrian network. Full same-input QGIS GUI geometry parity remains
an acceptance task. See [release instructions](https://github.com/kauevestena/headless_sidewalkreator/blob/feature/headless-prototype/docs/publishing.md).

## API Overview
### Planet Download API

You can now use cloud-optimized planet files (Overture Maps or Protomaps) as data sources:

```python
result = sidewalkreator(
    bbox=(-72.53, 42.37, -72.52, 42.38),
    parameters={
        "provider": "overture",
        "provider_kwargs": {"release": "2026-06-17.0"}
    }
)
```

See [PLANET_SOURCES.md](PLANET_SOURCES.md) for more details.


The library provides several APIs for different use cases:

### Full Sidewalk Generation API

The `sidewalkreator()` function accepts and returns GeoDataFrames, giving users full control over I/O.

> **Note**: This function was previously named `generate_sidewalks_gdf()`. The old name is still available for backward compatibility but is deprecated.

**Input options (choose one):**

```python
from headless_sidewalkreator import sidewalkreator
import geopandas as gpd

# Option 1: Use a polygon GeoDataFrame
input_polygon_gdf = gpd.read_file("area_of_interest.geojson")
result = sidewalkreator(input_polygon_gdf=input_polygon_gdf)

# Option 2: Use a place name (geocoded automatically)
result = sidewalkreator(place_name="Amherst, MA")

# Option 3: Use a bounding box (minx, miny, maxx, maxy)
result = sidewalkreator(bbox=(-72.53, 42.37, -72.52, 42.38))

# All options support additional parameters
result = sidewalkreator(
    bbox=(-72.53, 42.37, -72.52, 42.38),
    parameters={"buffer_dist": 2.0},  # Optional custom parameters
    ignore_existing=False
)

# Extract results - all are GeoDataFrames
sidewalks = result['sidewalks']
crossings = result['crossings'] 
kerbs = result['kerbs']
protoblocks = result['protoblocks']  # For analysis/debugging
parameters_used = result['parameters']

# User handles output as needed
sidewalks.to_file("output_sidewalks.geojson")
crossings.to_file("output_crossings.gpkg")
```

### Standalone Protoblocks Generation API

The `generate_protoblocks()` function generates only the protoblocks (enclosed areas formed by street networks) without creating sidewalks. This is useful for urban analysis, block-level studies, or as input for other algorithms.

```python
from headless_sidewalkreator import generate_protoblocks
import geopandas as gpd

# Same input options as sidewalkreator
protoblocks = generate_protoblocks(
    input_polygon_gdf=your_polygon_gdf
    # OR place_name="Your City, State"
    # OR bbox=(minx, miny, maxx, maxy)
)

# Result is a GeoDataFrame of polygon geometries
print(f"Generated {len(protoblocks)} protoblocks")
protoblocks.to_file("protoblocks_output.geojson")
```

## Command-Line Usage

The tool can also be used from the command line with three input options:

```bash
# Option 1: Use a GeoJSON polygon file
sidewalkreator --input-file area.geojson --output-dir ./output

# Option 2: Use a place name (geocoded automatically)  
sidewalkreator --place-name "Amherst, MA" --output-dir ./output

# Option 3: Use a bounding box (minx miny maxx maxy)
sidewalkreator --bbox -72.53 42.37 -72.52 42.38 --output-dir ./output

# All options support additional parameters
sidewalkreator --bbox -72.53 42.37 -72.52 42.38 --output-dir ./output --ignore-existing
```

**Alternative**: The tool can also be invoked using `python -m headless_sidewalkreator` with the same arguments.

## Development setup

Modern versions of geopandas and related geospatial libraries come with
bundled binaries on supported Python/platform combinations. File I/O uses
GeoPandas 1.0+ and its default Pyogrio backend; Fiona is not required.
Python 3.15 verification is deferred until upstream native dependencies are
ready; see the TODO in [the publishing guide](docs/publishing.md).

### Quick setup (Python 3.11+):

1. Create and activate a Python virtual environment:

```bash
python3 -m venv .venv
source .venv/bin/activate

# upgrade pip and build tools
python -m pip install --upgrade pip setuptools wheel
```

2. Install all dependencies:

```bash
# install in editable mode with development dependencies
pip install -e .[dev]
```

### Alternative: Conda setup

If you prefer conda:

```bash
conda create -n hs-env python=3.12 -y
conda activate hs-env

# install via conda-forge for potentially faster geospatial package installation
conda install -c conda-forge geopandas osmnx -y

# install remaining dependencies in editable mode
pip install -e .[dev]
```

## Running tests

With the virtual environment active and dependencies installed:

```bash
# run tests (uses pytest)
pytest -q
```

### QGIS GUI parity

The original QGIS GUI implementation is the behavioral reference for this
headless port.  The parity regressions in `test/test_qgis_gui_parity.py` cover
the following rules:

- positive sidewalk tags create diagnostic sure zones in QGIS but do not clip
  unrelated generated sidewalks;
- side-specific and negative sidewalk tags remove only the GUI-defined side;
- a crossing is emitted only after both sidewalk-axis intersections are found;
- road segments shorter than 20 metres are skipped by default, matching the
  GUI control;
- each candidate's 1 m center buffer must be contained by a generated
  protoblock;
- crossing rays are parallel to the smallest-angle incident street by default,
  matching the GUI's selected radio option; and
- the committed QGIS grid fixture yields 6 sidewalks, 14 crossings, and 28
  kerbs from the headless pipeline.

The segment-length, center-containment, and direction assumptions can be
overridden explicitly:

```python
parameters = {
    "min_crossing_segment_length": value_in_metres,
    "crossing_center_buffer_distance": value_in_metres,
    "crossing_direction_mode": "parallel",  # or "perpendicular"
}
```

The parallel option is applied consistently at both endpoint orientations.
The current GUI source appears to fall back to perpendicular at its `P0`
branch because that call does not request an index from
`point_forms_minor_angle_w2`. Consequently, the source-derived tests and the
count fixture are sufficient to trigger a fresh parity run, but production
acceptance still requires geometry-level comparison with a GUI export made
from the same frozen OSM input.

## Editable install and quick run

To install the package in editable/development mode:

```bash
pip install -e .

# then you can import the package in Python
python -c "from headless_sidewalkreator import sidewalkreator; print(sidewalkreator.__doc__)"
```

## Notes
- The package uses OSMnx to fetch OpenStreetMap data. OSMnx's `features_`
	helpers return GeoDataFrames and are preferred; the code falls back to
	older `geometries_` names if necessary.
- CI workflow is provided in `.github/workflows/ci.yml` which installs
	dependencies and runs the test suite on GitHub Actions.

If you'd like, I can add a Makefile or small helper scripts to automate
these steps.

This is the headless version of a QGIS Plugin called OSM Sidewalkreator, available at:

https://github.com/kauevestena/osm_sidewalkreator

TODO: Restore Python 3.15 verification in both the source-test and installed-wheel
CI matrices once the native dependency ecosystem is ready. Verification is
deferred as of September 22, 2026; Python 3.15 is not currently verified or a
release gate. Python 3.11–3.14 remain required, with matrix fail-fast disabled.
