【问题标题】:How to merge topojson and csv when properties is not present当属性不存在时如何合并 topojson 和 csv
【发布时间】:2024-05-04 03:30:04
【问题描述】:

我无法将 csv 与 topojson 文件合并。

我想将rate 列作为属性添加到topojson 文件中。

我的 csv 是这样的:

index,id,county,rate,error
1,1001,"Autauga County, Alabama",12.1,1.8
2,1003,"Baldwin County, Alabama",13.9,1.2
3,1005,"Barbour County, Alabama",26.7,2.6

我的topojson是标准的美国县地图:

{"type":"Topology",

"objects":{"counties":

{"type":"GeometryCollection","bbox":[-179.1473399999999,17.67439566600018,179.7784800000003,71.38921046500008],

"geometries":[

{"type":"MultiPolygon","id":53073,"arcs":[[[0,1,2]]]},{"type":"Polygon","id":30105,"arcs":[[3,4,5,6,7,8]]},

我正在尝试以下命令:

topojson -o final.json -e county_level1.csv --id-property=id,id -p id,rate=rate -- us.json

但它只是从 topojson 文件中删除 id 属性。

这里是a related question,但更新了解决方法。

【问题讨论】:

    标签: csv topojson


    【解决方案1】:

    我最终使用了 Mike Bostock 的 US-Atlas,然后使用了以下 makefile:

    topo/us-counties-10m-ungrouped.json: shp/us/counties.shp
        mkdir -p $(dir $@)
        node_modules/.bin/topojson \
            -o $@ \
            --no-pre-quantization \
            --post-quantization=1e6 \
            --id-property='+FIPS' \
            --external-properties=county_level1.csv \
            --properties="county=county" \
            --properties="rate_2006=+rate_2006" \
            --properties="rate_2008=+rate_2008" \
            --properties="rate_2010=+rate_2010" \
            --properties="rate_2012=+rate_2012" \
            --properties="rate_2013=+rate_2013" \
            --properties="error_2013=+error_2013" \
            --properties="attainment_2006=+attainment_2006" \
            --properties="attainment_2008=+attainment_2008" \
            --properties="attainment_2010=+attainment_2010" \
            --properties="attainment_2012=+attainment_2012" \
            --properties="attainment_2013=+attainment_2013" \
            --properties="snap_2006=+snap_2006" \
            --properties="snap_2008=+snap_2008" \
            --properties="snap_2010=+snap_2010" \
            --properties="snap_2012=+snap_2012" \
            --properties="snap_2013=+snap_2013" \
            --properties="single_2006=+single_2006" \
            --properties="single_2008=+single_2008" \
            --properties="single_2010=+single_2010" \
            --properties="single_2012=+single_2012" \
            --properties="single_2013=+single_2013" \
            --simplify=7e-7 \
            -- $<
    

    【讨论】: