GeoJSON入门到精通

5次阅读

共计 2301 个字符,预计需要花费 6 分钟才能阅读完成。

GeoJSON 是什么

如果你接触过数据可视化,那么大概率会知道 GeoJSON。不知道?没关系,本文将为您娓娓道来!

GeoJSON 是一种对各种地理数据结构进行编码的格式,基于 Javascript 对象表示法的地理空间信息数据交换格式。

官网:https://geojson.org/

中文翻译:https://www.oschina.net/trans…

GeoJSON 对象

GeoJSON 对象必须由一个名字为 ”type” 的成员。

type 成员的值必须是下面之一:”Point”, “MultiPoint”, “LineString”, “MultiLineString”, “Polygon”, “MultiPolygon”, “GeometryCollection”, “Feature”, 或者 “FeatureCollection”。

GeoJSON 对象分为三种:几何对象、特征对象、特征集合对象

note: 下面的代码都可以在 http://geojson.io 查看效果,如下:

几何对象

GeoJSON 支持以下几何类型:Point,MultiPoint,LineString,MultiLineString,Polygon,和 MultiPolygon。

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

点(Point)

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

多点(MultiPoint)

{
    "type": "MultiPoint",
    "coordinates": [[ 100, 0],
        [101, 1]
    ]
}

线(LineString)

{
    "type": "LineString",
    "coordinates": [[ 100, 0],
        [101, 1]
    ]
}

多线(MultiLineString)

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

多边(Polygon)

没有孔的:

{
    "type": "Polygon",
    "coordinates": [
        [[ 100, 0],
            [101, 0],
            [101, 1],
            [100, 1],
            [100, 0]
        ]
    ]
}

有孔的:

{
    "type": "Polygon",
    "coordinates": [
        [[ 100, 0],
            [101, 0],
            [101, 1],
            [100, 1],
            [100, 0]
        ],
        [[ 100.2, 0.2],
            [100.8, 0.2],
            [100.8, 0.8],
            [100.2, 0.8],
            [100.2, 0.2]
        ]
    ]
}

多多边(和 MultiPolygon)

{
  "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]
            ]
        ]
    ]
}

几何集合

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

特征对象

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

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

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

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

{
    "type":"Feature",
    "properties":{},
    "geometry":{"type": "Point", "coordinates": [100.0, 0.0] }
}

特征集合对象

特征集合对象 type 为 FeatureCollection。

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


{
  "type": "FeatureCollection",
  "features": []}

坐标参考系统对象

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

边界框

GeoJSON 对象可能有一个名字为 ”bbox 的成员。bbox 成员的值必须是 2 * n 数组,这儿 n 是所包含几何对象的维数,并且所有坐标轴的最低值后面跟着最高者值。

更多资源

https://github.com/abc-club/f…

您的支持是我们不断前进的动力。

喜欢请 start!!!

喜欢请 start!!!

喜欢请 start!!!

正文完
 0