19

When I look up the specs of GeoJson I see that circles are supported:

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

When I try out the code in geojsonlint (http://geojsonlint.com/) however, it gives me an error.

Input:

{ 
"type": "Circle",
"coordinates": [4.884, 52.353],
"radius": 200
}

Gives:

"Circle" is not a valid GeoJSON type. 

I want to show different places of interests with a range of influence on a map by using d3. It needs GeoJson for input but it is true that circles are not supported with GeoJson?

4

4 回答 4

34

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

他们不是。似乎您设法找到了一些虚假或不正确的规格。去 geojson.org 查找规格,没有关于圆圈的内容。

于 2013-06-05T15:47:46.397 回答
18

正如接受的答案所解释的,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);

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

于 2018-04-25T18:33:17.417 回答
9

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,
    };
  }

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

于 2016-11-16T07:07:57.887 回答
0
A circle... some code I use for making a circle for an OpenStreetMap

-- x is decimal latitude
-- y is decimal longitude
-- r is radius --  .00010 is about 40m in OSM (3 about 50km)

-- Adjust for map latitude distortion further north or south

x = math.log(math.tan((90 + x) * math.pi/360)) / (math.pi/180)

-- For loop to gather all the points of circle here 1 to 360
-- can also use the for loop to make some other interesting shapes

for i = 1, 360 do
    angle = i * math.pi / 180
    ptx = x + r * math.cos( angle )
    pty = y + r * math.sin( angle )

-- readjust latitude for map distortion

    ptx = 180/math.pi * (2 * math.atan(math.exp( ptx * math.pi/180)) - math.pi/2 )

-- Build an array of positions for GeoJSON - formatted lat and long

    data[i] = '[' .. string.format("%.6f",pty) .. ","
    data[i] = data[i] .. string.format("%.6f",ptx) .. ']'

-- End of for loop
end

-- Cycle through the data array with another for loop to build the
   coordinates (put in brackets and commas etc. for the actual
   GeoJSON coordinates string. Add data[1] to the end to close
   the polygon (circle). A circle.

-- If you want a solid circle then use fill and a hex color
-- If you want a LineString just make fill invisible or #ffffff
      Include the stroke-width and stroke-color parameters as well.
-- If latitude is greater than 89.5 or less than -89.5 you may wish
   to cut off the circle by drawing a line at polar regions by using
   those latitudes.
-- I use this simply for several circles and not for hundreds of them.

Cheers!
-- 
于 2017-05-24T00:17:24.703 回答