2013-06-05 50 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