Python: как объединить CSV с TopoJSON - PullRequest
0 голосов
/ 30 января 2019

Я следую этому учебнику, чтобы сделать карту хороплета в .D3.

У меня есть файл topoJson, который показывает окрестности Сан-Франциско.

Вот пример:

{"type":"Topology","arcs":[[[129720,16294],[0,1],[0,-1],[0,0]],[[129720,16294],[0,-1],[0,0],[0,-1],[0,0],[1,-1],[0,0],[0,-1],[0,0],[0,-1],[0,-1],
[THE MIDDLE IS OMITTED. IT'S JUST LOTS AND LOTS OF NUMBERS]
[-66,88],[-301,96],[-380,122],[-89,-37],[-62,80],[-292,93],[-400,87],[-87,-36],[-79,75],[-655,142],[-552,14],[-183,-64],[-71,-91],[38,139],[-335,533],[-142,36],[155,27],[301,398],[76,219],[-27,359],[-189,294],[-634,879],[-127,32],[-13,103],[-754,983],[-146,243],[-482,1359],[-372,650],[-105,78]],[[107977,293],[-75,-3],[-940,-10],[-802,2],[-458,-2],[-353,-20],[-4189,2],[-966,0],[-1021,2],[-942,-1],[-932,-1],[-795,3],[-128,0],[-940,0],[-34,-4],[-807,3],[-216,2],[-461,0],[-364,2],[-3641,12]]],"transform":{"scale":[0.000001014113972405492,7.500337955979233e-7],"translate":[-122.51494757950903,37.70813199967893]},
"objects":{"sanfran":{"type":"GeometryCollection","geometries":[{"arcs":[[0,1,2,3,4,5,6]],"type":"Polygon","properties":{"nhood":"Bayview Hunters Point"}},{"arcs":[[7,8,9,10,11,12,13,-5]],"type":"Polygon","properties":{"nhood":"Bernal Heights"}},{"arcs":[[14,15,16,17,18,19]],"type":"Polygon","properties":{"nhood":"Castro/Upper Market"}},{"arcs":[[20,21,22,23]],"type":"Polygon","properties":{"nhood":"Chinatown"}},{"arcs":[[24,25,26,27,28,-9]],"type":"Polygon","properties":{"nhood":"Excelsior"}},{"arcs":[[[31,32]],[[33,34]],[[35,36]],[[37,38,39,40,41,-21,42]]],"type":"MultiPolygon","properties":{"nhood":"Financial District/South Beach"}},{"arcs":[[-11,43,44,45,46]],"type":"Polygon","properties":{"nhood":"Glen Park"}},{"arcs":[[47,48,49,50,51,52]],"type":"Polygon","properties":{"nhood":"Inner Richmond"}},{"arcs":[[53,54,55,56,57,58,-49,59]],"type":"Polygon","properties":{"nhood":"Golden Gate Park"}},{"arcs":[[-18,60,-55,61]],"type":"Polygon","properties":{"nhood":"Haight Ashbury"}},{"arcs":[[-19,-62,-54,62,63,64,65]],"type":"Polygon","properties":{"nhood":"Hayes Valley"}},{"arcs":[[-61,-17,66,67,68,-56]],"type":"Polygon","properties":{"nhood":"Inner Sunset"}},{"arcs":[[69,70,71]],"type":"Polygon","properties":{"nhood":"Japantown"}},{"arcs":[[72,-26,73]],"type":"Polygon","properties":{"nhood":"McLaren Park"}},{"arcs":[[-65,74,75,-41,76,77]],"type":"Polygon","properties":{"nhood":"Tenderloin"}},{"arcs":[[78,79,80,81]],"type":"Polygon","properties":{"nhood":"Lakeshore"}},{"arcs":[[82,83,84]],"type":"Polygon","properties":{"nhood":"Lincoln Park"}},{"arcs":[[-63,-60,-48,85,86]],"type":"Polygon","properties":{"nhood":"Lone Mountain/USF"}},{"arcs":[[[87,88,89,90,91,92,93,94,95,96,97,98,99,100,101]],[[102,103]],[[104,105]],[[106,107]],[[108,109]],[[110,111]],[[112,113]],[[114,115]],[[116,117]]],"type":"MultiPolygon","properties":{"nhood":"Marina"}},{"arcs":[[[122,-23,123,124,-95,125]],[[-99,126,-103,127,-106,128,-107,129,-110,130,-111,131,-114,132,-115,133,-117,134]],[[135,136]]],"type":"MultiPolygon","properties":{"nhood":"Russian Hill"}},{"arcs":[[137,138,-13,139,-20,-66,-78,140]],"type":"Polygon",

Вот полный файл .

Я хочу объединить мой CSV с topoJSON.

nhood,popdensity
Bayview Hunters Point,11.4
Bernal Heights,37.9
Castro/Upper Market,38.4
Chinatown,103.1
Excelsior,44.2
Financial District/South Beach,24.3
Glen Park,19.2
Golden Gate Park,0.1
Haight Ashbury,50.7
Hayes Valley,58.1
Inner Richmond,47.2
Inner Sunset,32
Japantown,47.3
Lakeshore,7.8
Lincoln Park,1.3
Lone Mountain/USF,48.7
Marina,38.3
McLaren Park,2.2
Mission,48.6
Mission Bay,20.2
Nob Hill,97
Noe Valley,39.1
North Beach,39.4
Oceanview/Merced/Ingleside,41.6
Outer Mission,37.8
Outer Richmond,39.2
Pacific Heights,47.3
Portola,31.1
Potrero Hill,18.9
Presidio,2.5
Presidio Heights,33.3
Russian Hill,56.4
Seacliff,18.1
South of Market,33.9
Sunset/Parkside,29.9
Tenderloin,112.3
Treasure Island,5.4
Twin Peaks,17.5
Visitacion Valley,47.4
West of Twin Peaks,19.5
Western Addition,59.5

Я пытался сделать это с помощью этой команды:

topojson -o understandSF.json -e understandSFdata.csv --id-property=nhood,nhood -- SFtopojson.json

Я обнаружил, что topojson не является исполняемым.Как объединить CSV с файлом topoJSON?

...