私は、インドのウッタル・プラデシュにある様々な地区の境界を含むTopoJSONファイルを持っています。地図上にデータをロードすると、地区のアウトラインのみが表示されます。地区自体は満たされていません。TopoJSON線ストリングをポリゴンに変換するにはどうすればよいですか?
私は問題は、各地区がLineString
で構成された独自のgeometries
を持つタイプGeometryCollection
であると考えています。
代わりに、各地区のタイプをPolygon
とし、ちょうどarcs
とします。
例えば、第1の目的は次のとおりです。
{
"type": "GeometryCollection",
"geometries": [{
"type": "GeometryCollection",
"properties": {
"district_number": 1,
"district_name": "Ghaziabad"
},
"geometries": [{
"type": "LineString",
"arcs": [0]
}, {
"type": "LineString",
"arcs": [1]
}, {
"type": "LineString",
"arcs": [2]
}, {
"type": "LineString",
"arcs": [3]
}, {
"type": "LineString",
"arcs": [4]
}, {
"type": "LineString",
"arcs": [5]
}]
}
私はそれを変換したいと思うし、他のすべてのオブジェクトに:
{
"type": "Polygon",
"properties": {
"district_number": 1,
"district_name": "Ghaziabad"
},
"arcs": [[0,1,2,3,4,5]]
}
私はそれを手動で修正することができ、それはそう狂ったより良い方法がありますか?
更新
だから、私は私が欲しかったと思ったが、私はいくつかの非常に奇抜なポリゴンを得た結果にオブジェクトを変換する方法を考え出しました。ここに私の(非常にclunky)コードです。これに関するいくつかの指針については、Saeed Adel Mehrabanに感謝します。
d3.json('map.topojson',function(error,data){ // get my json that needs to be converted
var arr = data.objects.collection.geometries; // this is the relevant array
var newArr = []; // in order to map each object, i need to put each one into a new array as a single-item array
arr.forEach(function(d,i){
var curr = [d];
newArr.push(curr);
})
newArr.forEach(function(e,i){ // now that i have my new array, i want to convert each object that contains a LineString into a Polygon
var output = e.map(function(d){
var arcsArr = []; // an empty array to push each single value of the LineString arcs into
return {
"type": "Polygon", // change the type to polygon
"properties": d.properties, // keep the properties
"arcs": d.geometries.map(function(g) { // a single key-value pair for arcs, made up of the individual arcs from the LineString
arcsArr.push(g.arcs[0]);
return [arcsArr]; // the array of arcs must be in another array
})
};
});
var output = output[0]; // get only the first item in the output array, which is the object i have modified
output.arcs = output.arcs[0]; // and change the arcs so we're only taking the first array (as we've duplicated the arrays)
$('body').append(JSON.stringify(output)+','); // append the whole thing to the body so I can copy it and paste it into the appropriate part of the JSON
});
});
この私のLineString
sは確かにオリジナルのボーダーを保持、Polygon
秒に変換されたという意味で「働いていました」。しかし、ポリゴンそのものは悪夢であり、直線をすべての種類の角度で地図を十字架にしています。
LineString
の境界をPolygon
に変換できるコマンドラインツールのようなものがありますか?
同様に、GeoJSONファイル形式でこれを変換できます。しかし、私はまだそれを行う良い方法を見つけていない。 –