GeoJSON 格式规范文档(双语)

最近要用 d3 绘制地图,所以来补习一下 GeoJSON 的知识。

# Introduction(简介)

GeoJSON is a format for encoding a variety of geographic data structures. A GeoJSON object may represent a geometry, a feature, or a collection of features. GeoJSON supports the following geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection. Features in GeoJSON contain a geometry object and additional properties, and a feature collection represents a list of features.

GeoJSON 是一种对各种地理数据结构进行编码的格式。GeoJSON 对象可以表示几何、特征或者特征集合。GeoJSON 支持下面几何类型:点、线、面、多点、多线、多面和几何集合。GeoJSON 里的特征包含一个几何对象和其他属性,特征集合表示一系列特征。

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.

一个完整的 GeoJSON 数据结构总是一个(JSON 术语里的)对象。在 GeoJSON 里,对象由名/值对--也称作成员的集合组成。对每个成员来说,名字总是字符串。成员的值要么是字符串、数字、对象、数组,要么是下面文本常量中的一个:"true","false"和"null"。数组是由值是上面所说的元素组成。

# Examples

A GeoJSON feature collection:

GeoJSON 特征集合:

{
  "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" }
      }
    }
  ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# Definitions(定义)

  • JavaScript Object Notation (JSON), and the terms object, name, value, array, and number, are defined in IETF RTC 4627, at http://www.ietf.org/rfc/rfc4627.txt.

  • The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in IETF RFC 2119, at http://www.ietf.org/rfc/rfc2119.txt.

  • JSON 和术语对象、名字、值、数组和数字在 IETF RFC 4627 即 http://www.ietf.org/rfc/rfc4627.txt 里定义。

  • 这篇文档里的关键字“必须“,”不允许“,”需要“,”应当“,”应当不“,”应该“,”不应该“,”推荐的“,”也许“和”可选的“在 IETF RFC 2119, 即http://www.ietf.org/rfc/rfc2119.txt里解释。

# GeoJSON Objects(GeoJSON 对象)

GeoJSON always consists of a single object. This object (referred to as the GeoJSON object below) represents a geometry, feature, or collection of features.

GeoJSON 总是由一个单独的对象组成。这个对象(指的是下面的 GeoJSON 对象)表示几何、特征或者特征集合。

  • The GeoJSON object may have any number of members (name/value pairs).

  • 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.

  • The value of the type member must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", or "FeatureCollection". The case of the type member values must be as shown here.

  • A GeoJSON object may have an optional "crs" member, the value of which must be a coordinate reference system object (see 3. Coordinate Reference System Objects).

  • A GeoJSON object may have a "bbox" member, the value of which must be a bounding box array (see 4. Bounding Boxes).

  • GeoJSON 对象可能有任何数目成员(名/值对)。

  • GeoJSON 对象必须由一个名字为"type"的成员。这个成员的值是由 GeoJSON 对象的类型所确定的字符串。

  • type 成员的值必须是下面之一:"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", 或者 "FeatureCollection"。这儿 type 成员值必须如这儿所示。

  • GeoJSON 对象可能有一个可选的"crs"成员,它的值必须是一个坐标参考系统的对象(见 3.坐标参考系统对象)。

  • GeoJSON 对象可能有一个"bbox"成员,它的值必须是边界框数组(见 4.边界框)。

# Geometry Objects(几何对象)

A geometry is a GeoJSON object where the type member's value is one of the following strings: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", or "GeometryCollection".

几何是一种 GeoJSON 对象,这时 type 成员的值是下面字符串之一:"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", 或者"GeometryCollection"。

A GeoJSON geometry object of any type other than "GeometryCollection" must have a member with the name "coordinates". The value of the coordinates member is always an array. The structure for the elements in this array is determined by the type of geometry.

除了“GeometryCollection”外的其他任何类型的 GeoJSON 几何对象必须由一个名字为"coordinates"的成员。coordinates 成员的值总是数组。这个数组里的元素的结构由几何类型来确定。

# Positions(位置)

A position is the fundamental geometry construct. The "coordinates" member of a geometry object is composed of one position (in the case of a Point geometry), an array of positions (LineString or MultiPoint geometries), an array of arrays of positions (Polygons, MultiLineStrings), or a multidimensional array of positions (MultiPolygon).

位置是基本的几何结构。几何对象的"coordinates"成员由一个位置(这儿是几何点)、位置数组(线或者几何多点),位置数组的数组(面、多线)或者位置的多维数组(多面)组成。

