亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

寫給小白學習的地理信息的表示法GeoJSON

瀏覽:155日期:2022-06-09 14:32:35
目錄
  • 簡介
    • 舉例
  • 空間行狀
    • FeatureCollection
    • Feature
  • 幾何對象
    • Point
    • MultiPoint
    • LineString
    • MultiLineString
    • Polygon
    • MultiPolygon
    • GeometryCollection
  • 可選屬性
    • 其他
      • coordinate
      • 坐標參考系
      • 在 ts 中使用

    簡介

    GeoJSON 是一種使用 JSON 來編碼各種地理數(shù)據結構的格式,是一種輕量級的數(shù)據交換格式,可以用來表示幾何對象、屬性數(shù)據、空間參考系統(tǒng)等信息

    由兩種對象組成:Geometry(幾何對象)和 Feature(空間行狀)

    • 幾何對象用來描述地理空間中的點、線、面等幾何形狀
    • 空間行狀用來描述一個有界的實體,包括幾何對象和其他屬性信息

    幾何對象類型有:

    • 點:Point
    • 多點:MultiPoint
    • 線:LineString
    • 多線:MultiLineString
    • 面:Polygon
    • 多面:MultiPolygon
    • 幾何集合:GeometryCollection

    空間行狀類型有:

    • 空間行狀:Feature
    • 空間形狀集合:FeatureCollection

    舉例

    幾何對象和空間行狀可以相互嵌套

    const GeoJSON = {
      type: "FeatureCollection",
      features: [
        {
          type: "Feature",
          geometry: { type: "Point", coordinates: [121.4737, 31.2304] },
          properties: { id: 1 },
        },
        {
          type: "Feature",
          geometry: { type: "Point", coordinates: [121.4837, 31.2504] },
          properties: { id: 2 },
        },
      ],
    };

    空間行狀

    FeatureCollection

    FeatureCollection 是 Feature 對象的集合,用來表示一組 Feature 對象

    由 type 和 features 兩個屬性組成:

    • type 屬性的值為 FeatureCollection
    • features 屬性的值為 Feature 對象的數(shù)組
    const FeatureCollectionJSON = {
      type: "FeatureCollection",
      features: [feature],
    };

    Feature

    Feature 對象用來表示幾何對象的屬性信息

    由 typegeometry 和 properties 三個屬性組成:

    • type 屬性的值為 Feature
    • geometry 屬性的值為 Geometry 幾何對象
    • properties 屬性的值為屬性對象(可選)
    const FeatureJSON = {
      type: "Feature",
      geometry: { type: "Point", coordinates: [121.4737, 31.2304] },
      properties: { id: 1 },
    };

    幾何對象

    Point

    Point 用來表示一個點

    由 type 和 coordinates 兩個屬性組成:

    • type 屬性的值為 Point
    • coordinates 屬性的值為一個數(shù)組,數(shù)組的第一個元素為經度,第二個元素為緯度
    const PointJSON = {
      type: "Point",
      coordinates: [121.4737, 31.2304],
    };

    MultiPoint

    MultiPoint 用來表示多個點

    由 type 和 coordinates 兩個屬性組成:

    • type 屬性的值為 MultiPoint
    • coordinates 屬性的值為一個數(shù)組,數(shù)組的每個元素都是一個點的坐標
    const MultiPointJSON = {
      type: "MultiPoint",
      coordinates: [
        [121.4737, 31.2304],
        [121.4837, 31.2504],
      ],
    };

    LineString

    LineString 用來表示一條線

    由 type 和 coordinates 兩個屬性組成:

    • type 屬性的值為 LineString
    • coordinates 屬性的值為一個數(shù)組,數(shù)組的每個元素都是一個點的坐標
    const LineStringJSON = {
      type: "LineString",
      coordinates: [
        [121.4737, 31.2304],
        [121.4837, 31.2504],
      ],
    };

    MultiLineString

    MultiLineString 用來表示多條線

    由 type 和 coordinates 兩個屬性組成:

    • type 屬性的值為 MultiLineString
    • coordinates 屬性的值為一個數(shù)組,數(shù)組的每個元素都是一個線的坐標數(shù)組
    const MultiLineStringJSON = {
      type: "MultiLineString",
      coordinates: [
        [
          [121.4737, 31.2304],
          [121.4837, 31.2504],
        ],
        [
          [121.4727, 31.2314],
          [121.4827, 31.2514],
        ],
      ],
    };

    Polygon

    Polygon 用來表示一個面

    由 type 和 coordinates 兩個屬性組成:

    • type 屬性的值為 Polygon
    • coordinates 屬性的值為一個數(shù)組,數(shù)組的第一個元素為外環(huán)的坐標數(shù)組,后面的元素為內環(huán)的坐標數(shù)組

    polygon 的坐標數(shù)組的第一個元素和最后一個元素是相同的,表示閉合

    const PolygonJSON = {
      type: "Polygon",
      coordinates: [
        [
          [121.4737, 31.2304],
          [121.4837, 31.2504],
          [121.4937, 31.2304],
          [121.4737, 31.2304],
        ],
        [
          [121.4717, 31.2314],
          [121.4827, 31.2524],
          [121.4937, 31.2334],
          [121.4757, 31.2344],
        ],
      ],
    };

    MultiPolygon

    MultiPolygon 用來表示多個面

    由 type 和 coordinates 兩個屬性組成:

    • type 屬性的值為 MultiPolygon
    • coordinates 屬性的值為一個數(shù)組,數(shù)組的每個元素都是一個面的坐標數(shù)組
    const MultiPolygonJSON = {
      type: "MultiPolygon",
      coordinates: [
        [
          [
    [121.4737, 31.2304],
    [121.4837, 31.2504],
    [121.4937, 31.2304],
    [121.4737, 31.2304],
          ],
          [
    [121.4737, 31.2304],
    [121.4837, 31.2504],
    [121.4937, 31.2304],
    [121.4737, 31.2304],
          ],
        ],
        [
          [
    [121.4737, 31.2304],
    [121.4837, 31.2504],
    [121.4937, 31.2304],
    [121.4737, 31.2304],
          ],
          [
    [121.4737, 31.2304],
    [121.4837, 31.2504],
    [121.4937, 31.2304],
    [121.4737, 31.2304],
          ],
        ],
      ],
    };

    GeometryCollection

    GeometryCollection 用來表示幾何對象的集合

    由 type 和 geometries 兩個屬性組成:

    • type 屬性的值為 GeometryCollection
    • geometries 屬性的值為幾何對象的數(shù)組
    const GeometryCollectionJSON = {
      type: "GeometryCollection",
      geometries: [
        { type: "Point", coordinates: [121.4737, 31.2304] },
        {
          type: "LineString",
          coordinates: [
    [121.4737, 31.2304],
    [121.4837, 31.2504],
          ],
        },
      ],
    };

    可選屬性

    這些屬性都是 GeoJSON 的擴展屬性,不是 GeoJSON 規(guī)范的一部分

    • id 屬性,用來描述 FeatureCollection 的唯一標識
    • bbox 屬性,用來描述 FeatureCollection 的邊界框

      • 四至坐標,一般用來做數(shù)據裁剪
      • 這是一組左上角和右下角的坐標,示例:[minLon, minLat, maxLon, maxLat]
    • properties 屬性,用來描述 FeatureCollection 的屬性
    • crs 屬性,用來描述坐標參考系

    其他

    coordinate

    coordinate 是一個數(shù)組,表示一個點的坐標,數(shù)組的長度表示坐標的維度,一般是 2 維或 3 維

    • 2 維:[lon, lat]
    • 3 維:[lon, lat, height]

    coordinate 的第一個元素表示經度,第二個元素表示緯度,第三個元素表示高度

    坐標順序是 [lon, lat],這個是推薦順序,可由 crs 屬性指定

    coordinates 是多維數(shù)組:

    • 點:[lon, lat]
    • 線:[[lon, lat], [lon, lat]]
    • 面:[[[lon, lat], [lon, lat]]]
    • 多面:[[[[lon, lat], [lon, lat]]]]

    坐標參考系

    最常使用的坐標系是 EPSG:4326 和 EPSG:3857

    • EPSG:4326 是 WGS84(CGCS2000,大地) 坐標系,是 GeoJSON 規(guī)范的默認坐標系
    • EPSG:3857 是 Web Mercator(墨卡托) 坐標系,是 OpenLayers 的默認坐標系

    它們的區(qū)別:

    • EPSG:4326 是經緯度坐標系,EPSG:3857 是投影坐標系
    • EPSG:4326 的坐標范圍是 [-180, -90, 180, 90]EPSG:3857 的坐標范圍是 [-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]
    • EPSG:4326 的坐標單位是度,EPSG:3857 的坐標單位是米
    • EPSG:4326 的坐標原點是 [0, 0]EPSG:3857 的坐標原點是 [-20037508.342789244, -20037508.342789244]
    • EPSG:4326 的坐標軸方向是 [x, y]EPSG:3857 的坐標軸方向是 [x, -y]

    在 ts 中使用

    為了在 ts 使用 GeoJSON 能夠有類型約束,我整理整理了一些 GeoJSON 的 ts 類型定義和創(chuàng)建 GeoJSON 的方法:

    • geojson.d.ts
    • geojson.helper.ts

    舉例:

    表示一個點和多個點的 GeoJSON 集合:

    使用geojson.d.ts

    type PointType = FeatureCollection<Point | MultiPoint, GeoJsonProperties<T>>;
    const point2Geojson: PointType<{ id: string; name?: string }> = {
      type: "FeatureCollection",
      features: [
        {
          type: "Feature",
          geometry: {
    type: "Point",
    coordinates: [120.4737, 31.2304],
          },
          properties: { id: "12", name: "uccs" },
        },
        {
          type: "Feature",
          geometry: {
    type: "MultiPoint",
    coordinates: [
      [121.4737, 31.2304],
      [111.4737, 31.2204],
    ],
          },
          properties: { id: "1" },
        },
      ],
    };

    創(chuàng)建一個幾何對象

    使用geojson.helper.ts

    const pointGeometry = point<{ id: string }>([120.4737, 31.2304], {
      id: "1",
    });
    const featureGeoJSON = feature<Point>(pointGeometry);

    參考

    • GeoJSON
    • GeoJSON 格式
    • GeoJSON 格式規(guī)范
    • EPSG 4326 vs EPSG 3857 (投影,數(shù)據集,坐標系)
    • turf.js

    以上就是寫給小白的地理信息的表示法GeoJSON的詳細內容,更多關于GeoJSON地理信息表示法的資料請關注其它相關文章!

    標簽: JavaScript
    主站蜘蛛池模板: 色婷婷亚洲精品综合影院 | 黄色一级片黄色一级片 | 色欲综合视频天天天 | 亚洲 欧美 日韩 在线 | 精品大臿蕉视频在线观看 | 草操视频| 亚洲国产精品第一页 | 久久99国产综合精品 | 精品国产一区二区三区四区色 | 中文字幕一区二区在线视频 | 模特尤妮丝凹凸福利视频 | 日韩精品一区二区三区中文 | 国产一区二区三区波多野吉衣 | 女女互添下身免费视频 | 二区三区视频 | 一级一级一片在线观看 | 国产伦精品一区二区三区女 | 久久国产精品系列 | 国产 另类 在线 欧美日韩 | 国产2021精品视频免费播放 | er久99久热只有精品国产 | 黄色a三级三级三级免费看 黄色a三级免费看 | 美美女高清毛片视频黄的一免费 | 在线观看中文字幕2021 | 成人国产精品一区二区网站 | 大乳女人做受视频免费观看 | 黄网站色年片在线观看 | 一区二区三区在线看 | 视色视频在线观看 | 久草97| 欧美不在线 | 欧美日韩一区二区三区在线观看 | 国产精品久久久久久久午夜片 | 国产亚洲精品视频中文字幕 | 国产免费一级视频 | 老司机一级毛片 | bbbxxx乱大交欧美小说 | 中文字幕亚洲视频 | 亚洲免费视频网站 | 91寡妇天天综合久久影院 | 九九99久久精品影视 |