Return to Snippet

Revision: 57098
at May 16, 2012 02:12 by chrisaiv


Initial Code
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;}
        });
}

Initial URL
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=API_KEY&text=kitty+kat&has_geo=true&extras=geo&per_page=1000&format=json&nojsoncallback=1

Initial Description
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 name_of_this_javascript.js

Initial Title
Node.js: Import geo-based Flickr data into CouchDB

Initial Tags

                                

Initial Language
JavaScript