Git Product home page Git Product logo

geojson-quirks's Introduction

geojson-quirks

Tweak your data to interoperate with quirky GeoJSON readers

Why

You've got valid GeoJSON; you know it's valid since you ran it through geojson-hint. But for some reason another application, library or service doesn't like it.

Well it turns out these quirks are pretty common in GeoJSON readers. In fact, they're so common that I'm writing a python library to encapsulate them, making it dead simple to tweak the GeoJSON structure for the sake of interoperability.

Installation

pip install -e git+https://github.com/mapbox/geojson-quirks.git#egg=geojson-quirks

Usage

$ geojson-quirks --help
Usage: geojson-quirks [OPTIONS] FEATURES...

  Tweak your data to interoperate with quirky GeoJSON readers

Options:
  --sequence / --no-sequence   Write a LF-delimited sequence of texts
                               containing individual objects or write a single
                               JSON text containing a feature collection
                               object (the default).
  --rs / --no-rs               Use RS (0x1E) as a prefix for individual texts
                               in a sequence as per http://tools.ietf.org/html
                               /draft-ietf-json-text-sequence-13 (default is
                               False).
  --gather-properties          any non-standard keys will be moved to
                               Features.properties
  --flatten                    flatten Feature.properties
  --string-id                  casts the Feature.id (if exists) to a string
  --add-id                     add an auto-incrementing integer as the
                               Feature.id
  --add-uuid                   add a unique string identifier as the
                               Feature.id
  --add-id-from-property TEXT  add a Feature.id from specified
                               Feature.properties object
  --override-id                Allow options that manipulate Feature.id to
                               overwrite
  --type-first                 Put type element at beginning of
                               FeatureCollection
  --help                       Show this message and exit.

Key ordering

Some GeoJSON readers assume that the "type": "FeatureCollection" property comes at the very top of the file.

geojson-quirks --type-first

Feature Identifiers

Features can optionally contain an id but some GeoJSON readers require them. You can add a Feature.id using a unique identifier string

geojson-quirks --add-uuid

Or an auto-incrementing integer id.

geojson-quirks --add-id

GeoJSON writers sometime put the effective feature id in the properties object. You can grab an id from your existing properties

geojson-quirks --id-from-property "FID"

By default, all of the above operations won't touch existing ids; if you want to overwrite them with new values

geojson-quirks --add-uuid --override-id

Or convert ids to strings if your reader requires it.

geojson-quirks --string-id

Properties

GeoJSON features require a type, geometry, properties and optionally specifies an id. However, it is valid to put other keys in there (see foo in the example below):

{
    "id": 1,
    "type": "Feature",
    "properties": {
        "fid": 9001,
        "nest": {
            "a": 1,
            "b": 2}},
    "geometry": {"type": "Point", "coordinates": [0, 0]},
    "foo": "bar"
}

Many GIS applications expect all important data to live in a flat key:value properties object.

You can gather all "foreign" members into the properties object.

geojson-quirks --gather-properties
# feature.properties.foo == "bar"

And flatten nested properties members to make it more tabular GIS friendly

geojson-quirks --flatten
# feature.properties.nest_a == 1

geojson-quirks's People

Contributors

perrygeo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.