A position is represented by an array of numbers. There must be at least two elements, and may be more. The order of elements must follow x, y, z order (easting, northing, altitude for coordinates in a projected coordinate reference system, or longitude, latitude, altitude for coordinates in a geographic coordinate reference system). Any number of additional elements are allowed -- interpretation and meaning of additional elements is beyond the scope of this specification.

位置由数字数组表示。必须至少两个元素,可以有更多元素。元素的顺序必须遵从 x,y,z 顺序(投影坐标参考系统中坐标的东向、北向、高度或者地理坐标参考系统中的坐标长度、纬度、高度)。任何数目的其他元素是允许的---其他元素的说明和意义超出了这篇规格说明的范围。

Examples of positions and geometries are provided in Appendix A. Geometry Examples.

位置和几何的例子在附录 A.几何例子里呈现。

# Point(点)

For type "Point", the "coordinates" member must be a single position.

对类型"Point"来说,“coordinates"成员必须是一个单独的位置。

# MultiPoint(多点)

For type "MultiPoint", the "coordinates" member must be an array of positions.

对类型"MultiPoint"来说,"coordinates"成员必须是位置数组。

# LineString(线)

For type "LineString", the "coordinates" member must be an array of two or more positions.

对类型"LineString"来说,“coordinates"成员必须是两个或者多个位置的数组。

A LinearRing is closed LineString with 4 or more positions. The first and last positions 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 个或者更多位置的封闭的线。第一个和最后一个位置是相等的(它们表示相同的的点)。虽然线性环没有鲜明地作为 GeoJSON 几何类型,不过在面几何类型定义里有提到它。

# MultiLineString(多线 )

For type "MultiLineString", the "coordinates" member must be an array of LineString coordinate arrays.

对类型“MultiLineString"来说,"coordinates"成员必须是一个线坐标数组的数组。

# Polygon(面)

For type "Polygon", the "coordinates" member must be an array of LinearRing coordinate arrays. For Polygons with multiple rings, the first must be the exterior ring and any others must be interior rings or holes.

对类型"Polygon"来说,"coordinates"成员必须是一个线性环坐标数组的数组。对拥有多个环的的面来说,第一个环必须是外部环,其他的必须是内部环或者孔。

# MultiPolygon(多面)

For type "MultiPolygon", the "coordinates" member must be an array of Polygon coordinate arrays.

对类型"MultiPlygon"来说,"coordinates"成员必须是面坐标数组的数组。

# Geometry Collection(几何集合)

A GeoJSON object with type "GeometryCollection" is a geometry object which represents a collection of geometry objects.

类型为"GeometryCollection"的 GeoJSON 对象是一个集合对象,它表示几何对象的集合。

A geometry collection must have a member with the name "geometries". The value corresponding to "geometries" is an array. Each element in this array is a GeoJSON geometry object.

几何集合必须有一个名字为"geometries"的成员。与"geometries"相对应的值是一个数组。这个数组中的每个元素都是一个 GeoJSON 几何对象。

# Feature Objects(特征对象)

A GeoJSON object with the type "Feature" is a feature object.

类型为"Feature"的 GeoJSON 对象是特征对象。

  • A feature object must have a member with the name "geometry". The value of the geometry member is a geometry object as defined above or a JSON null value.

  • A feature object must have a member with the name "properties". The value of the properties member is an object (any JSON object or a JSON null value).

  • If a feature has a commonly used identifier, that identifier should be included as a member of the feature object with the name "id".

  • 特征对象必须由一个名字为"geometry"的成员,这个几何成员的值是上面定义的几何对象或者 JSON 的 null 值。

  • 特征对戏那个必须有一个名字为“properties"的成员,这个属性成员的值是一个对象(任何 JSON 对象或者 JSON 的 null 值)。

  • 如果特征是常用的标识符,那么这个标识符应当包含名字为“id”的特征对象成员。

# Feature Collection Objects(特征集合对象)

A GeoJSON object with the type "FeatureCollection" is a feature collection object.

类型为"FeatureCollection"的 GeoJSON 对象是特征集合对象。

An object of type "FeatureCollection" must have a member with the name "features". The value corresponding to "features" is an array. Each element in the array is a feature object as defined above.

类型为"FeatureCollection"的对象必须由一个名字为"features"的成员。与“features"相对应的值是一个数组。这个数组中的每个元素都是上面定义的特征对象。

