superset使用(四) 地图绘制的ISO 3166转码以及名称汉化显示
本文以制作“中国地图”为例
在chart中选择“Country Map”
我这里提供一份中国省份iso3166的编码数据,建表和添加数据如下:
CREATE TABLE wm_dim.dim_e_fact_region_province (
`id` STRING COMMENT 'id',
`province_name` STRING COMMENT '省市名称',
`area_code` STRING COMMENT '地区编码',
`iso_code` STRING COMMENT 'ISO-3166编码,供可视化使用',
`iso_3166_2` STRING COMMENT 'IOS-3166-2编码,供可视化使用',
`region_id` STRING COMMENT '地区id',
`region_name` STRING COMMENT '地区名称'
)
COMMENT '地区省份维度表'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
STORED AS Parquet
LOCATION 'hdfs://wm-bigdata-pro/user/hive/warehouse/wm_dim.db/dim_e_fact_region_province'
TBLPROPERTIES (
"parquet.compression"="SNAPPY",
"k_creator"="bucat", -- 创建者
"k_create_date"="2021-12-29" -- 创建日期
);
insert into wm_dim.dim_e_fact_region_province values ('1','北京','110000','CN-11','CN-BJ','1','华北'),
('2','天津','120000','CN-12','CN-TJ','1','华北'),
('3','山西','140000','CN-14','CN-SX','1','华北'),
('4','内蒙古','150000','CN-15','CN-NM','1','华北'),
('5','河北','130000','CN-13','CN-HE','1','华北'),
('6','上海','310000','CN-31','CN-SH','2','华东'),
('7','江苏','320000','CN-32','CN-JS','2','华东'),
('8','浙江','330000','CN-33','CN-ZJ','2','华东'),
('9','安徽','340000','CN-34','CN-AH','2','华东'),
('10','福建','350000','CN-35','CN-FJ','2','华东'),
('11','江西','360000','CN-36','CN-JX','2','华东'),
('12','山东','370000','CN-37','CN-SD','2','华东'),
('14','台湾','710000','CN-71','CN-TW','2','华东'),
('15','黑龙江','230000','CN-23','CN-HL','3','东北'),
('16','吉林','220000','CN-22','CN-JL','3','东北'),
('17','辽宁','210000','CN-21','CN-LN','3','东北'),
('18','陕西','610000','CN-61','CN-SN','7','西北'),
('19','甘肃','620000','CN-62','CN-GS','7','西北'),
('20','青海','630000','CN-63','CN-QH','7','西北'),
('21','宁夏','640000','CN-64','CN-NX','7','西北'),
('22','新疆','650000','CN-65','CN-XJ','7','西北'),
('23','河南','410000','CN-41','CN-HA','4','华中'),
('24','湖北','420000','CN-42','CN-HB','4','华中'),
('25','湖南','430000','CN-43','CN-HN','4','华中'),
('26','广东','440000','CN-44','CN-GD','5','华南'),
('27','广西','450000','CN-45','CN-GX','5','华南'),
('28','海南','460000','CN-46','CN-HI','5','华南'),
('29','香港','810000','CN-91','CN-HK','5','华南'),
('30','澳门','820000','CN-92','CN-MO','5','华南'),
('31','四川','510000','CN-51','CN-SC','6','西南'),
('32','贵州','520000','CN-52','CN-GZ','6','西南'),
('33','云南','530000','CN-53','CN-YN','6','西南'),
('13','重庆','500000','CN-50','CN-CQ','6','西南'),
('34','西藏','540000','CN-54','CN-XZ','6','西南')
然后选择“iso_code”列即可
完成后发现superset显示的省份名称是英文,如何展示成汉字如下:
到安装superset的机器assets目录下,找到65d35076af8ab2eac6355ea6f4932f54.geojson
文件
我的地址在这里
~/wmzky/opt/module/miniconda3/envs/superset/lib/python3.7/site-packages/superset/static/assets
有人问这么多.geojson文件,怎么知道哪个是中国地图呢,可以用这个命令
grep -rl 'BeiJing'
然后就会把文件内包含‘Beijing’字段的文件找出来了
之后,将NAME_1的值由拼音改成中文,如下(以Hebei为例)
改成中文‘河北’
然后页面刷新你的缓存,就完成了