国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

寫(xiě)給小白學(xué)習(xí)的地理信息的表示法GeoJSON

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

    簡(jiǎn)介

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

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

    • 幾何對(duì)象用來(lái)描述地理空間中的點(diǎn)、線、面等幾何形狀
    • 空間行狀用來(lái)描述一個(gè)有界的實(shí)體,包括幾何對(duì)象和其他屬性信息

    幾何對(duì)象類(lèi)型有:

    • 點(diǎn):Point
    • 多點(diǎn):MultiPoint
    • 線:LineString
    • 多線:MultiLineString
    • 面:Polygon
    • 多面:MultiPolygon
    • 幾何集合:GeometryCollection

    空間行狀類(lèi)型有:

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

    舉例

    幾何對(duì)象和空間行狀可以相互嵌套

    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 對(duì)象的集合,用來(lái)表示一組 Feature 對(duì)象

    由 type 和 features 兩個(gè)屬性組成:

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

    Feature

    Feature 對(duì)象用來(lái)表示幾何對(duì)象的屬性信息

    由 typegeometry 和 properties 三個(gè)屬性組成:

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

    幾何對(duì)象

    Point

    Point 用來(lái)表示一個(gè)點(diǎn)

    由 type 和 coordinates 兩個(gè)屬性組成:

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

    MultiPoint

    MultiPoint 用來(lái)表示多個(gè)點(diǎn)

    由 type 和 coordinates 兩個(gè)屬性組成:

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

    LineString

    LineString 用來(lái)表示一條線

    由 type 和 coordinates 兩個(gè)屬性組成:

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

    MultiLineString

    MultiLineString 用來(lái)表示多條線

    由 type 和 coordinates 兩個(gè)屬性組成:

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

    Polygon

    Polygon 用來(lái)表示一個(gè)面

    由 type 和 coordinates 兩個(gè)屬性組成:

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

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

    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 用來(lái)表示多個(gè)面

    由 type 和 coordinates 兩個(gè)屬性組成:

    • type 屬性的值為 MultiPolygon
    • coordinates 屬性的值為一個(gè)數(shù)組,數(shù)組的每個(gè)元素都是一個(gè)面的坐標(biāo)數(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 用來(lái)表示幾何對(duì)象的集合

    由 type 和 geometries 兩個(gè)屬性組成:

    • type 屬性的值為 GeometryCollection
    • geometries 屬性的值為幾何對(duì)象的數(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 的擴(kuò)展屬性,不是 GeoJSON 規(guī)范的一部分

    • id 屬性,用來(lái)描述 FeatureCollection 的唯一標(biāo)識(shí)
    • bbox 屬性,用來(lái)描述 FeatureCollection 的邊界框

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

    其他

    coordinate

    coordinate 是一個(gè)數(shù)組,表示一個(gè)點(diǎn)的坐標(biāo),數(shù)組的長(zhǎng)度表示坐標(biāo)的維度,一般是 2 維或 3 維

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

    coordinate 的第一個(gè)元素表示經(jīng)度,第二個(gè)元素表示緯度,第三個(gè)元素表示高度

    坐標(biāo)順序是 [lon, lat],這個(gè)是推薦順序,可由 crs 屬性指定

    coordinates 是多維數(shù)組:

    • 點(diǎn):[lon, lat]
    • 線:[[lon, lat], [lon, lat]]
    • 面:[[[lon, lat], [lon, lat]]]
    • 多面:[[[[lon, lat], [lon, lat]]]]

    坐標(biāo)參考系

    最常使用的坐標(biāo)系是 EPSG:4326 和 EPSG:3857

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

    它們的區(qū)別:

    • EPSG:4326 是經(jīng)緯度坐標(biāo)系,EPSG:3857 是投影坐標(biāo)系
    • EPSG:4326 的坐標(biāo)范圍是 [-180, -90, 180, 90],EPSG:3857 的坐標(biāo)范圍是 [-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]
    • EPSG:4326 的坐標(biāo)單位是度,EPSG:3857 的坐標(biāo)單位是米
    • EPSG:4326 的坐標(biāo)原點(diǎn)是 [0, 0]EPSG:3857 的坐標(biāo)原點(diǎn)是 [-20037508.342789244, -20037508.342789244]
    • EPSG:4326 的坐標(biāo)軸方向是 [x, y],EPSG:3857 的坐標(biāo)軸方向是 [x, -y]

    在 ts 中使用

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

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

    舉例:

    表示一個(gè)點(diǎn)和多個(gè)點(diǎn)的 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)建一個(gè)幾何對(duì)象

    使用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ù)據(jù)集,坐標(biāo)系)
    • turf.js

    以上就是寫(xiě)給小白的地理信息的表示法GeoJSON的詳細(xì)內(nèi)容,更多關(guān)于GeoJSON地理信息表示法的資料請(qǐng)關(guān)注其它相關(guān)文章!

    標(biāo)簽: JavaScript
    主站蜘蛛池模板: 中文字幕一区二区精品区 | 国产一区二区三区四区五区 | 日本亚欧乱色视频在线观看 | 综合刺激网 | 久久视频免费观看 | 日韩成人免费一级毛片 | 欧美成人专区 | 亚洲天堂久久精品成人 | 国产精品久久久亚洲 | 国产成人黄网在线免 | 国产成人综合日韩精品婷婷九月 | 香蕉视频黄在线观看 | 男女男免费视频网站国产 | 涩涩网站 | 国产激爽大片在线播放 | 国产成人一区二区三区影院免费 | 欧美日韩 国产区 在线观看 | 国产精品网站 夜色 | 我要看a级毛片 | 免费看一级做a爰片久久 | 久久亚洲一级毛片 | 成人黄色三级 | 亚洲精品一区二区三区福利 | 亚洲欧美日本人成在线观看 | 久久国产精品久久久久久久久久 | 国产成人高清视频在线观看免费97 | vr18成人资源 | 国产精品亚洲视频 | 亚洲字幕波多野结衣作品 | 美女很黄很黄免费的 | 欧美a级毛片免费播敢 | 免费又黄又爽又猛大片午夜 | 色狠狠色综合吹潮 | 九九热国产精品视频 | 一区二区三区 亚洲区 | 日本视频在线免费观看 | 成人三级做爰在线观看男女 | 日本精品一区二区三区在线视频 | 亚洲精品在线网站 | 成人久久18免费网站 | 天堂8在线天堂资源bt |