Skip to main content

Convert GeoJSON to BrokJSON and vice versa

Project description

BrokJSON

Ever struggled with huge GeoJSON-Files? BrokJSON is your space-saving alternative! Depending on your data you can save up to 80%. Withouth losing any data! Why? Because it uses the same ideas as GeoJSON.

The idea behind BrokJSON: RAM is mightier than the bandwidth - download the small BrokJSON and convert it on runtime to GeoJSON than loading a huge GeoJSON.

Example

This GeoJSON with just two Points...

{
  "type": "FeatureCollection",
  "features": [
  {
    "type": "Feature",
    "properties": {
      "id": 1,
      "title": "Datapoint 1",
      "value": 343
    },
    "geometry": {
      "type": "Point",
      "coordinates": [8.5402,47.3782]
    }
  },
  {
    "type": "Feature",
    "properties": {
      "id": 1,
      "title": "Datapoint 2",
      "value": 14
    },
    "geometry": {
      "type": "Point",
      "coordinates": [8.5637,47.4504]
    }
  }]
}

... looks as a BrokJSON like this:

{
  "properties": ["id", "title", "value"],
  "geometries": [{
    "type": "Point",
    "features": [
      [[8.5402, 47.3782], [1, "Datapoint 1", 343]],
      [[8.5637, 47.4504], [1, "Datapoint 2", 14]]
    ]
  }
]}

No information lost, everything is there. Amazing!

Installation

pip install brokjson

Usage

# import BrokJSON
import brokjson

# Load your GeoJSON
geojson = {
    "type": "FeatureCollection",
    "features": [
    {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [8.5402,47.3782]
        }
    }]
}

# Convert your Json-Object to BrokJson
brok = brokjson.geo2brok(geojson);

# "brok" is your BrokJSON as a dictionary object
print(brok)

# Convert it back
geojson = brokjson.brok2geo(brok)
print(geojson)

Documentation

BrokJSON is a lightweight library, there are only two functions.

GeoJSON to BrokJSON

brokjson.geo2brok(geoJsonObject)

Parameters
GeoJSON as a Dictionary

Return value
BrokJSON as a Dictionary

BrokJSON to GeoJSON

brokjson.brok2geo(brokJsonObject)

Parameters
BrokJSON as a Dictionary

Return value
GeoJSON as a Dictionary

Full Spec and other languages

Have a look at https://www.brokjson.dev

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

brokJSON-1.0.0.tar.gz (3.7 kB view hashes)

Uploaded source

Built Distribution

brokJSON-1.0.0-py3-none-any.whl (3.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page