Metadata-Version: 2.4
Name: geosplit
Version: 0.4.0
Summary: Split GeoJSON by feature count or file size and convert GeoJSON to and from GeoPackage
Project-URL: Source, https://github.com/KoaOkano/GeoSplit
Project-URL: Issues, https://github.com/KoaOkano/GeoSplit/issues
Author: GeoSplit contributors
License-Expression: MIT
License-File: LICENSE
Keywords: geojson,geopackage,gis,splitter
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: GIS
Requires-Python: >=3.10
Requires-Dist: ijson>=3.5
Requires-Dist: simplejson>=3.20.2
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: gpkg
Requires-Dist: geopandas>=1.1.2; extra == 'gpkg'
Description-Content-Type: text/markdown

# GeoSplit

A focused command-line tool that:

- splits a GeoJSON `FeatureCollection` by feature count;
- splits it by a strict maximum file size; and
- converts GeoJSON to GeoPackage, or a GeoPackage layer back to GeoJSON.

The splitter uses a lightweight streaming parser, preserves coordinate precision, and bounds memory use to the current output chunk. GeoPackage support is optional.

View general or command-specific help at any time:

```bash
geosplit help
geosplit help split
geosplit help convert
```

## Install

Requires Python 3.10 or newer. Install GeoSplit from PyPI:

```bash
python -m pip install geosplit
```

Include conversion support:

```bash
python -m pip install "geosplit[gpkg]"
```

Confirm the installation:

```bash
geosplit help
```

If the `geosplit` command is not on your system path, use `python -m geosplit help` and replace `geosplit` with `python -m geosplit` in the examples below.

## Split GeoJSON

By feature count:

```bash
geosplit split world.geojson output --features 1000
```

Omit the output directory to create `world_split` . Specifying Output directory is optional:

```bash
geosplit split world.geojson --features 1000
```

By maximum file size:

```bash
geosplit split world.geojson output --size 10MB
```

Preview every output file, feature count, size, warning, and conflict without writing anything:

```bash
geosplit split world.geojson output --features 1000 --dry-run
```

Sizes accept `B`, `KB`, `KiB`, `MB`, `MiB`, `GB`, and `GiB`. Each resulting file is a complete, compact GeoJSON document whose on-disk size does not exceed the requested limit. If one feature cannot fit by itself, the command stops with a clear error.

Output files are numbered automatically, such as `world_001.geojson`, `world_002.geojson`, and so on. Use `--prefix countries` to customize their names or `--force` to replace files recorded in GeoSplit's hidden output manifest. Progress is written to stderr; use `--quiet` to suppress it. Interrupted transactions are recovered on the next run. A source collection's top-level `bbox` is omitted because it would no longer describe each split collection; other top-level metadata is retained.

## Python API

Stream validated collections without writing files:

```python
from geosplit import iter_batches

for collection in iter_batches("world.geojson", features=1000):
    process(collection)
```

Plan a split, or inspect the result of a completed split:

```python
from geosplit import plan_split, split_geojson

plan = plan_split("world.geojson", features_per_file=1000)
result = split_geojson("world.geojson", features_per_file=1000)

print(plan.files)
print(result.files)
print(result.feature_count)
print(result.total_bytes)
```

Show the installed version with `geosplit --version`.

## Convert formats

```bash
# GeoJSON to GeoPackage
geosplit convert roads.geojson roads.gpkg

# Choose the new GeoPackage layer name
geosplit convert roads.geojson map.gpkg --output-layer roads

# GeoPackage to GeoJSON
geosplit convert map.gpkg roads.geojson --layer roads
```

If a GeoPackage contains exactly one layer, `--layer` is optional. Existing destinations are protected unless `--force` is supplied.

## Update

```bash
python -m pip install --upgrade geosplit
```

## License

MIT
