GeoJSON几何对象示例

GeoJSON几何对象示例

GeoJSON 是一种开放的标准,用于描述地理信息对象的 JSON(JavaScript Object Notation)格式。它以文本方式存储地理空间数据,并包含了对象的地理位置信息和其他属性信息。GeoJSON 对象可用于 GIS 应用程序的分析和显示。

GeoJSON 官方规范定义了以下几种对象类型:

  • Point(点) – 表示一个具有一组地理坐标的点
  • LineString(线) – 表示一个由线段组成的路径
  • Polygon(面)-- 包括由线形环组成的封闭面
  • MultiPoint(多个点) – 包含多个点的集合
  • MultiLineString(多条线) – 包含多条线的集合
  • MultiPolygon(多个面) – 包含多个面的集合
  • GeometryCollection(几何图元集合) – 包含多个简单几何对象的集合
  • Feature(要素) – 表示一个要素,包含一个几何图元和其他属性
  • FeatureCollection(要素集) – 包含多个要素的集合

GeoJSON 格式通过简单的 JSON 对象来表示以上对象,如下是一个简单的 GeoJSON 示例:

{ "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [104.0, 30.0]
  },
  "properties": {
    "name": "test point"
  }
}

在这个示例中,"type":"Feature" 表示这是一个要素对象。"geometry" 包含着要素对象的几何信息,"properties" 包含着要素对象的其他属性。 "geometry" 对象中的 "type":"Point" 表示这是一个点对象,而 "coordinates" 数组则包含着该点的经纬度坐标。

使用 GeoJSON 可以方便地存储和传输地图和空间数据,并且易于处理。GeoJSON 格式已被广泛应用于 Web 地图应用程序、GPS 设备、地图编辑器和空间数据分析工具等领域。

GeoJSON 示例

下面是 GeoJSON 的各种对象类型的示例:

Point

// Point(点)
{
    "type": "Point",
    "coordinates": [104.6, 30.1]
}

LineString

// LineString(线)
{
    "type": "LineString",
    "coordinates": [
        [104.6, 30.1],
        [104.7, 30.2],
        [104.8, 30.3]
    ]
}

Polygon

Polygons由GeoJSON LinearRing坐标数组组成。这些 LinearRings都是闭合线(Closed LineStrings)。闭合线(Closed LineStrings)的至少具有四个坐标对(coordinate pairs),并指定与第一个和最后一个坐标相同的位置。

单环多边形(Polygons with a Single Ring)

以下示例指定了一个带外部环但没有内部环(或孔)的GeoJSON多边形(Polygon)。第一个和最后一个坐标必须匹配才能闭合这个多边形:

// Polygon(面)
{
    "type": "Polygon",
    "coordinates": [
        [
            [104.6, 30.1],
            [104.7, 30.2],
            [104.8, 30.3]
            [104.6, 30.1]
        ]
    ]
}

对于带有单个环的多边形,环不能自相交。

多环多边形(Polygons with Multiple Rings)

对于具有多个环的多边形:

  • 描述的第一个环必须是外环。
  • 外环不能自相交。
  • 任何内环必须完全由外环容纳。
  • 内环不能相交或重叠。内环不能共享边缘。

以下示例表示一个带内环的GeoJSON多边形:

{
  "type" : "Polygon",
  "coordinates" : [
     [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ],
     [ [ 2 , 2 ] , [ 3 , 3 ] , [ 4 , 2 ] , [ 2 , 2 ] ]
  ]
}

MultiPoint

// MultiPoint(多个点)
{
    "type": "MultiPoint",
    "coordinates": [
        [125.6, 10.1],
        [125.7, 10.2],
        [125.8, 10.3]
    ]
}

MultiLineString

// MultiLineString(多条线)
{
    "type": "MultiLineString",
    "coordinates": [
        [
            [125.6, 10.1],
            [126.0, 11.0],
            [126.4, 12.0]
        ],
        [
            [125.6, 10.1],
            [125.7, 10.2],
            [125.8, 10.3]
        ]
    ]
}

MultiPolygon

// 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]
            ]
        ]
    ]
}

GeometryCollection

// GeometryCollection(几何图元集合)
{
    "type": "GeometryCollection",
    "geometries": [
        {
            "type": "Point",
            "coordinates": [125.6, 10.1]
        },
        {
            "type": "LineString",
            "coordinates": [
                [125.6, 10.1],
                [126.0, 11.0],
                [126.4, 12.0]
            ]
        },
        {
            "type": "Polygon",
            "coordinates": [
                [
                    [100.0, 0.0],
                    [101.0, 0.0],
                    [101.0, 1.0],
                    [100.0, 1.0],
                    [100.0, 0.0]
                ]
            ]
        }
    ]
}

Feature

// Feature(地物)
{
    "type": "Feature",
    "geometry": {
        "type": "Point",
        "coordinates": [125.6, 10.1]
    },
    "properties": {
        "name": "test point"
    }
}

FeatureCollection

// FeatureCollection(地物集)
{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [125.6, 10.1]
            },
            "properties": {
                "name": "test point 1"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [125.7, 10.2]
            },
            "properties": {
                "name": "test point 2"
            }
        }
    ]
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值