The goal is to add external properties to a TopoJSON. I have succeeded in converting shapefiles from http://www.diva-gis.org/gdata for various countries into JSON files. I have also succeeded in down-sampling these files to a more front-end friendly file-size. Like this:
shp2json CHN_adm0.shp --out CHN_adm0.json geo2topo CHN_adm0.json > china.json shp2json CHN_adm1.shp --out CHN_adm1.json geo2topo CHN_adm1.json > china.json toposimplify -s 1e-9 -f < china.json > china-topo.json toposimplify -s 1e-9 -f < china1.json > china1-topo.json
Then I merged the country level polygons with the provincial level polygons. And perhaps this is where I might append external properties if this is correct, but as you will see I may have an additional hurdle:
geo2topo regions=CHN_adm1.json country=CHN_adm0.json > china-regions-topo.json toposimplify -s 1e-9 -f < china-regions-topo.json > china-regions.json
What I am unsure with at this juncture is how one appends properties to data from diva-gis. Here is an example slice of the dict/object and relevant keys of what my china-regions.json ended up like (note: I'm using Python to explore the JSON file, but I'm not really going to use Python for anything else in question):
len(json['objects']['regions']['geometries']) >> 31 ## 31 provinces in China json_data['objects']['regions'].keys() >> dict_keys(['type', 'bbox', 'geometries']) ## seems like there is nothing to map to, like an id or province name
How do I add external properties to TopoJSONs that I have converted from shapefiles from diva-gis? It appears there is nothing to map to. I can't even tell which province is which after exploring the data; it's just a list of arcs -- which plot on a map well enough, but there is nothing intuitive for a human to discern which province is which.
- External property format is arbitrary; just imagine a CSV with province name and a number, say population of province.
- Not opposed to putting in some elbow grease, but I'd like to avoid trial and error as much as possible
- Order of the regions in the JSON file is unknown. Not sure whether or not diva-gis would adhere to any particular convention (alphabetical order, ect)