2016-03-29 3 views
0

マルチジオメトリで同じプロパティを持つTopoJSONジオメトリをグループ化できるかどうかは知りませんか?特定のプロパティによるTopoJSONジオメトリのグループ化

例として、領域の標高等値を持つTopoJSONを指定すると、プロパティを保持しながら同じ標高のジオメトリをグループ化することが可能になります。

私はTopoJSONのドキュメントでこれを見つけた: https://github.com/mbostock/topojson/blob/master/bin/topojson-group

私はそれが異なる高さのためのIDを使用しますが、出力が(でも、-pパラメータを使用して)のプロパティを保持していないテスト。

答えて

0

を使用して、topojsonをgeojsonの機能に変換します。その後、標高に基づいてフィーチャをグループ化できます。 geojson-groupbyを使用して任意の属性に基づいてグループ化し、mutligeojsonを使用してジオメトリをMultiGeometryに結合することができます。

var features = [f1, f2, ..,fn] 
var grouped = GeoJSONGroupBy(features, 'properties.elevation'); 
// grouped is 
// { 
// '100': [f1, f3, ..], 
// '200': [f5, f8, f6, ..], 
//  .... 
// } 
var merged = {}; // final output merged with geometry and other attributes 
Object.keys(grouped).reduce(function(merged,groupKey) { 
    var group = grouped[groupKey]; 
    var reduced = { 
    geomCollection: [] 
    attributes: { 
     elevation: group[0].attributes.elevation, 
     length: 0 // any other that you want to include 
    } 
    }; 
    group.reduce(function(reduced, cur) { 
    reduced.geomCollection.push(cur.geometry); 
    reduced.attributes.length += length(cur.geometry); //length functon 
    },reduced); 
    return { 
    type: 'Feature', 
    geometry: multigeojson.implode(reduced.geomCollection), 
    attributes: reduced.attributes 
    } 
},merged); 
関連する問題