Skip to main content

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

Project description

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:

geosplit help
geosplit help split
geosplit help convert

Install

Requires Python 3.10 or newer. Install GeoSplit from PyPI:

python -m pip install geosplit

Include conversion support:

python -m pip install "geosplit[gpkg]"

Confirm the installation:

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:

geosplit split world.geojson output --features 1000

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

geosplit split world.geojson --features 1000

By maximum file size:

geosplit split world.geojson output --size 10MB

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

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:

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:

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

# 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

python -m pip install --upgrade geosplit

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.0.tar.gz (15.2 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.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: geosplit-0.4.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for geosplit-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6fb333e6c852363af81b88cff78b9143b9db68b4ea730268a551a7c977f01cca
MD5 eeb219bee8d43bb5ef309ebc1ef0737b
BLAKE2b-256 44ad25dd54d6f2b8ed4e7f4b25d66898525c5d51bccf84dbf11e35ce8f98bc82

See more details on using hashes here.

File details

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

File metadata

  • Download URL: geosplit-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for geosplit-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6079f58d7bf5e1ce9c6d6d60de6213b979b3c9934b77c32c2f81ef8773784d0
MD5 ab4386b678b014e9dd749734f23e7e03
BLAKE2b-256 13deac5b42c25f61f34ef074eef53001da6f5ef80290aefd46c65c641a1b6e57

See more details on using hashes here.

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