Difference between revisions of "GeoJSON draft version 5"

From GeoJSON
Jump to: navigation, search
m (Specification)
m (Specification)
Line 24: Line 24:
 
#### For type "MultiPolygon", each element in the coordinates array is a coordinates array as described for type Polygon.
 
#### For type "MultiPolygon", each element in the coordinates array is a coordinates array as described for type Polygon.
 
#### For type "Box", each element in the coordinates array is a coordinates array as described for type "Point".  The coordinates array for a Box must have exactly two elements.
 
#### For type "Box", each element in the coordinates array is a coordinates array as described for type "Point".  The coordinates array for a Box must have exactly two elements.
### Geometry objects may also have a member with the name "crs" which specifies the coordinate reference system of the coordinates.  If present, the value of the crs member must be a string.
+
### Geometry objects may also have a member with the name "crs" which specifies the coordinate reference system of the coordinates.  If present, the value of the crs member must be an object.  The structure of that object is beyond the scope of this specification.
 
## A GeoJSON object with type "GeometryCollection" represents a collection of geomety objects.
 
## A GeoJSON object with type "GeometryCollection" represents a collection of geomety objects.
 
### An object of type "GeometryCollection" must have a member with the name "geometries".  The value of the geometries member is an array.  Each element in this array is a geometry object as defined above.
 
### An object of type "GeometryCollection" must have a member with the name "geometries".  The value of the geometries member is an array.  Each element in this array is a geometry object as defined above.

Revision as of 11:05, 23 May 2007

Overview

GeoJSON is a data-interchange format for a variety of geographic data structures. GeoJSON can be used to represent a geometry, a feature, a collection of geometries, or a collection of features. The geometry types supported in GeoJSON are Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and Box. Features in GeoJSON are geometry objects with additional properties. A geometry collection represents a list of geometries and a feature collection represents a list of features.

A complete GeoJSON data structure is always an object (in JSON terms). In GeoJSON, an object consists of a collection of name/value pairs - also called members. For each member, the name is always a string. Member values are either a string, number, object, array or one of the literals: true, false, and null. An array consists of elements where each element is a value as described above. Note that the term member generally refers to a name/value pair.

Definitions

Specification

  1. GeoJSON always consists of a single object. This object (referred to as the GeoJSON object below) represents a geometry, feature, collection of geometries, or collection of features.
  2. The GeoJSON object may have any number of members (name/value pairs).
  3. The GeoJSON object must have a member with the name "type". This member's value is a string that determines the type of the GeoJSON object.
    1. The value of the type member must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "Box", "GeometryCollection", "Feature", or "FeatureCollection"
    2. A geometry is a GeoJSON object where the type member's value is one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", or "Box".
      1. In addition to the type member, a GeoJSON object that represents a geometry (referred to as a geometry object below) must have a member with the name "coordinates". The value of the coordinates member is always an array (referred to as the coordinates array below). The structure for the elements in this array are determined by the type of geometry.
        1. For type "Point", each element in the coordinates array is a number representing the point coordinate in one dimension. The order of elements follows x, y, z order (or Longitude, Latitude, Elevation for coordinates in decimal degrees).
        2. For type "MultiPoint", each element in the coordinates array is a coordinates array as described for type "Point".
        3. For type "LineString", each element in the coordinates array is a coordinates array as described for type "Point". The coordinates array for a LineString must have two or more elements. A LinearRing is a special case of type LineString where the first and last elements in the coordinates array are equivalent (they represent equivalent points). Though a LinearRing is not explicitly represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition.
        4. For type "Polygon", each element in the coordinates array is a coordinates array as described for type "LineString". Furthermore, each LineString in the coordinates array must be a LinearRing. For Polygons with multiple LinearRings, the first must be the exterior ring and any others must be interior rings or holes.
        5. For type "MultiPolygon", each element in the coordinates array is a coordinates array as described for type Polygon.
        6. For type "Box", each element in the coordinates array is a coordinates array as described for type "Point". The coordinates array for a Box must have exactly two elements.
      2. Geometry objects may also have a member with the name "crs" which specifies the coordinate reference system of the coordinates. If present, the value of the crs member must be an object. The structure of that object is beyond the scope of this specification.
    3. A GeoJSON object with type "GeometryCollection" represents a collection of geomety objects.
      1. An object of type "GeometryCollection" must have a member with the name "geometries". The value of the geometries member is an array. Each element in this array is a geometry object as defined above.
      2. A GeometryCollection object may also have a member with the name "crs" which specifies the coordinate reference system of the collection. If a GeometryCollection has a crs member, the individual geometries in its "geometries" array shall not have their own crs member.
    4. A GeoJSON object with the type "Feature" represents a geometry with additional properties (referred to as a feature object below).
      1. A feature object must have a member with the name "geometry". The value of the geometry member is a geometry object as defined above (a GeoJSON object with type "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", or "Box").
      2. A feature object must have a member with the name "properties". The value of the properties member is an object (any JSON object).
    5. A GeoJSON object with the type "FeatureCollection" represents a collection of feature objects.
      1. An object of type "FeatureCollection" must have a member with the name "features". The value of the features member is an array. Each element in the array is a feature object as defined above with the exception that feature objects in a FeatureCollection need not have their own member named "type". All elements in the features array of a FeatureCollection must be feature objects and do not need to be identified as features with a "type" member.
      2. A FeatureCollection object may also have a member with the name "crs" which specifies the coordinate reference system of the collection. If a FeatureCollection has a crs member, the individual features in its "features" array shall not have their own crs member.

