Blog

懒癌晚期


Project maintained by VirusPC Hosted on GitHub Pages — Theme by mattgraham

Back Home

GeoJSON

GeoJSON is a geospatial data interchange format based on JavaScript Object Notation (JSON). It defines several types of JSON objects and the manner in which they are combined to represent data about geographic features, their properties, and their spatial extents. GeoJSON uses a geographic coordinate reference system, World Geodetic System 1984, and units of decimal degrees.

Table of Contents

An Example

A GeoJSON Feature Collection looks like this:

{
  "type": "FeatureCollection",
  "features": [{
      "type": "Feature",
      "geometry": {
          "type": "Point",
          "coordinates": [102.0, 0.5]
      },
      "properties": {
          "prop0": "value0"
      }
  }, {
      "type": "Feature",
      "geometry": {
          "type": "LineString",
          "coordinates": [
              [102.0, 0.0],
              [103.0, 1.0],
              [104.0, 0.0],
              [105.0, 1.0]
          ]
      },
      "properties": {
          "prop0": "value0",
          "prop1": 0.0
      }
  }, {
      "type": "Feature",
      "geometry": {
          "type": "Polygon",
          "coordinates": [
              [
                  [100.0, 0.0],
                  [101.0, 0.0],
                  [101.0, 1.0],
                  [100.0, 1.0],
                  [100.0, 0.0]
              ]
          ]
      },
      "properties": {
          "prop0": "value0",
          "prop1": {
              "this": "that"
          }
      }
  }]
}

GeoJSON Objects Overview

geojson objects

A GeoJSON object have 3 types:

  1. Geometry: A region of space
  2. Feature: A spatially bounded entity, which contains a Geometry object and additional properties. (append more properties to geometry!)
  3. FeatureCollection: A list of features

The GeoJSON object Geometry includes 7 types:

  1. Point: 0-dimentional point
  2. LineString: 1-dimentional curve
  3. Polygon: 2-dimentional surface
  4. MultiPoint: collection of Point
  5. MultiLineString: collection of LineString
  6. MultiPolygon: collection of Polygon
  7. GeometryCollection: collection of all the other types

Notes:

  1. Point, LineString and Polygon are the most fundamental objects. All the other Geometry objects, even all types of GeoJSON objects, are based on them.
  2. The types above are case-sensitive
  3. The “features” and “geometries” members, respectively, of these collection objects are standard ordered JSON arrays, not unordered sets.

Geometry

Geometries Except GeometryCollection

A Geometry (except GeometryCollection) consists of two parts: type and coordinates.

{
    "type": "Point",
    "coordinates": [102.0, 0.5]
}

The value of type property can be choosen from the 7 geometry types we talked above.

The format of the value of coordinates property differs.

Here are some definitions help to understand the following table:

Geometryg coordinates Format Example
Point a single position [103.0 31.0]
MultiPoint an array of positions [ [103.0, 31.0] ]
LineString an array of two or more positions [ [103.0, 31.0], [104.0, 31.0] ]
MultiLineString an array of LineString coordinate arrays [ [[103.0, 31.0], [104.0, 31.0]] ]
Polygon an array of linear ring coordinate arrays (the first must be the exterior ring: [exterior, ...interiors]) [ [[102.0, 31.0], [103.0, 31.0], [104.0, 31.0]] ]
MultiPolygon an array of Polygon coordinates [ [[[102.0, 31.0], [103.0, 31.0], [104.0, 31.0]]]] ]

GeometryCollection

Compared with the other geometries, GeometryCollection do not have the coordiantes member and have a new member called geometries instead. It looks like this:

{
    "type": "GeometryCollection",
    "geometries": [
        {
            "type": "Point",
            "coordinates": [102.0, 0.5]
        },
        {
          "type": "LineString",
          "coordinates": [
              [102.0, 0.0],
              [103.0, 1.0],
              [104.0, 0.0],
              [105.0, 1.0]
          ]
        }
    ]
}

There are some suggestions for GeometryCollection:

Antimeridian Cutting

Any geometry that crosses the antimeridian SHOULD be represented by cutting it in two such that neither part’s representation crosses the antimeridian. For example, if a Polygon across the antimeridian, it should be cutted in two and represented as a MultiPolygon.

Feature Object

A Feature object represents a spatially bounded thing. It has three members: type, geometry (do not confused with geometries in GeometryCollection) and properties:

{
  "type": "Feature",
  "geometry": {
      "type": "LineString",
      "coordinates": [
          [102.0, 0.0],
          [103.0, 1.0],
          [104.0, 0.0],
          [105.0, 1.0]
      ]
  },
  "properties": {
      "prop0": "value0",
      "prop1": 0.0
}

If a Feature has a commonly used identifier, that identifier SHOULD be included as a member of the Feature object with the name id, and the value of this member is either a JSON string or number.

FeatureCollection Object

A FeatureCollection object has two members: type and features:

{
  "type": "FeatureCollection",
  "features": [{
      "type": "Feature",
      "geometry": {
          "type": "Point",
          "coordinates": [102.0, 0.5]
      },
      "properties": {
          "prop0": "value0"
      }
  }]
}

Bounding Box

A GeoJSON object MAY have a member named bbox to include information on the coordinate range for its Geometrys, Features, or FeatureCollections.

{
    "type": "FeatureCollection",
    "bbox": [100.0, 0.0, 105.0, 1.0],
    "features": [
    //...
    ]
}

TopoJSON


Reference: