2013-06-05 8 views
12

Wenn ich die Spezifikationen von GeoJSON sehen Ich sehe, dass Kreise unterstützt:Geojson Kreise, unterstützt oder nicht?

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

Wenn ich den Code in geojsonlint ausprobieren (http://geojsonlint.com/) aber es mir einen Fehler gibt.

Eingang:

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

Gibt:

"Circle" is not a valid GeoJSON type. 

Ich mag mit Hilfe d3 verschiedene Orte von Interesse mit einer Reihe von Einfluss auf einer Karte zeigen. Es benötigt GeoJson für die Eingabe, aber es stimmt, dass Kreise bei GeoJson nicht unterstützt werden.

+0

Sie caould außer Kraft setzen 'L.Circle.toGeoJSON()', um zusätzliche Eigenschaften hinzufügen, um anzuzeigen, dass der Punkt sollte als Kreis dargestellt werden: https://github.com/Leaflet/Leaflet/issues/2888 Obwohl Es ist nicht Standard, es gibt Ihnen die Metadaten zu wissen, um als ein Kreis darzustellen. –

+0

Ah ja, aber das wird mit dem Leaflet api gelöst. Dies würde funktionieren, aber Sie würden nicht Geojson per se verwenden, würden Sie die Funktionalität verwenden, die Ihnen die Broschüre bietet. D3 bietet eine ähnliche Lösung, die unabhängig von der verwendeten Zuordnungsbibliothek ist. – cantdutchthis

Antwort

19

Wenn ich die Spezifikationen von GeoJSON sehen Ich sehe, dass Kreise

unterstützt werden sie nicht sind. Scheint du hast es geschafft, einige falsche oder falsche Spezifikationen zu finden. Gehe zu geojson.org, um die specs zu finden, es gibt nichts über Kreise.

+1

Ich denke, er fand etwas im Entwurf oder Vorschläge wie hier https://github.com/geojson/geojson-spec/issues/1 oder https://github.com/geojson/geojson-spec/wiki/Proposal--- Kreise-und-Ellipsen-Geome –

2

Kein Kreis Unterstützung von GeoJSON, aber Sie können Linestring verwenden, um einen Kreis

verwenden, um ein Objekt Linestring 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, 
    }; 
    } 

zu simulieren wie ein Kreis auf der Karte aussieht.

+0

Kann auch mit einem 'Punkt' gemacht werden, ich bin mir ziemlich sicher ... –

-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

Willkommen bei SO! Bitte beachten Sie, dass diese Frage aus dem Jahr 2013 (vor 4 Jahren!) Stammt. Natürlich können Sie auch alte Posts beantworten, aber stellen Sie in diesem Fall sicher, dass Ihre Antwort besser ist als die vorherige. Dies kann dank neuer Technologie, Bibliothek usw. sein. In diesem speziellen Fall bin ich mir jedoch nicht sicher, ob Ihr Beitrag eine Antwort auf die Frage liefert: Der Punkt ist nicht, wie ein Kreis gezeichnet wird, sondern ob Kreismetadaten in GeoJSON gültig sind Format. – ghybs