2013-06-05 49 views
12

当我仰望以GeoJSON的规格我看到圈的支持:geojson圈子,支持与否?

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

当我尝试在geojsonlint(http://geojsonlint.com/)的代码,但是,它给了我一个错误。

输入:

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

给出:

"Circle" is not a valid GeoJSON type. 

我想通过使用D3,以显示与地图上的范围内的影响力的利益不同的地方。它需要GeoJson进行输入,但确实没有GeoJson支持圆圈?

+0

您caould覆盖'L.Circle.toGeoJSON()'添加额外的属性,以表明该点应表示为一个圆圈:https://github.com/Leaflet/Leaflet/issues/2888虽然它不是标准的,它会给你知道元数据来表示为一个圆圈。 –

+0

啊是的,但这将通过使用Leaflet api解决。这可行,但你不会使用geojson本身,你会使用传单给你的功能。 D3会提供一个独立于您使用的映射库的类似解决方案。 – cantdutchthis

回答

19

当我仰望以GeoJSON的规格我看到圆圈支持

他们不是。似乎你设法找到一些假的或不正确的规格。去geojson.org找到specs,没有什么关于圈子的。

+1

我认为他在草稿或命题中找到了一些像https://github.com/geojson/geojson-spec/issues/1或https://github.com/geojson/geojson-spec/wiki/Proposal---圆形和椭圆形 - Geoms –

2

从GeoJSON的, 没有圈子的支持,但是你可以用线段形式来模拟一个圆

使用线段形式geiometry对象

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

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

+0

也可以用'Point'来完成,我很确定... –

-1
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! 
-- 
+2

欢迎来到SO!请注意,这个问题从2013年开始(4年前!)。当然,你仍然可以回答旧帖子,但在这种情况下,一定要强调为什么你的答案比以前更好。这可能要归功于新技术,图书馆等。在这个特定的情况下,我不确定你的帖子是否提供了一个问题的答案:问题不在于如何绘制圆圈,而是如果圆圈元数据在GeoJSON中有效格式。 – ghybs