2013-06-05 14 views
12

Quando guardo le specifiche di GeoJSON vedo che i cerchi sono supportati:cerchi geojson, supportati o no?

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

Quando provo il codice a geojsonlint (http://geojsonlint.com/), tuttavia, mi dà un errore.

ingresso:

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

Dà:

"Circle" is not a valid GeoJSON type. 

voglio mostrare diversi luoghi di interesse con una gamma di influenza su una mappa utilizzando d3. Ha bisogno di GeoJson per l'input, ma è vero che le cerchie non sono supportate da GeoJson?

+0

È caould sovrascrivere 'L.Circle.toGeoJSON()' per aggiungere ulteriori proprietà per indicare che il punto dovrebbe essere rappresentato come un cerchio: https://github.com/Leaflet/Leaflet/issues/2888 Anche se non è standard, ti dà i metadati per sapere di rappresentare come un cerchio. –

+0

Ah sì, ma questo sarà risolto usando l'opuscolo Leaflet. Questo funzionerebbe, ma non utilizzeresti geojson di per sé, useresti la funzionalità fornita dal volantino. D3 offrirebbe una soluzione simile indipendente dalla libreria di mapping che si utilizza. – cantdutchthis

risposta

19

Quando guardo le specifiche di GeoJSON vedo che i cerchi sono supportati

Essi non sono. Sembra che tu sia riuscito a trovare alcune specifiche false o errate. Vai a geojson.org per trovare lo specs, non c'è niente riguardo ai cerchi.

+1

Penso che abbia trovato qualcosa nella bozza o nelle proposizioni come qui https://github.com/geojson/geojson-spec/issues/1 o https://github.com/geojson/geojson-spec/wiki/Proposal--- Cerchi-ed-ellissi-Geomi –

2

Nessun supporto cerchio da GeoJSON, ma è possibile utilizzare per simulare LineString un cerchio

utilizzare una stringa lineare geiometry oggetto

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

appare come un cerchio sulla mappa.

+0

Può anche essere fatto con un 'Punto', sono abbastanza sicuro ... –

-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

Benvenuti in SO! Si prega di notare che questa domanda risale al 2013 (4 anni fa!). Naturalmente puoi ancora rispondere ai vecchi post, ma in tal caso assicurati di evidenziare perché la tua risposta è migliore della precedente. Questo potrebbe essere grazie alla nuova tecnologia, alla biblioteca, ecc. In questo caso specifico, non sono sicuro che il tuo post fornisca una risposta alla domanda: il punto non è come disegnare un cerchio, ma se i metadati del cerchio sono validi in GeoJSON formato. – ghybs