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

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

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

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

    簡介

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

    由兩種對象組成: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 對象的數組
    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 屬性的值為一個數組,數組的第一個元素為經度,第二個元素為緯度
    const PointJSON = {
      type: "Point",
      coordinates: [121.4737, 31.2304],
    };

    MultiPoint

    MultiPoint 用來表示多個點

    由 type 和 coordinates 兩個屬性組成:

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

    LineString

    LineString 用來表示一條線

    由 type 和 coordinates 兩個屬性組成:

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

    MultiLineString

    MultiLineString 用來表示多條線

    由 type 和 coordinates 兩個屬性組成:

    • type 屬性的值為 MultiLineString
    • coordinates 屬性的值為一個數組,數組的每個元素都是一個線的坐標數組
    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 屬性的值為一個數組,數組的第一個元素為外環的坐標數組,后面的元素為內環的坐標數組

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

    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 屬性的值為一個數組,數組的每個元素都是一個面的坐標數組
    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 屬性的值為幾何對象的數組
    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 規范的一部分

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

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

    其他

    coordinate

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

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

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

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

    coordinates 是多維數組:

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

    坐標參考系

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

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

    它們的區別:

    • 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 類型定義和創建 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" },
        },
      ],
    };

    創建一個幾何對象

    使用geojson.helper.ts

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

    參考

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

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

    標簽: JavaScript
    主站蜘蛛池模板: 国产成人 免费观看 | 亚洲福利精品 | 成人三级在线播放线观看 | 久久成人免费网站 | 国产精品毛片一区 | 欧美性生大片免费观看 | 菠萝菠萝蜜在线看7 | 一区二区三区免费视频 www | 国产午夜精品尤物福利视频 | 91视频免费入口 | 99re在线精品视频免费 | 久青草香蕉精品视频在线 | 欧美一区二区亚洲 | 日韩免费观看一级毛片看看 | 手机在线黄色网址 | 欧美色视 | 国产原创麻豆精品视频 | 91精品手机国产免费 | 日韩高清网站 | 韩日中文字幕 | 国产一区二区三区免费看 | 久久精品a一国产成人免费网站 | 在线爱爱视频 | 国产精品久久久久乳精品爆 | 国产欧美精品一区二区 | 欧美高清不卡 | 欧美在线观看日韩欧美在线观看 | 国产精品福利在线观看免费不卡 | 国产精品嫩草影院一二三区 | 四虎永久免费地址ww 41.6 | 国产精品嫩草影院人体模特 | 一区二区不卡在线观看 | 久久夜色tv网站免费影院 | 久久精品国产精品亚洲婷婷 | 国产一二区视频 | 一级做a爱过程免费视频麻豆 | 国产精选一区 | 青草娱乐极品免费视频 | 香蕉视频在线网站 | 日韩欧美精品综合久久 | 亚洲九九九 |