/ Published in: JavaScript
The Flickr URL creates a JSON feed with geo-based photos. Using Node.js, CouchDB, and cradle (npm install cradle), you can ingest the JSON data into CouchDB and perform complicated spatial indexing queries. The command for the import is bash$ node nameofthis_javascript.js
Expand |
Embed | Plain Text
var cradle = require("cradle"), sys = require("sys"), fs = require("fs"); var connection = new(cradle.Connection)("localhost", 5984); var db = connection.database('geoexample'); data = fs.readFileSync("./json/data_flickr.json", "utf-8"); flickr = JSON.parse(data); for(p in flickr.photos.photo){ photo = flickr.photos.photo[p]; photo.geometry = {"type":"Point", "coordinates": [ photo.longitude, photo.latitude ] }; // Save the url to the flickr image. // http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstzb].jpg photo.image_url_small = "http://farm"+photo.farm+".static.flickr.com/"+photo.server+"/"+photo.id+"_"+photo.secret+"_s.jpg"; db.save(photo.id, photo, function(er, ok) { if (er) {sys.puts("error: "+er); return;} }); }
You need to login to post a comment.
