geojson圈子,支持与否?

can*_*his 13 maps geojson d3.js leaflet

当我查看GeoJson的规格时,我看到支持圆圈:

http://geopriv.dreamhosters.com/geojson/geojson-spec.html#circleExample

当我尝试使用geojsonlint(http://geojsonlint.com/)中的代码时,它会给我一个错误.

输入:

{ 
"type": "Circle",
"coordinates": [4.884, 52.353],
"radius": 200
}
Run Code Online (Sandbox Code Playgroud)

得到:

"Circle" is not a valid GeoJSON type. 
Run Code Online (Sandbox Code Playgroud)

我想通过使用d3来显示不同的兴趣点,并对地图产生一系列影响.它需要GeoJson作为输入,但是GeoJson不支持圆圈吗?

L. *_*nna 25

当我查看GeoJson的规格时,我看到圈子得到了支持

他们不是.似乎你设法找到一些假的或不正确的规格.转到geojson.org查找规格,没有关于圈子的信息.


小智 8

geojson 不支持圆,但您可以使用 LineString 来模拟圆

使用 LineString 几何对象

"geometry": {
        "type": "LineString",
        "coordinates": [
                    [center_X, center_y],
                    [center_X, center_y]
                ]
      }
then set the dynamic style use radius as the strokeweight
function featureStyle(feature){
    return {
      strokeWeight: radius,
    };
  }
Run Code Online (Sandbox Code Playgroud)

它在地图上看起来像一个圆圈。


arg*_*g20 7

正如公认的答案所解释的那样,GeoJson规范不支持圆圈.

但是,大多数地图实现都可以让你创建圆圈,但是如果这对你不起作用(例如,你需要将它存储在数据库中并进行查询),解决方案是创建一个大致近似圆形的多边形(想象一个有32个边缘的多边形).

我写了一个模块来做到这一点.你可以像这样使用它:

const circleToPolygon = require('circle-to-polygon');

const coordinates = [-27.4575887, -58.99029]; //[lon, lat]
const radius = 100;                           // in meters
const numberOfEdges = 32;                     //optional that defaults to 32

let polygon = circleToPolygon(coordinates, radius, numberOfEdges);
Run Code Online (Sandbox Code Playgroud)

为了澄清为什么不支持圆圈,它与地球的曲率有关.因为地球不是一个完美的球体,如果你在它上面绘制一个圆形,它也不是一个完美的圆形.但是,上述解决方案适用于大多数情况,您不需要严格的精度.