# Coordinate Reference System Objects(坐标参考系统对象)

The coordinate reference system (CRS) of a GeoJSON object is determined by its "crs" member (referred to as the CRS object below). If an object has no crs member, then its parent or grandparent object's crs member may be acquired. If no crs member can be so acquired, the default CRS shall apply to the GeoJSON object.

GeoJSON 对象的坐标参考系统(CRS)是由它的"crs"成员(指的是下面的 CRS 对象)来确定的。如果对象没有 crs 成员,那么它的父对象或者祖父对象的 crs 成员可能被获取作为它的 crs。如果这样还没有获得 crs 成员,那么默认的 CRS 将应用到 GeoJSON 对象。

  • The default CRS is a geographic coordinate reference system, using the WGS84 datum, and with longitude and latitude units of decimal degrees.

  • The value of a member named "crs" must be a JSON object (referred to as the CRS object below) or JSON null. If the value of CRS is null, no CRS can be assumed.

  • The crs member should be on the top-level GeoJSON object in a hierarchy (in feature collection, feature, geometry order) and should not be repeated or overridden on children or grandchildren of the object.

  • A non-null CRS object has two mandatory members: "type" and "properties".

  • The value of the type member must be a string, indicating the type of CRS object.

  • The value of the properties member must be an object.

  • CRS shall not change coordinate ordering (see 2.1.1. Positions).

  • 默认的 CRS 是地理坐标参考系统,使用的是 WGS84 数据,长度和高度的单位是十进制标示。

  • 名字为"crs"成员的值必须是 JSON 对象(指的是下面的 CRS 对象)或者 JSON 的 null。如果 CRS 的值为 null,那么就假设没有 CRS 了。

  • crs 成员应当位于(特征集合、特征、几何的顺序的)层级结构里 GeoJSON 对象的最顶级,而且在自对象或者孙子对象里不应该重复或者覆盖。

  • 非空的 CRS 对象有两个强制拥有的对象:"type"和"properties"。

  • type 成员的值必须是字符串,这个字符串说明了 CRS 对象的类型。

  • 属性成员的值必须是对象。

  • CRS 应不能更改坐标顺序(见 2.1.1.位置)。

# Named CRS(名字 CRS)

A CRS object may indicate a coordinate reference system by name. In this case, the value of its "type" member must be the string "name". The value of its "properties" member must be an object containing a "name" member. The value of that "name" member must be a string identifying a coordinate reference system. OGC CRS URNs such as "urn:ogc:def:crs:OGC:1.3:CRS84" shall be preferred over legacy identifiers such as "EPSG:4326":

CRS 对象可以通过名字来表明坐标参考系统。在这种情况下,它的"type"成员的值必须是字符串"name"。它的"properties"成员的值必须是包含"name"成员的对象。这个"name"成员的值必须是标识坐标参考系统的字符串。比如“urn:ogc:def:crs:OGC:1.3:CRS84"的 OGC CRS 的 URN 应当优先于旧的标识符如"EPSG:4326"得到选用:

{
  "crs": {
    "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
    }
  }
}
1
2
3
4
5
6
7
8

# Linked CRS(连接 CRS)

A CRS object may link to CRS parameters on the Web. In this case, the value of its "type" member must be the string "link", and the value of its "properties" member must be a Link object (see 3.2.1. Link Objects).

CRS 对象也可以连接到互联网上的 CRS 参数。在这种情况下,它的"type"成员的值必须是字符串"link",它的"properties"成员的值必须是一个连接对象(见 3.2.1.连接对象) 。

A link object has one required member: "href", and one optional member: "type".

连接对象由一个必需的成员:"href",和一个可选的成员:"type"。

The value of the required "href" member must be a dereferenceable URI.

必需的"href"成员的值必须是解引用的 URI(统一资源标识)。

The value of the optional "type" member must be a string that hints at the format used to represent CRS parameters at the provided URI. Suggested values are: "proj4", "ogcwkt", "esriwkt", but others can be used:

可选的"type"成员的值必须是字符串,而且这个字符串暗示了所提供的 URI 里用来表示 CRS 参数的格式。建议值是:"proj4","ogcwkt",esriwkt",不过可以使用其他值:

{
  "crs": {
    "type": "link",
    "properties": {
      "href": "http://example.com/crs/42",
      "type": "proj4"
    }
  }
}
1
2
3
4
5
6
7
8
9

Relative links may be used to direct processors to CRS parameters in an auxiliary file:

