问题描述
鉴于世界各国的庞大形状文件.
鉴于我使用的是通过 npm install [email protected]
在本地安装的 [email protected].通过 npm install [email protected]
在本地安装.
鉴于我有许多国家/地区的 csv 数据,例如
FR,144145EN,5643DE,25667ES,3567美国,83466CN,34576JA,69353
鉴于我想将该数据绑定到 Topojson+D3js 生成的 SVG.
因此,我想要一个具有权限属性的轻便而精确的 world-id.topojson 文件...以便通过匹配 ID 简化 CSV-SVG 数据投标.
所以,我选择:
#下载GADM卷曲\-L -C - 'http://biogeo.ucdavis.edu/data/gadm2.8/gadm28_levels.shp.zip'\-o ./gadm28_levels.shp.zip解压 -n ./gadm28_levels.shp.zip -d ./# 处理数据节点 ./node_modules/topojson/bin/topojson -q 1e4 \-p 名称=NAME_ENGL,iso=ISO,iso2=ISO2-o world-all.json \-- ./gadm28_adm0.shp
但它失败了,Aborted (core dumped)
.如何进行?
干净优雅
GADM 数据
#在本地安装topojson v.1npm 安装 [email protected]# 运行 topojson节点 --max_old_space_size=8000 ./node_modules/topojson/bin/topojson \-q 1e4 \-p 名称=NAME_ENGL,iso=ISO,iso2=ISO2 \-o world-id.json \-- 国家=./gadm28_adm0.shp
Shapefile 的数据是这样的:
{特性": {"对象 ID": 79,ID_0":79,"ISO": "FRA","NAME_ENGLI": "法国","NAME_ISO": "法国","NAME_FAO": "法国","NAME_LOCAL": "法国",NAME_OBSOL":空,NAME_VARIA":空,NAME_NONLA":空,"NAME_FRENC": "法国","NAME_SPANI": "弗朗西亚","NAME_RUSSI": "ФÑанÑиÑ","NAME_ARABI": "ÙرÙسا","NAME_CHINE": "æ³å½",WASPARTOF":空,包含":空,"SOVEREIGN": "法国","ISO2": "FR",WWW":空,"FIPS": "FR",伊森":250,"VALIDFR": "1944","VALIDTO": "现在",POP2000":59237668,SQKM":546728.875,POPSQKM":108.349258122,"UNREGION1": "西欧","UNREGION2": "欧洲",发展":2,独联体":0,过渡":0,经合组织":1,WBREGION":空,"WBINCOME": "高收入:经合组织","WBDEBT": "债务未分类","WBOTHER": "动车组","CEEAC": 0,CEMAC":0,"CEPLG": 0,"COMESA": 0,EAC":0,"西非经共体": 0,伊加德":0,国际奥委会":0,"MRU": 0,"SACU": 0,"UEMOA": 0,乌玛":0,"PALOP": 0,部分":0,"CACM": 0,"EurAsEC": 0,阿加迪尔":0,南盟":0,东盟":0,北美自由贸易协定":0,海湾合作委员会":0,"南航": 0,加勒比共同体":0,欧盟":1,可以":0,ACP":0,内陆":0,"AOSIS": 0,小岛屿发展中国家":0,岛屿":0,最不发达国家":0,"Shape_Leng": 130.51585694,形状_区域":64.5133204963}}
自然地球数据
- 下载:1.3G
- 输入:实际源只有 5M,不会因大小而崩溃.
- 输出:优雅的world-id.json,579.9kb.
# 下载 NaturalEarthData卷曲\-L -C - 'https://github.com/nvkelso/natural-earth-vector/archive/v4.0.0.zip' \-o ./ne.shp.zip解压 -n ./ne.shp.zip -d ./# 在本地安装 topojson v.1npm 安装 [email protected]# 运行 topojson节点 ./node_modules/topojson/bin/topojson -q 1e3 --bbox \-p 名称=管理员,iso2=WB_A2,iso3=WB_A3 \-o world-id.json \-- country=./natural-earth-vector-4.0.0/10m_culture/ne_10m_admin_0_countries.shp
注:NE v4.0 数据为:
{特性": {"scalerank": 0,"featurecla": "Admin-0 国家",标签等级":2,"SOVEREIGNT": "法国","SOV_A3": "FR1",ADM0_DIF":1,级别":2,"TYPE": "国家","ADMIN": "法国","ADM0_A3": "FRA","GEOU_DIF": 0,"GEOUNIT": "法国","GU_A3": "FRA","SU_DIF": 0,"SUBUNIT": "法国","SU_A3": "FRA","BRK_DIFF": 0,"NAME": "法国","NAME_LONG": "法国","BRK_A3": "FRA","BRK_NAME": "法国",BRK_GROUP":空,"ABBREV": "神父","邮政": "F","FORMAL_EN": "法兰西共和国",FORMAL_FR":空,"NAME_CIAWF": "法国",NOTE_ADM0":空,NOTE_BRK":空,"NAME_SORT": "法国",NAME_ALT":空,"MAPCOLOR7": 7,MAPCOLOR8":5,"MAPCOLOR9": 9,MAPCOLOR13":11,POP_EST":67106161,"POP_RANK": 16,GDP_MD_EST":2699000,POP_YEAR":2017,上次人口普查":-99,"GDP_YEAR": 2016,"经济": "1. 发达地区: G7","INCOME_GRP": "1. 高收入:经合组织",维基百科":-99,"FIPS_10_": "FR","ISO_A2": "-99","ISO_A3": "-99","ISO_A3_EH": "-99","ISO_N3": "250","UN_A3": "250","WB_A2": "FR","WB_A3": "FRA",WOE_ID":-90,WOE_ID_EH":23424819,"WOE_NOTE": "仅包括法国本土(包括科西嘉)","ADM0_A3_IS": "FRA","ADM0_A3_US": "FRA",ADM0_A3_UN":-99,ADM0_A3_WB":-99,大陆":欧洲","REGION_UN": "欧洲","SUBREGION": "西欧","REGION_WB": "欧洲和中亚",NAME_LEN":6,"LONG_LEN": 6,"ABBREV_LEN": 3,小":-99,家庭部分":1,"MIN_ZOOM": 0,MIN_LABEL":1.7,MAX_LABEL":6.7}}
Given a massive shape file of world countries.
Given I'am using [email protected] installed locally via npm install [email protected]
.talled locally via npm install [email protected]
.
Given I have csv data for many countries such as
FR,144145
EN,5643
DE,25667
ES,3567
US,83466
CN,34576
JA,69353
Given I want to bind that data to the Topojson+D3js generated SVG.
Thus I want a light yet precise world-id.topojson file with the rights properties... so to ease up the CSV-SVG data biding via matchings ids.
So, I go for :
# download GADM
curl \
-L -C - 'http://biogeo.ucdavis.edu/data/gadm2.8/gadm28_levels.shp.zip' \
-o ./gadm28_levels.shp.zip
unzip -n ./gadm28_levels.shp.zip -d ./
# Process data
node ./node_modules/topojson/bin/topojson -q 1e4 \
-p name=NAME_ENGL,iso=ISO,iso2=ISO2
-o world-all.json \
-- ./gadm28_adm0.shp
But it fails with Aborted (core dumped)
. How to proceed ?
EDIT: clean elegant world-id.json, 579.9kb, with iso-639-2, countrynames, and iso-639-3.
Currently via [email protected]. (version using [email protected] welcome!)
Output (Natural Earth) : clean elegant world-id.json, 579.9kb, with iso-639-2, countrynames, and iso-639-3.
Properties filtering
Add -p
to keep all properties and their values, use nothing to drop them all, and use -p ISO
to transmit to your topojson the duo "ISO": "FRA"
. See Topojson v.1 API
What we want
- Data sample / visual :
{
"type": "MultiPolygon",
"arcs": [
[ [4347,4348,4349] ],
[ [4350,4350,4351,4352,4353,4354] ],
[ [4355,4356,4357,4358,4358,4358,4359,4360,4361,-4350,4362,4363,-3047,-1961,-1960,-598], [4364], [4365] ]
],
"properties": {
"name": "Italy",
"iso2": "IT",
"iso3": "ITA"
}
},
GADM data
# Install topojson v.1 locally
npm install [email protected]
# Run topojson
node --max_old_space_size=8000 ./node_modules/topojson/bin/topojson \
-q 1e4 \
-p name=NAME_ENGL,iso=ISO,iso2=ISO2 \
-o world-id.json \
-- countries=./gadm28_adm0.shp
Shapefile's data is such :
{
"properties": {
"OBJECTID": 79,
"ID_0": 79,
"ISO": "FRA",
"NAME_ENGLI": "France",
"NAME_ISO": "FRANCE",
"NAME_FAO": "France",
"NAME_LOCAL": "France",
"NAME_OBSOL": null,
"NAME_VARIA": null,
"NAME_NONLA": null,
"NAME_FRENC": "France",
"NAME_SPANI": "Francia",
"NAME_RUSSI": "ФÑанÑиÑ",
"NAME_ARABI": "ÙرÙسا",
"NAME_CHINE": "æ³å½",
"WASPARTOF": null,
"CONTAINS": null,
"SOVEREIGN": "France",
"ISO2": "FR",
"WWW": null,
"FIPS": "FR",
"ISON": 250,
"VALIDFR": "1944",
"VALIDTO": "Present",
"POP2000": 59237668,
"SQKM": 546728.875,
"POPSQKM": 108.349258122,
"UNREGION1": "Western Europe",
"UNREGION2": "Europe",
"DEVELOPING": 2,
"CIS": 0,
"Transition": 0,
"OECD": 1,
"WBREGION": null,
"WBINCOME": "High income: OECD",
"WBDEBT": "Debt not classified",
"WBOTHER": "EMU",
"CEEAC": 0,
"CEMAC": 0,
"CEPLG": 0,
"COMESA": 0,
"EAC": 0,
"ECOWAS": 0,
"IGAD": 0,
"IOC": 0,
"MRU": 0,
"SACU": 0,
"UEMOA": 0,
"UMA": 0,
"PALOP": 0,
"PARTA": 0,
"CACM": 0,
"EurAsEC": 0,
"Agadir": 0,
"SAARC": 0,
"ASEAN": 0,
"NAFTA": 0,
"GCC": 0,
"CSN": 0,
"CARICOM": 0,
"EU": 1,
"CAN": 0,
"ACP": 0,
"Landlocked": 0,
"AOSIS": 0,
"SIDS": 0,
"Islands": 0,
"LDC": 0,
"Shape_Leng": 130.51585694,
"Shape_Area": 64.5133204963
}
}
Natural Earth Data
- Download : 1.3G
- Input : actual source is just 5M and doesn't crash due to size.
- Output : elegant world-id.json, 579.9kb.
# download NaturalEarthData
curl \
-L -C - 'https://github.com/nvkelso/natural-earth-vector/archive/v4.0.0.zip' \
-o ./ne.shp.zip
unzip -n ./ne.shp.zip -d ./
# Install topojson v.1 locally
npm install [email protected]
# Run topojson
node ./node_modules/topojson/bin/topojson -q 1e3 --bbox \
-p name=ADMIN,iso2=WB_A2,iso3=WB_A3 \
-o world-id.json \
-- countries=./natural-earth-vector-4.0.0/10m_cultural/ne_10m_admin_0_countries.shp
Note: NE v4.0 data is :
{
"properties": {
"scalerank": 0,
"featurecla": "Admin-0 country",
"LABELRANK": 2,
"SOVEREIGNT": "France",
"SOV_A3": "FR1",
"ADM0_DIF": 1,
"LEVEL": 2,
"TYPE": "Country",
"ADMIN": "France",
"ADM0_A3": "FRA",
"GEOU_DIF": 0,
"GEOUNIT": "France",
"GU_A3": "FRA",
"SU_DIF": 0,
"SUBUNIT": "France",
"SU_A3": "FRA",
"BRK_DIFF": 0,
"NAME": "France",
"NAME_LONG": "France",
"BRK_A3": "FRA",
"BRK_NAME": "France",
"BRK_GROUP": null,
"ABBREV": "Fr.",
"POSTAL": "F",
"FORMAL_EN": "French Republic",
"FORMAL_FR": null,
"NAME_CIAWF": "France",
"NOTE_ADM0": null,
"NOTE_BRK": null,
"NAME_SORT": "France",
"NAME_ALT": null,
"MAPCOLOR7": 7,
"MAPCOLOR8": 5,
"MAPCOLOR9": 9,
"MAPCOLOR13": 11,
"POP_EST": 67106161,
"POP_RANK": 16,
"GDP_MD_EST": 2699000,
"POP_YEAR": 2017,
"LASTCENSUS": -99,
"GDP_YEAR": 2016,
"ECONOMY": "1. Developed region: G7",
"INCOME_GRP": "1. High income: OECD",
"WIKIPEDIA": -99,
"FIPS_10_": "FR",
"ISO_A2": "-99",
"ISO_A3": "-99",
"ISO_A3_EH": "-99",
"ISO_N3": "250",
"UN_A3": "250",
"WB_A2": "FR",
"WB_A3": "FRA",
"WOE_ID": -90,
"WOE_ID_EH": 23424819,
"WOE_NOTE": "Includes only Metropolitan France (including Corsica)",
"ADM0_A3_IS": "FRA",
"ADM0_A3_US": "FRA",
"ADM0_A3_UN": -99,
"ADM0_A3_WB": -99,
"CONTINENT": "Europe",
"REGION_UN": "Europe",
"SUBREGION": "Western Europe",
"REGION_WB": "Europe & Central Asia",
"NAME_LEN": 6,
"LONG_LEN": 6,
"ABBREV_LEN": 3,
"TINY": -99,
"HOMEPART": 1,
"MIN_ZOOM": 0,
"MIN_LABEL": 1.7,
"MAX_LABEL": 6.7
}
}
这篇关于如何使用 ID 创建最佳的 world.topo.json 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!