d3.js geoJSON和bounds [英] d3.js geoJSON and bounds

查看:677
本文介绍了d3.js geoJSON和bounds的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功加载geoJSON文件,将功能集合加载到

  d3.geo.path  

我当前的实现的问题是它开始缩放,使路径是一个点,放大每次。现在我知道有很多方法可以设置缩放级别,但我希望使用

  d3.geo。 bounds()

给定以下geoJSON功能:

  json.features [0]:

对象
geometry:Object
coordinates:Array [2]
0 :-71.248913
1:44.078426
length:2
__proto__:Array [0]
type:Point
__proto__:Object
id:2
type:Feature
__proto__:Object



  json.features [1]:

对象
geometry:Object
coordinates:Array [2]
0:-71.249021
1:44.078387
length:2
__proto__:Array [0]
type:Point
__proto__: Object
id:3
type:Feature
__proto__:Object

如果我执行

  d3.geo.bounds(json.features)
  

d3.geo.bounds(json.features)
[
Array [2]
0:无穷大
1:无穷大
长度:2
__proto__ array [0]

Array [2]
0:-Infinity
1:-Infinity
length:2
__proto__:Array [0]
]



我不确定是什么错了,显然我有一个很多larget数据集上面,但我只是想了解输出。这个输出对我没有意义,并且显然缺少关于d3处理geoJSON数据的简单的事情。



感谢。

解决方案

d3.geo.bounds 使用单个Feature或FeatureCollection作为参数,而不是要素数组。请参见文档。您需要调用例如

  d3.geo.bounds(json.features [0])

如果你想要一个包含所有特征的边界框,你需要依次得到每个边界框,然后计算那些。


I have successfully loaded geoJSON files loaded the feature collection into a

d3.geo.path() 

The problem with my current implementation is that it starts off the scaling such that the path is a point, and I have to zoom in each time. Now I know there are plenty of methods to about setting the zoom level right, but I was hoping to use

d3.geo.bounds()

Given the following geoJSON feature:

json.features[0]:

Object
geometry: Object
coordinates: Array[2]
0: -71.248913
1: 44.078426
length: 2
__proto__: Array[0]
type: "Point"
__proto__: Object
id: 2
type: "Feature"
__proto__: Object

and

json.features[1]:

Object
geometry: Object
coordinates: Array[2]
0: -71.249021
1: 44.078387
length: 2
__proto__: Array[0]
type: "Point"
__proto__: Object
id: 3
type: "Feature"
__proto__: Object

If I execute

d3.geo.bounds(json.features)

I get infinity for the bounds:

d3.geo.bounds(json.features)
[
Array[2]
0: Infinity
1: Infinity
length: 2
__proto__: Array[0]
, 
Array[2]
0: -Infinity
1: -Infinity
length: 2
__proto__: Array[0]
]

I'm unsure what is wrong, clearly I have a much larget dataset than above, but I'm just trying to understand the output. This output does not make sense to me and clearly missing something simple about d3 handling of geoJSON data. Any help to get the bounds to work would be helpful.

Thanks.

解决方案

d3.geo.bounds takes a single Feature or a FeatureCollection as argument, not an array of features. See the documentation. You need to call e.g.

d3.geo.bounds(json.features[0])

If you want a bounding box that contains all features, you need to get the bounding box for each one in turn and then calculate the union of those.

这篇关于d3.js geoJSON和bounds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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