【问题标题】:geojson file formatting issue, mini-arrays(coordinates) inside larger array of coordinatesgeojson 文件格式问题,更大的坐标数组中的迷你数组(坐标)
【发布时间】:2017-08-12 19:04:40
【问题描述】:

我的 geoJSON 文件:坐标键包含带有坐标的普通数组,但随后包含一个填充了更多坐标的迷你数组的数组。我无法遍历文件以提取路线的中心,以便将我的 google 功能层添加到我的 google api 调用中。

当我尝试拆分迷你阵列并将其添加到整个总阵列时,路线变得可见,但不正确。路线越过水面并穿过建筑物,它不知道顺序。任何帮助都会很棒。粗体打破了整个特征的格局。

例如: {"type":"Feature","properties":{"OBJECTID":3,"LENGTH":3919.4410000000003,"NAME":"Anacostia Riverwalk-SW","STATUS":"Open","MAINTENANC":" DDOT","Shape_Length":1194.6479669066844,"MILES":0.7423183712121213},"geometry":{"type":"MultiLineString","coordinates":[[[-77.02215895389972,38.87673054256091],[-77.02186869854079,38.87653957420972],[ -77.02150193815677,38.87588299990856],[-77.0208280524279,38.874621556490816],[-77.02075697415529,38.87448850380858],[-77.02062323938105,38.874211704408985],[-77.02008845385471,38.87338800912766],[-77.01937789804083,38.87202111748801],[-77.01768265826789,38.87204526498413]],

[[-77.02594024042205,38.87974434948391],[-77.02509229875858,38.87909983220277],[-77.0237707432032,38.8780375415248],[-77.02215132050688,38.87674248295079]] ]}},

【问题讨论】:

    标签: javascript ruby-on-rails google-maps-api-3 geojson


    【解决方案1】:

    你所说的mini-arrays只是geojson MultiLineStrings的规范。 http://geojson.org/geojson-spec.html#multilinestring

    For type "MultiLineString", the "coordinates" member is an array of LineString coordinate arrays.

    所以每个数组都描述了一条线的一部分,它们一起形成了结果路线。您可以使用 2 个 for 循环(它是一个数组数组)来迭代它们

    var geojson = {
      "type": "FeatureCollection",
      "features": [
        {
          "type": "Feature",
          "properties": {},
          "geometry": {
            "type": "MultiLineString","coordinates":[
              [[-77.02215895389972,38.87673054256091],[-77.02186869854079,38.87653957420972],[-77.02150193815677,38.87588299990856],[-77.0208280524279,38.874621556490816],[-77.02075697415529,38.87448850380858],[-77.02062323938105,38.874211704408985],[-77.02008845385471,38.87338800912766],[-77.01937789804083,38.87202111748801],[-77.01768265826789,38.87204526498413]],
              [[-77.02594024042205,38.87974434948391],[-77.02509229875858,38.87909983220277],[-77.0237707432032,38.8780375415248],[-77.02215132050688,38.87674248295079]] 
            ]
          }
        }
      ]
    }
    
    let coords = geojson.features[0].geometry.coordinates;
    for (let i = 0; i < coords.length; i += 1) {
      for (let j = 0; j < coords[i].length; j += 1) {
        console.log(coords[i][j]);
      }
    }

    【讨论】:

      猜你喜欢
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-20
      • 2015-04-29
      • 1970-01-01
      相关资源
      最近更新 更多