| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 
 | var sqlite = require('spatialite');
var db = new sqlite.Database('IDF.db');
var query = "SELECT name, AsGeoJSON(geom) as geojson from minor_roads UNION SELECT name, AsGeoJSON(geom) as geojson from major_roads;";
var i =0;
var elasticsearch = require('elasticsearch');
var async = require('async');
 
var client = new elasticsearch.Client({
  host: 'localhost:9200',
  //og: 'trace',
  requestTimeout : 3600000,
  deadTimeout : 3600000,
});
 
function indexIt(row, cb) {
       var geojson = JSON.parse(row.geojson);
            geojson.name = row.name;
            console.log(row.id + " " +row.name);
 
            client.index({
                  index: 'e42',
                  type: 'roads',
                  body: geojson,
            }, function (error, response) {
                if (error)  console.log(error);
                cb(error, response )
            });
}
 
db.spatialite( function(err){
    db.all(query, function(err, rows){
        if (err) throw err;
 
        async.eachSeries(rows, indexIt, function(error) {
            if (err)  throw err;
            console.log('All files have been processed successfully');
        });
 
    });
}); | 
Partager