json - How to add properties to topojson file? -
given data.tsv file such :
id code name 1 al alabama 2 ak alaska 4 az arizona 5 ar arkansas 6 ca california ... ... ...
given topojson.json file such : (the structure correct, numeral values random)
{ "type":"topology", "transform": { "scale": [0.0015484881821515486,0.0010301030103010299], "translate":[-5.491666666666662,41.008333333333354] }, "objects": { "states": { "type":"geometrycollection", "geometries": [ {"type":"polygon","arcs":[[0]],"properties":{"code_2":"al"}}, {"type":"polygon","arcs":[[1]],"properties":{"code_2":"ak"}} ] } }, "arcs": [ [[2466,9916],[-25,-5],[3,-13]], [[2357,9852],[1,-2],[1,-2]] ] }
how use common fields(1) inject values of other field(2) json file ?
1]: data.txt#code
, topojson.txt.objects.states.geometries.properties.code_2
2]: data.txt#name
the end result should contains :
{"type":"polygon","arcs":[[0]],"properties":{"code_2":"al", "name":"alabama" }}, {"type":"polygon","arcs":[[1]],"properties":{"code_2":"ak", "name":"alaska" }},
edit: accepted answer:
topojson -o final.json -e data.tsv --id-property=code_2,code -p code_2,state=name -- topojson.json
try using this:
topojson -o final.json -e data.tsv --id-property=code_2,code -p code_2,state=name -- topojson.json
which should output:
{ "type": "topology", "transform": { "scale": [ 0.000016880209206372492, 0.000007005401010148724 ], "translate": [ -1.8418800213354616, 51.15278777877789 ] }, "objects": { "states": { "type": "geometrycollection", "geometries": [ { "type": "polygon", "arcs": [ [ 0 ] ], "id": "ak", "properties": { "code_2": "ak", "state": "alaska" } } ] } }, "arcs": [ [ [ 0, 588 ], [ 92, -294 ], [ 91, -294 ], [ -183, 588 ] ] ] }
from command line reference wiki:
--id-property name of feature property promote geometry id
by using code_2
property option, promote feature id.
prepend + in front of input property name coerce value number.
plus:
if properties referenced --id-property null or undefined, omitted output geometry object. thus, generated objects may not have defined id if input features did not have property specified name.
so, when using +code
, +code_2
, undefined
, can't convert ak
string value number.
here, input property "fips" coerced number , used feature identifier; likewise, column named "fips" used identifier in csv file. (if csv file uses different column name feature identifier, can specify multiple id properties, such
--id-property=+fips,+id
.)
that's why have add code
--id-property=code_2,code
option. how mapping made (the code_2
topojson.json , code
column data.tsv).
then, output property "unemployment" generated external data file, unemployment.tsv, defines input property "rate"
in our case, -p code_2,state=name
specifies preserve code_2
property , rename name
property state
. properties , external properties sections in aforementioned documentation wiki pretty informative on matter.
Comments
Post a Comment