Examples

Each of the examples below represents a complete GeoJSON object. Note that unquoted whitespace is not significant in JSON. Whitespace is used in the examples to help illustrate the data structures - though it is not required.

Geometries

Point

{
   "type": "Point",
   "coordinates": [0.0, 0.0]
}

MultiPoint

{
   "type": "MultiPoint",
   "coordinates": [
       [0.0, 0.0], [1.0, 1.0]
   ]
}

LineString

{
   "type": "LineString",
   "coordinates": [
       [0.0, 0.0], [1.0, 1.0]
   ]
}

MultiLineString

{
   "type": "MultiLineString",
   "coordinates": [
       [
           [0.0, 0.0], [1.0, 1.0]
       ],
       [
           [2.0, 2.0], [3.0, 3.0]
       ]
   ]
}

Polygon

No holes

{
   "type": "Polygon",
   "coordinates": [
       [
           [0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0]
       ]
   ]
}

With holes

{
   "type": "Polygon",
   "coordinates": [
       [
           [0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0]
       ],
       [
           [0.2, 0.2], [0.8, 0.2], [0.8, 0.8], [0.2, 0.8], [0.2, 0.2]
       ]
   ]
}

MultiPolygon

{
   "type": "Polygon",
   "coordinates": [
       [
           [
               [2.0, 2.0], [3.0, 2.0], [3.0, 3.0], [2.0, 3.0], [2.0, 2.0]
           ]
       ],
       [
           [
               [0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0]
           ],
           [
               [0.2, 0.2], [0.8, 0.2], [0.8, 0.8], [0.2, 0.8], [0.2, 0.2]
           ]
       ]
   ]
}

Box

{
   "type": "Box",
   "coordinates": [
       [0.0, 0.0], [1.0, 1.0]
   ]
}

GeometryCollection

{
   "type": "GeometryCollection",
   "geometries": [
       {
           "type": "Point",
           "coordinates": [0.0, 0.0]
       },
       {
           "type: "LineString",
           "coordinates": [
               [0.0, 0.0], [1.0, 1.0]
           ]
       }
   ]
}

Feature

{
   "type": "Feature"
   "geometry": {
       "type": "LineString",
       "coordinates": [
           [0.0, 0.0], [1.0, 1.0]
       ]
   }
   "properties": {
       "prop0": "value0",
       "prop1": "value1"
   }
}

FeatureCollection

{
   "type": "FeatureCollection",
   "crs": "EPSG:27700",
   "features": [
       {
           "id": "id0",
           "geometry": {
               "type": "LineString",
               "coordinates": [
                   [0.0, 0.0], [1.0, 1.0]
               ]
           }
           "properties": {
               "prop0": "value0",
               "prop1": "value1"
           }
       },
       {
           "id": "id1",
           "geometry": {
               "type": "LineString",
               "coordinates": [
                   [0.0, 2.0], [1.0, 3.0]
               ]
           }
           "properties": {
               "prop0": "value0",
               "prop1": "value1"
           }
       }
   ]
}