编辑巨大的 geoJSON 的最简单方法?
我坐在这里,手里拿着从开放街道地图形状文件中获得的巨大 geoJSON。然而,大多数多边形是不必要的。理论上,可以根据某些属性轻松地挑选出这些。
但是如何查询 geoJSON 文件以删除某些元素(特征)?或者以其他格式保存形状文件(在 QGIS 中工作)会更容易吗?
链接到 json 文件示例: http://dl.dropbox.com/u/15955488 /hki_test_sample.json (240 kB)
I'm sitting here with a huge geoJSON that I got from an Open Street Map shape-file. However, most of the polygons are unnecessary. These could, in theory, easily be singled out based on certain properties.
But how do I query the geoJSON file to remove certain elements (features)? Or would it be easier to save the shape-file in another format (working in QGIS)?
Link to sample of json-file: http://dl.dropbox.com/u/15955488/hki_test_sample.json (240 kB)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
当您说“查询 geoJSON”时,您是在谈论让获取 geoJSON 的源为您提供数据子集吗?没有像这样“查询”JSON 的广泛实施的标准,但是您检索的每个站点可能都有自己的参数,以减少您获取的数据的大小。
如果您正在讨论削减客户端代码中的数据,则只需循环遍历结构并删除属性(使用
delete
)和数组项就是您必须做的。When you say "query the geoJSON," are you talking about having the source where you get the geoJSON give you a subset of data? There is no widely-implemented standard for "querying" JSON like this, but each site you retrieve from may have its own parameters to reduce the size of data you get.
If you're talking about paring down the data in client-side code, simply looping through the structure and removing properties (with
delete
) and array items is what you'd have to do.对于大型(非巨型)数据,Shapefile 击败了 GeoJSON。它支持随机访问功能。要获取集合中的 GeoJSON 功能,您必须读取并反序列化整个文件。
Shapefile beats GeoJSON for large (not mega) data. It supports random access to features. To get at the GeoJSON features in a collection you have to read and deserialize the entire file.
根据您想要编辑的方式以及可用的软件,您有几种选择。如果您可以访问 Safe FME,这是迄今为止最好的地理特征操作软件,并且将为您提供大量选项(它可以读取/写入(并在之间转换)几乎任何地理格式)。如果您只是在寻找可以处理大量数据的文本编辑器,我会考虑 Notepad++ - 它可以容纳大量文本,并且您可以使用正则表达式进行查找/替换。 Safe FME 可能有点贵,但您也许可以试用
Depending on how you want to edit it and what software is available you have a few options. If you have access to Safe FME this is by far the best geographic feature manipuluation software and will give you tons of options (it can read / write (and convert between) just about any geographic format). If you're just looking for a text editor that can handle the volume of data I would look at Notepad++ - it can hold a lot of text and you can do find / replace using regular expressions. Safe FME can be a little pricy, but you might be able to get a trial
正如雅各布所说,只需迭代并删除不需要的元素即可。为了方便起见,我喜欢 http://documentcloud.github.com/underscore/#reject 。
As Jacob says, just iterate and remove the elements you don't want. I like http://documentcloud.github.com/underscore/#reject for convenience.
如果您要永久删除字段,只需将其转换为 shapefile,删除不需要的字段,然后将其重新导出为 GeoJSON。
If you are going to permanently remove fields just convert it to a shapefile, remove the fields you don't want, and re-export it as GeoJSON.
我意识到这个问题已经很老了,但如果现在有人遇到这个问题,我会推荐 TopoJSON。
将其转换为 TopoJSON。
默认情况下,TopoJSON 会删除所有属性,但您可以标记您想要保留的属性,如下所示:
TopoJSON 命令行参考
I realize this question is old, but if anyone comes across this now, I'd recommend TopoJSON.
Convert it to TopoJSON.
By default TopoJSON removes all attributes, but you can flag those you'd like to keep like this:
More info in the TopoJSON command line reference