• Stars
    star
    240
  • Rank 168,229 (Top 4 %)
  • Language
    Python
  • Created over 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A template to create map of China by province using d3js

China map template using d3.js

This is a template to easily create nice map of China using data by provinces with d3js. The map includes Taiwan, HK and Macau.

Add your data

To generate a map, you can use the small Python script called create_d3_map.py or pass your values to js variables directly within the html file.

Per province

You need to parse you data into a 2D array where each province is associated to a count (int or float).

var data=[ ["Guangdong",12], ["Guizhou", 15] ...]

Available provinces are :

["Gansu", "Qinghai", "Guangxi", "Guizhou", "Chongqing", "Beijing", "Fujian", "Anhui", "Guangdong", "Xizang", "Xinjiang", "Hainan", "Ningxia", "Shaanxi", "Shanxi", "Hubei", "Hunan", "Sichuan", "Yunnan", "Hebei", "Henan", "Liaoning", "Shandong", "Tianjin", "Jiangxi", "Jiangsu", "Shanghai", "Zhejiang", "Jilin", "Inner Mongol", "Heilongjiang", "Taiwan", "Xianggang", "Macau"]

Colors

Colors scope is defined in the colorScale function in d3map.js

Title, description, units and credits

Additional info should be added like this :

var title='Population of Sina Weibo users for a specific keyword';
var desc='Based on Sina Weibo user profiles during a period of time. Data from weiboscope.';
var credits='by Clement Renaud - 2013';
var units='Volume of tweets';

Notes

Map data

To map data about China, we need to combine several maps to include HK, Aomen and Taiwan.

Map data has been prepared on Mike Bostock's d3js map tutorial and this other tutorial

Map data map need to be downloaded from Natural Earth 1:10m Cultural Vectors

  • Admin 0 - Countries (including taiwan and HK) Download
  • Admin 1 - States, Provinces (only the mainland) Download

Then, we use command-line tool ogr2ogr to filter SHP and keep only relevant part of the map and convert to geojson.

For the countries, we use ISO 3166-1 alpha-3 standard names of the countries : 'CHN', 'HKG', 'TWN' and 'MAC' to generate 2 maps : PRC+Taiwan borders, Aomen+HK borders

ogr2ogr -f GeoJSON -where "ADM0_A3 IN ('CHN','TWN')" zh-chn-twn.topo.json ne_10m_admin_0_countries_lakes.shp

ogr2ogr -f GeoJSON -where "ADM0_A3 IN ('HKG','MAC')" zh-hkg-mac.geo.json ne_10m_admin_0_countries_lakes.shp

For the provinces, we need only the mainland.

ogr2ogr -f GeoJSON -where "gu_A3 IN ('CHN')" zh-mainland-provinces.json ne_10m_admin_1_states_provinces_lakes.shp 

The we use mapshaper.org to simplify the geometry (make the file smaller) and download it as topojson. Final states of the files are available in this rep.

TODO : Make the maps files smaller using npm topojson and removing useless fields

More Repositories

1

jueso

Community-oriented crowdfunding platform for artists
JavaScript
8
star
2

flask-fabric-deploy

Fabric scripts to deploy projects made with Python / Flask
Python
8
star
3

metalsmith-scan-images

A metalsmith plugin that scan all images in subfolders and add it to metadata.
JavaScript
6
star
4

china-political-mobility-map

Political mobility of Chinese officials between province
Jupyter Notebook
5
star
5

angular-chap-timeline

Google CHAP timeline with AngularJS
JavaScript
5
star
6

booksuite

Toolkit for collaborative publishing
TeX
5
star
7

carto-univ

Cartographie des universités médiévales
Jupyter Notebook
4
star
8

feeling-wheel

Html5/canvas/javascript selectable wheel to store info and colors.
JavaScript
4
star
9

photo-portfolio

A portfolio for photographers based on Symphony CMS
PHP
4
star
10

wiki-plugin-single-page

Single page for Fedwiki
JavaScript
3
star
11

unlock-erc721-tokenURIHook

Solidity
3
star
12

bandstour

Visualization of bands touring around
JavaScript
3
star
13

dumb-crawler

A crawler to extract keywords from all links related to a page
Python
3
star
14

processing101

Scracth course for Processing
Processing
2
star
15

topogram-miner

Data mining SNA workflow for topogram
Python
2
star
16

mapmakers.space

Mapping making worldwide
HTML
2
star
17

datfic.net

data + fiction =
JavaScript
2
star
18

arc5

Arc5 mapping project
Jupyter Notebook
2
star
19

duangish.github.io

Duangish
CSS
1
star
20

graph-events

Manipulate and store states of your graphs over time.
JavaScript
1
star
21

zinemakers

A zine about spaces for making in Shenzhen, Shanghai and Chengdu
CSS
1
star
22

old-website

Personal website
JavaScript
1
star
23

sol-upgrade-pattern

JavaScript
1
star
24

micromesomacro.com

Exploring the frontiers of data representation
JavaScript
1
star
25

blockfetcher

Fetch and save files from bl.ocks.org or gist
JavaScript
1
star
26

graphology-react

React component for graphology lib
JavaScript
1
star