相对连接常常可以作为辅助文件里的 CRS 的直接处理器:

{
  "crs": {
    "type": "link",
    "properties": {
      "href": "data.crs",
      "type": "ogcwkt"
    }
  }
}
1
2
3
4
5
6
7
8
9

# Bounding Boxes(边界框)

To include information on the coordinate range for geometries, features, or feature collections, a GeoJSON object may have a member named "bbox". The value of the bbox member must be a 2*n array where n is the number of dimensions represented in the contained geometries, with the lowest values for all axes followed by the highest values. The axes order of a bbox follows the axes order of geometries. In addition, the coordinate reference system for the bbox is assumed to match the coordinate reference system of the GeoJSON object of which it is a member.

为了包含几何、特征或者特征集合的坐标范围信息,GeoJSON 对象可能有一个名字为"bbox 的成员。bbox 成员的值必须是 2*n 数组,这儿 n 是所包含几何对象的维数,并且所有坐标轴的最低值后面跟着最高者值。bbox 的坐标轴的顺序遵循几何坐标轴的顺序。除此之外,bbox 的坐标参考系统假设匹配它所在 GeoJSON 对象的坐标参考系统。

Example of a bbox member on a feature:

特征对象上的 bbox 成员的例子:

{
  "type": "Feature",
  "bbox": [-180.0, -90.0, 180.0, 90.0],
  "geometry": {
    "type": "Polygon",
    "coordinates": [[[-180.0, 10.0], [20.0, 90.0], [180.0, -5.0], [-30.0, -90.0]]]
  }
}
1
2
3
4
5
6
7
8

Example of a bbox member on a feature collection:

特征集合对象 bbox 成员的例子:

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

# Appendix A. Geometry Examples(附录 A.集合例子)

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, but is not required.

下面例子中的每一个都表示一个完整的 GeoJSON 对象。注意 JSON 对象里的结尾的空白字符没有意义。例子里所用的空白符有助于说明这个数据结构,不过不是必需的。

# Point(点)

Point coordinates are in x, y order (easting, northing for projected coordinates, longitude, latitude for geographic coordinates):

点坐标是按照 x,y 顺序的(投影坐标的东向、北向,地理坐标的长度、高度):

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

# LineString(线)

Coordinates of LineString are an array of positions (see 2.1.1. Positions):

线的坐标是位置数组(见 2.1.1.位置):

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

# Polygon(面)

Coordinates of a Polygon are an array of LinearRing coordinate arrays. The first element in the array represents the exterior ring. Any subsequent elements represent interior rings (or holes).

面的坐标是线性环坐标数组的数组。这个数组的第一个元素表示的是外部环。其他后续的元素表示的内部环(或者孔)。

No holes:

没有孔的:

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

With holes:

有孔的:

{
  "type": "Polygon",
  "coordinates": [
    [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
    [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]
  ]
}
1
2
3
4
5
6
7

# MultiPoint(多点)

Coordinates of a MultiPoint are an array of positions:

多点的坐标是位置数组:

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

# MultiLineString(多线)

Coordinates of a MultiLineString are an array of LineString coordinate arrays:

多线的坐标是线坐标数组的数组:

{ "type": "MultiLineString", "coordinates": [[[100.0, 0.0], [101.0, 1.0]], [[102.0, 2.0], [103.0, 3.0]]] }
1

# MultiPolygon(多面)

Coordinates of a MultiPolygon are an array of Polygon coordinate arrays:

多面的坐标是面坐标数组的数组:

{
  "type": "MultiPolygon",
  "coordinates": [
    [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
    [
      [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
      [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]
    ]
  ]
}
1
2
3
4
5
6
7
8
9
10

# GeometryCollection(几何集合)

Each element in the geometries array of a GeometryCollection is one of the geometry objects described above:

几何集合的几何数组里的每个元素都是上面所描述的几何对象之一:

{
  "type": "GeometryCollection",
  "geometries": [
    { "type": "Point", "coordinates": [100.0, 0.0] },
    { "type": "LineString", "coordinates": [[101.0, 0.0], [102.0, 1.0]] }
  ]
}
1
2
3
4
5
6
7

# Appendix B. Contributors(附录 B.贡献者)

The GeoJSON format specification is the product of discussion on the GeoJSON list:

GeoJSON 的格式规格说明是 GeoJSON 邮件列表即:

http://lists.geojson.org/listinfo.cgi/geojson-geojson.org