使用topojson命令向TopoJSON文件添加属性不会从外部csv加载数据

时间:2016-05-26 20:22:09

标签: javascript json csv d3.js topojson

我正在尝试将一些数据从csv绑定到topojson文件,但来自csv的数据没有被添加到topojson对象的属性中。 Here is the csv file以及其中一部分的示例:

GEO.id,GEO.id2,GEO.display-label,HC01_EST_VC21,HC01_EST_VC22,HC01_EST_VC23
Id,Id2,Geography,Total; Estimate; Population 18 years and over,Total; Estimate; Population 18 years and over - Enrolled in college or graduate school %,Total; Estimate; Population 18 years and over - Enrolled in college or graduate school #
1400000US06001400100,6001400100,"Census Tract 4001, Alameda County, California",3056,25.5,779
1400000US06001400200,6001400200,"Census Tract 4002, Alameda County, California",1619,4.3,70

Here is the topojson I'm trying to bind the data to以及部分示例:

{"type":"Topology","objects":{"cb_2015_06_tract_500k":{"type":"GeometryCollection","bbox":[-124.409591,32.534155999999996,-114.131211,42.009518],"geometries":[
{"type":"Polygon","properties":{"STATEFP":"06","COUNTYFP":"001","TRACTCE":"400600","AFFGEOID":"1400000US06001400600","GEOID":"06001400600","NAME":"4006","LSAD":"CT","ALAND":297856,"AWATER":0},"arcs":[[0,1,2,3,4]]},
{"type":"Polygon","properties":{"STATEFP":"06","COUNTYFP":"001","TRACTCE":"400900","AFFGEOID":"1400000US06001400900","GEOID":"06001400900","NAME":"4009","LSAD":"CT","ALAND":420877,"AWATER":0},"arcs":[[5,6,7,8]]},

我使用了命令topojson -o out.json -e education_dataset.csv --id-property=GEOID,GEO.id2 -p population=+HC01_EST_VC01 -- ca-tracts.jsonHC01_EST_VC01从csv绑定到topojson中的population属性,但输出没有任何属性。我还尝试了命令topojson -o out.json -e education_dataset.csv --id-property=AFFGEOID,GEO.id -p population=+HC01_EST_VC01 -- ca-tracts.json,因为topojson具有AFFGEOIDGEOID属性,分别对应于csv GEO.idGEO.id2中的列。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

  1. 对于--id-property,可能不能用作Ge0.id2,将其更改为GEO。

  2. 对于--id-property,在topojson中你的GEOID为“06001440335”,你的GEO.id2是6001440335。所以你应该在它们面前保持+符号以便它可以作为数字进行比较 的 - 编号属性= + GEOID,+ GEO

  3. HC01_EST_VC01在给定的csv文件中不存在

  4. 我将Geo.id2更改为GEO并使用“HC01_EST_VC21”进行填充后所做的工作命令是

    topojson -o out.json -e education_dataset.csv --id-property = + GEOID,+ GEO -p population = HC01_EST_VC21 - ca-tracts.json

    随时提出更多疑问