2017-09-22 1 views
0

Je souhaite générer un fichier geojson à partir de mon application rails à l'aide de rgeo-geojson. J'ai une table de points avec lat et long.Comment générer un fichier geojson à partir d'une collection

J'ai mis mon contrôleur dans la manière standard

respond_to do |format| format.html format.csv { send_data @nodes_for_map.to_csv } format.json { send_data @nodes_for_map.as_geo_json } end

Comment ne pas créer la GeoJSON de la collection?

RGEO-GeoJSON FeatureCollection

Répondre

1

Cela répondra avec un corps JSON:

format.json { render json: RGeo::GeoJSON.encode(@nodes_for_map).to_json } 

Cela répondra avec un fichier JSON:

format.json do 
    send_data RGeo::GeoJSON.encode(@nodes_for_map).to_json, 
    filename: "whatever.json", 
    type: "text/plain" 
end 
+0

grâce à cela. Comment est-ce que je m'assure que mon @nodes_for_map a les champs corrects (lat, long etc.) et place les propriétés (la couleur de marqueur pour par exemple)? – Will