2016-05-10 5 views

答えて

2

これは私自身のデータの一部で動作しますが、これには小さなバリエーションが必要です。ここでは、領域を計算し、REQ_AREAよりgreatedされることに応じて、trueまたはfalseを返すフィルタリング関数を提供しています。また、匿名関数を.createIndex('area', function(doc) { ... }に渡し、そのインデックスを使用してgetAllを実行することによって、この計算を自動的に実行するインデックスを作成することもできます。

.sliceおよびprepend | appendingは、単純な乗算マッピングのためにx座標とy座標を回転させるだけです。ここで

はReQL面積計算外だけれども次のようになります。そのため

r.db('geography').table('area_polygons').filter((doc) => { 

    // Retrieve just the points of the polygon 
    var coords = doc('polygon').toGeojson()('coordinates').nth(0) 

    var x_coords = coords.map((point) => {return point.nth(0)}).coerceTo('array'); 
    var y_coords = coords.map((point) => {return point.nth(1)}).coerceTo('array'); 

    // Move item from beginning to end 
    y_coords = y_coords.append(y_coords.slice(0,1).nth(0)).deleteAt(0); 
    var x = r.map(x_coords, y_coords, (l, r) => { return l.mul(r) }).sum(); 

    // Reset y and now move first x item to end 
    y_coords = y_coords.prepend(y_coords.slice(-1).nth(0)).deleteAt(-1); 
    x_coords = x_coords.append(x_coords.slice(0,1).nth(0)).deleteAt(0); 
    var y = r.map(x_coords, y_coords, (l, r) => { return l.mul(r) }).sum(); 

    // Return area 
    return x.sub(y).div(2) > REQ_SIZE ? true : false; 
}) 
+0

素敵=)ありがとう! – zcaudate

関連する問題