未捕获InvalidValueError:不是Feature或FeatureCollection [英] Uncaught InvalidValueError: not a Feature or FeatureCollection

查看:282
本文介绍了未捕获InvalidValueError:不是Feature或FeatureCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在看到Google Devs最近发布的视频后,我决定制作英国的地区地图。在这个网站上提到了一些可能性,因为我不得不解雇*所以我最终使用这个网站(数据下载的示例页面): a b href =http://mapit.mysociety.org/area/11804.html> http://mapit.mysociety.org/area/11804.html

请注意, GeoJSON下载作为第三个链接向下?它大约有1Mb的文件大小。当我第一次尝试使用它与我的地图:

 函数initMap(){
var ukc = new google.maps.LatLng(54.8,-4.6);
var mapOptions = {
zoom:5,
center:ukc
};
map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
map.data.loadGeoJson('http://local.mapsite.com:8080/app/jsondata/eastern.json');


$(document).ready(function(){
initMap();
});

我得到了上面的错误:未捕获InvalidValueError:不是Feature或FeatureCollection



修正尝试1 - Google it



使用Google搜索错误返回没有用处。 b
$ b

修正尝试2 - 收缩它



我想也许这是野兽的庞大规模,所以我使用mapshaper.org到更易于管理的10K。 仍然没有运气!

修正尝试3 - 甩掉它



也许我的GeoJSON格式不正确?但是,它怎么会认为它正在mapit.org上工作,但我发现这个奇妙的网站用于检查GeoJSON数据: http://geojsonlint.com/ - 短线工作!显然,GeoJSON工作得非常好,它在东英吉利的所有荣耀中都绘制了我的多边形(请注意geojsonlint使用OpenStreetMap)。但仍然不幸运

修正尝试4 - TopoJson



希望我可以合并地区和压缩在同一时间,我认为topojson会工作。我尝试过 - 我仍然遇到同样的错误。以下是我在Google云端硬盘上共享的topojson文件的链接: someregions.json 没有运气



修复尝试5 - 添加功能代码以启动JSON



当前GeoJSON文件启动
{bbox:[ - 0.745702,51.448473,1.767999,52.98991],type:GeometryCollection,geometries:...

我补充道:

  {type:Feature,bbox:[ -  0.745702,51.448473,1.767999 ,52.98991],type:GeometryCollection,geometry:



Fix Attempt 6 < h2>

重试不同的区域,因为它们不包含开始附近的bbox参数,只需启动
{type:Polygon,coordinates:[[[ [-3.155785,53.427385],[-3.151533,53.427328],[...



仍然没有运气



输入(失败)结论



即使我证明我的文件是足够小 linted 在其他地方工作尝试将它们放在我的地图上时,仍然从控制台收到那些令人生厌的错误消息。

 未捕获InvalidValueError:不是Feature或FeatureCollection 

以下是我通过GDrive公用共享的GeoJSON文件共享: https:// drive.google.com/file/d/0B42Aec8RKcHtNVNZZUxqV0Y5Rkk/edit?usp=sharing



我的下一次尝试将涉及topojson将所有区域压缩为一个内部区域但我想首先在这里查看是否有人知道我的问题可能是什么?因为这可能会浪费几个小时的无用能量。

*尝试使用Ordanance Survey数据失败,因为他们提供了SHD数据,而不是上一个问题中提到的SHP主题。因此,我无法使用ogr2​​ogr将其转换为GeoJSON。

解决方案

GeoJSON的规范可以在http://geojson.org/geojson-spec.html
相关(虽然是实验性)Google Maps API文档可以在< href =https://developers.google.com/maps/documentation/javascript/3.exp/reference#Data> https://developers.google.com/maps/documentation/javascript/3.exp/reference #Data



因此,Google地图看起来像GeoJSON是可以接受的,您需要将MapIt返回的Polygon(或类似物)封装在Feature或FeatureCollection,这里有一个bermuda-triangle的例子:


$ b

  {type:FeatureCollection ,
features:[
{type:Feature,
geometry:{
type:Polygon,
coordinates :
[
[
[-80.190262,25.774252],
[-66.118292,18.466465],
[-64.75737,32.321384],
[-80.190262,25.774252]
]
]
}
}
]
}



对于 http://mapit.mysociety.org/area/11804.html 提供的数据必须是:


$ b

{type:FeatureCollection,
features :[
{type:Feature,
geometry:/ **这里粘贴
的完整输出http://mapit.mysociety.org/area/11804 .geojson ** /
}
]
}


After seeing a recent video by the Google Devs I decided to do a regional map of the UK. There were a couple of possibilities mentioned on this site that I've since had to dismiss*

So I ended up using this site (example page of data downloads): http://mapit.mysociety.org/area/11804.html

Notice the GeoJSON download as the third link down? Its about a 1Mb file size. When I first tried using it with my map:

function initMap(){
    var ukc = new google.maps.LatLng(54.8, -4.6);
    var mapOptions = {
        zoom: 5,
        center: ukc
    };
    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    map.data.loadGeoJson('http://local.mapsite.com:8080/app/jsondata/eastern.json');
}

$(document).ready(function(){
    initMap();
});

I got the above error: Uncaught InvalidValueError: not a Feature or FeatureCollection

Fix Attempt 1 - Google it

Googling the error came back with nothing useful.

Fix Attempt 2 - Shrink it

I thought maybe it was the sheer size of the beast so I shrank it using mapshaper.org to a more manageable 10K. Still no luck!

Fix Attempt 3 - Lint it

Maybe my GeoJSON was badly formatted? But how could it be considering it was right there working on mapit.org but I found this wonderful site for linting GeoJSON data: http://geojsonlint.com/ - The linting worked! Apparently the GeoJSON worked so well that it drew my polygon of East Anglia on the UK in all its glory (note geojsonlint uses OpenStreetMap). But still No Luck

Fix Attempt 4 - TopoJson

Hoping I could combine the regions and compress at the same time I thought desperately that topojson would work. I tried - I still got that same error. Here's a link to my topojson file shared on Google Drive: someregions.json No luck.

Fix Attempt 5 - Add Feature code to start of JSON

The current GeoJSON file starts {"bbox":[-0.745702,51.448473,1.767999,52.98991],"type":"GeometryCollection","geometries":...

I added:

{"type": "Feature", "bbox":[-0.745702,51.448473,1.767999,52.98991],"type":"GeometryCollection","geometries":

Fix Attempt 6

Retry different regions as they donm't contain the bbox parameter near the start but simply start { "type": "Polygon", "coordinates": [ [ [ -3.155785, 53.427385 ], [ -3.151533, 53.427328 ], [...

Still no luck.

In (Failed) Conclusion

Even though I proved my file was small enough, linted and worked elsewhere I still got those infuriating error messages from the console when attempting to put them on my map.

Uncaught InvalidValueError: not a Feature or FeatureCollection

Here is my shrunk GeoJSON file publically shared via GDrive: https://drive.google.com/file/d/0B42Aec8RKcHtNVNZZUxqV0Y5Rkk/edit?usp=sharing

My next attempts will involve topojson to compress all regions into one with internal borders but I wanted to check here first to see if anyone knows what my problem could be? Because that may be another few hours of futile energy wasted.

* Attempting to use Ordanance Survey data failed as they provided SHD data and not SHP as stated in a previous question on the subject. So I couldn't convert it into GeoJSON using ogr2ogr.

解决方案

The specification for GeoJSON can be found at http://geojson.org/geojson-spec.html Relevant (though experimental) Google Maps API documentation can be found at https://developers.google.com/maps/documentation/javascript/3.exp/reference#Data

So it looks like for GeoJSON to be acceptable by Google Maps, you need to wrap a Polygon (or similar) returned by MapIt in a Feature or FeatureCollection, here's an example for bermuda-triangle:

  { "type": "FeatureCollection",
    "features": [
      { "type": "Feature",
         "geometry": {
           "type": "Polygon",
           "coordinates": 
              [
                [
                  [-80.190262,25.774252],
                  [-66.118292,18.466465],
                  [-64.75737,32.321384],
                  [-80.190262,25.774252]
                ]
              ]
         }
      }
    ]
  }

for the data provided by http://mapit.mysociety.org/area/11804.html it has to be:

  { "type": "FeatureCollection",
    "features": [
      { "type": "Feature",
         "geometry": /** paste here the complete output of 
                         http://mapit.mysociety.org/area/11804.geojson **/
      }
    ]
  }

这篇关于未捕获InvalidValueError:不是Feature或FeatureCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