Skip to main content

Split GeoJSON by feature count or file size and convert GeoJSON to and from GeoPackage

Project description

GeoSplit

GeoSplit safely splits a GeoJSON FeatureCollection by feature count or exact file size. It can also convert GeoJSON to and from GeoPackage.

The splitter streams large inputs, preserves coordinate precision, limits memory to the active output chunk, checks available disk space, and uses recoverable output transactions.

Install

GeoSplit requires Python 3.10 or newer:

python -m pip install geosplit

On Windows, py can be used instead:

py -m pip install geosplit

Install optional GeoPackage support:

python -m pip install "geosplit[gpkg]"

Check the installation:

geosplit --version
geosplit --help
geosplit help split

If geosplit is not on your PATH, replace it with python -m geosplit or, on Windows, py -m geosplit.

Split GeoJSON

Split every 1,000 features:

geosplit split world.geojson --features 1000

The output directory is optional. When omitted, GeoSplit creates world_split beside the input. To choose it explicitly:

geosplit split world.geojson output --features 1000

Split using an exact maximum output size:

geosplit split world.geojson output --size 10MB

Sizes accept B, KB, KiB, MB, MiB, GB, and GiB. Every output is a complete compact GeoJSON document. A feature that cannot fit by itself produces an error.

Preview with dry-run

Show planned files, feature counts, sizes, warnings, and conflicts without creating anything:

geosplit split world.geojson --features 1000 --dry-run

Dry-run still reads and validates the complete input.

Other split options

Choose the output filename prefix:

geosplit split world.geojson --features 1000 --prefix countries

Replace output files previously managed by GeoSplit:

geosplit split world.geojson --features 1000 --force

Suppress progress and success output for scripts:

geosplit split world.geojson --features 1000 --quiet

Options can be combined:

geosplit split world.geojson output --size 50MiB --prefix region --force --quiet

Output files are numbered automatically, for example world_001.geojson. GeoSplit preserves top-level metadata except bbox, which would no longer describe each split collection. Interrupted transactions are recovered on the next run.

Convert GeoJSON and GeoPackage

Install geosplit[gpkg] first, then run:

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

# Select 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

# Replace an existing destination
geosplit convert roads.geojson roads.gpkg --force

If a GeoPackage contains exactly one layer, --layer is optional.

Python API

Stream validated collections without writing files:

from geosplit import iter_batches

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

Plan without writing, then perform a split:

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)

Use max_bytes instead of features_per_file for exact-size splitting.

Safety behavior

  • Existing output is protected unless --force is supplied.
  • --force only replaces files tracked by GeoSplit or recognized legacy output.
  • Output is staged before replacing existing files.
  • Coordinate values retain their parsed decimal precision.
  • Invalid geometry structure, non-finite coordinates, corrupt JSON, and excessive nesting are rejected.
  • A disk-space estimate is checked before staging; operating-system write errors are still handled if free space changes later.

Update

python -m pip install --upgrade geosplit

Contributing and security

See CONTRIBUTING.md and SECURITY.md.

License

MIT

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

geosplit-0.4.2.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geosplit-0.4.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file geosplit-0.4.2.tar.gz.

File metadata

  • Download URL: geosplit-0.4.2.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for geosplit-0.4.2.tar.gz
Algorithm Hash digest
SHA256 f206102049e15f42b1cd1996f78d964b9d49e469542add60f5e2b7d59f98f4d7
MD5 0e73c5bdf52df3851a41dee5d4cdf840
BLAKE2b-256 0a31375502c9cace88ebc7844221475d758af6b2b0ac384f8f317befd225d255

See more details on using hashes here.

Provenance

The following attestation bundles were made for geosplit-0.4.2.tar.gz:

Publisher: release.yml on KoaOkano/GeoSplit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geosplit-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: geosplit-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for geosplit-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a33b512e8308213b39f3de3b0f1b58df8ed8cf606140c3f3df827b2f778ed95
MD5 1e35e822b24f6c121d622529283ef3a1
BLAKE2b-256 41fc46175c98cf323cbf3b00ce59ca29ebab7dcc78597659a83463e41e71b7c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for geosplit-0.4.2-py3-none-any.whl:

Publisher: release.yml on KoaOkano/GeoSplit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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