power bi形状地图_如何使用内置形状图在Power BI中创建地理图
power bi形状地图
Introduction
介绍
This is the second article of a series dedicated to discovering geographic map tools in Power BI.
这是致力于在Power BI中发现地理地图工具的系列文章的第二篇。
In the ToC below the article, you can find out references to the previous article and the project’s goal.
在ToC的文章下面,你可以找到以前的文章,该项目的目标引用。
In this piece, I’m going to cover the default settings for the Shape Maps visual. In the next one, I’ll explain how to create and use custom shape maps.
在本文中,我将介绍Shape Maps视觉效果的默认设置。 在下一篇中,我将解释如何创建和使用自定义形状贴图。
形状图 (Shape Maps)
The shape map visual has been available in Power BI for several months, but it’s still in preview (at the time of writing). So, you need to enable it in Power BI Desktop.
形状贴图视觉效果已在Power BI中使用了几个月,但仍处于预览状态(在撰写本文时)。 因此,您需要在Power BI Desktop中启用它。
Select File > Options and settings > Options > Preview features then select the “Shape map visual” check box and click OK. You need to close and restart Power BI Desktop to make the change effective.
选择“ 文件”>“选项”和“设置”>“选项”>“预览功能”,然后选中“ 视觉形状图 ”复选框,然后单击“确定”。 您需要关闭并重新启动Power BI Desktop才能使更改生效。

After restarting, you’ll find the visual into the “Visualizations” toolbox.
重新启动后,您将在“ Visualizations”工具箱中找到视觉效果。

Shape maps are usually made of filled regions with delimited borders, that are used to compare values in different regions based on a color range. For example, you can show the distribution of the population in the world countries with different shades of the same color, according to the value intensity.
形状图通常由边界定界的填充区域组成,用于基于颜色范围比较不同区域中的值。 例如,您可以根据值强度显示世界各国使用相同颜色深浅不同的人口的分布。
This is how a typical shape maps looks like:
典型的形状贴图如下所示:
Shape maps are based on the concept of shapefile a storage format developed by Esri (Environmental System Research Institute), nowadays universally recognized as standard for storing geospatial information.
形状图基于shapefile的概念,该形状文件是由Esri (环境系统研究所)开发的一种存储格式,如今已被普遍认为是存储地理空间信息的标准。
A shapefile format spatially describes vector features: points, lines, polygons. It is therefore commonly used for representing geometric locations for data and its attributes. Storing together data and attributes allows the representation of geographic data on a map and makes some calculations possible.
shapefile格式在空间上描述矢量特征:点,线,多边形。 因此,它通常用于表示数据及其属性的几何位置。 将数据和属性存储在一起可以在地图上表示地理数据,并使某些计算成为可能。
A shapefile isn’t a “single” file but rather is a collection of files stored in the same directory. A shapefile at least must be made of three files each with a common name and different extensions. The mandatory files are:
shapefile不是“单个”文件,而是存储在同一目录中的文件的集合。 shapefile至少必须由三个文件组成,每个文件都具有相同的名称和不同的扩展名。 强制文件是:
.shp (the proper) shapefile;
.shx shape index format;
.dbf a table description for each shape.
.shp (适当的)shapefile;
.shx形状索引格式;
.dbf每个形状的表格说明。
Other common (optional) files are:
其他常见(可选)文件是:
.prj projection format;
.sbn, .sbx spatial index;
.ain, .aix attribute index of the active fields in a table;
.shp.xml geospatial metadata in xml format;
.prj投影格式;
.sbn,.sbx空间索引;
表中活动字段的.ain,.aix属性索引;
xml格式的.shp.xml地理空间元数据;
But in Power BI you can’t use directly shapefiles as the visual supports only TopoJSON files. TopoJSON format comes from GeoJSON the most common open standard format designed for representing geographical features, based on JavaScript Object Notation.
但是在Power BI中,您不能直接使用shapefile,因为视觉仅支持TopoJSON文件。 TopoJSON格式来自GeoJSON , GeoJSON是最常见的开放标准格式,旨在基于JavaScript对象符号表示地理特征。
TopoJSON inherits GeoJSON features and includes geospatial topology. Also, TopoJSON files are typically much smaller, up to 80% of the original size.
TopoJSON继承了GeoJSON功能,并包括地理空间拓扑。 另外,TopoJSON文件通常要小得多,最多可达原始大小的80%。
TopoJSON files are not very common. You can create your own file, converting from other formats (shapefile, geojson, ecc.), using, for instance, an online tool such as MapShaper (mapshaper.org). I’ll explain how-to-do later when talking about custom maps.
TopoJSON文件不是很常见。 您可以使用例如MapShaper (mapshaper.org)等在线工具,创建自己的文件,将其转换为其他格式(shapefile,geojson,ecc。)。 我将在稍后讨论自定义地图时说明操作方法。
The shape map visual allows two different uses:
形状图视觉允许两种不同的用途:
- Default built-in maps 默认内置地图
- Custom maps 自定义地图
默认内置地图 (Default built-in maps)
Few built-in maps are supplied inside the visual itself, ready for use. You can easily create some shape maps based on these existing templates.
视觉系统内部几乎没有内置地图可供使用。 您可以基于这些现有模板轻松创建一些形状图。
First of all, we need a dataset. You can download an example from the bottom of the page. It is called ItalianRegions.csv and contains few quantitative data for the 20 Italian administrative regions (population, surface, a number of provinces inside the regions, a number of municipalities).
首先,我们需要一个数据集。 您可以从页面底部下载示例。 它称为ItalianRegions.csv,其中包含20个意大利行政区域(人口,地表,区域内多个省,多个市镇)的定量数据。
After downloading the dataset open a new empty report in Power BI Desktop. Select the menu Get Data and then Text/CSV.
下载数据集后,在Power BI Desktop中打开一个新的空报告。 选择菜单获取数据 ,然后选择文本/ CSV 。

Click Connect and pick up the downloaded file. Power BI loads the .csv and shows you a data preview.
单击“ 连接”,然后选择下载的文件。 Power BI将加载.csv并显示数据预览。
For this first demo we don’t need to do some transformations. Simply click Load and the dataset is imported into Power BI.
对于第一个演示,我们不需要做一些转换。 只需单击“ 加载” ,即可将数据集导入Power BI。
In the left tool bar select the Data icon.
在左侧工具栏中,选择数据图标。

Power BI Desktop opens the dataset. Take a look at the first column; it contains the code for every region. This value is the key for matching your data with the shape map definition as we’ll see shortly.
Power BI Desktop将打开数据集。 看看第一列; 它包含每个区域的代码。 这个值是将您的数据与形状映射定义进行匹配的关键,我们将很快看到。

Once loaded the dataset we can create our maps. Select the Shape map visual from the Visualization tools.
加载数据集后,我们可以创建地图。 从“ 可视化”工具中选择“形状贴图”视觉效果。

Power BI shows an empty object on the report. Move the Code field into the Location bucket and Population into Color saturation.
Power BI在报表上显示一个空对象。 将“ 代码”字段移至“ 位置”存储桶,并将“ 填充”移至“ 颜色饱和度” 。
Now a grey map of United States shows up.
现在显示了美国的灰色地图。

This isn’t what we expected. To get the desired map click the Format icon for the selected visual.
这不是我们所期望的。 要获取所需的地图,请单击所选视觉效果的“ 格式”图标。

A new menu is available. Click to enlarge the Shape item.
有一个新菜单。 单击以放大形状项目。

Power BI prompts as default the USA states map. Click the down arrow and look at the other options available. These are built-map to use in our reports.
Power BI会默认提示美国国家地图。 单击向下箭头,然后查看其他可用选项。 这些是内置地图,可在我们的报告中使用。
Select Italy: regions and notice that the visual on the reports immediately gets colored according to population values.
选择“ 意大利:地区”,并注意报告上的视觉效果会根据人口值立即变为彩色。

Why has this happened? Because we’ve correctly defined the match between the map and the dataset. To understand what I mean, click on View map keys …
为什么会这样呢? 因为我们已经正确定义了地图和数据集之间的匹配。 要了解我的意思,请点击查看地图键…
A new window opens to display the key codes for this map. These are the inside values used by the shapefile as a key for geographical attributes of data. If you scroll laterally you can see all the existing fields.
将打开一个新窗口,以显示此地图的键控代码。 这些是shapefile用作数据地理属性的键的内部值。 如果横向滚动,则可以看到所有现有字段。

At least one of the fields of your dataset must match to one key values field. In my case I preferred to use the ISO coding for Italian regions, to stick to standard values.
数据集的至少一个字段必须与一个键值字段匹配。 就我而言,我更喜欢在意大利地区使用ISO编码,以遵循标准值。
This means that before building a dataset, you must know which are the keys defined in the shape map in order to correctly join your data to the shapefile’s definition.
这意味着在建立数据集之前,您必须知道在形状图中定义的键是什么,以便将数据正确连接到shapefile的定义。
If the shape map doesn’t find any match, the filled regions remain empty.
如果形状图找不到任何匹配项,则填充的区域将保持空白。
In case you’re wondering how to get values, in the article “Shape Maps in Power BI Desktop (Preview)” are reported all the key codes for built-in shape maps in Power BI.
如果您想知道如何获取值,请在文章“ Power BI Desktop中的形状图(预览)”中报告Power BI中内置形状图的所有关键代码。
Now that we have drawn a shape map, let’s explore some of the helpful options in the visual.
现在,我们已经绘制了形状图,让我们探索视觉中的一些有用选项。
The “Data colors” menu allows changing the default colors; it’s possible to set the colors for the visualization range, by picking up one of the theme colors or creating a new one at your choice.
“数据颜色”菜单允许更改默认颜色。 可以通过选择一种主题颜色或创建一种新的颜色来设置可视化范围的颜色。

There are three types of projection available: 1) Equirectangular 2) Mercator 3) Orthographic.
可以使用三种类型的投影: 1)等角 2)墨卡托 3)正交投影。

None of these is the “right” projection. It depends on your needs, the extension of your map and the data you want to represent. Please refer to the articles linked in the Reference section, for more details.
这些都不是“正确”的预测。 这取决于您的需求,地图的扩展名和要表示的数据。 有关更多详细信息,请参考“参考”部分中链接的文章。
Usually, a “Mercator” projection is a good compromise for showing flat data on the Earth’s curved surface.
通常,“墨卡托”投影是在地球曲面上显示平面数据的良好折衷方案。
Expand the “Zoom” area. I’ll explain the behavior of the three filters by practical example. For now, switch Selection Zoom to On. Go back to the map and select any one of the regions. The zoom changes according to your selection.
展开“缩放”区域。 我将通过实际示例说明这三个过滤器的行为。 现在,将“ 选择缩放”切换为“ 开” 。 返回地图,然后选择任意一个区域。 缩放根据您的选择而变化。
Switch the Selection Zoom to Off and the map returns to natural size.
将“ 选择缩放”切换为“ 关闭” ,地图将恢复为自然大小。
If you want to add legend, swap to the Field icon:
如果要添加图例,请交换到“ 字段”图标:

The legend appears as a row in the upper side of the visual. To change its settings, go to the Format icon and you find the new Legend menu, where you can set up Position, Title, Color, Text Font.
图例在视觉效果的上侧显示为一行。 要更改其设置,请转到“ 格式”图标,然后找到新的“ 图例”菜单,您可以在其中设置“ 位置”,“标题”,“颜色”,“文本字体” 。

Bear in mind that the visual is full interactive that is data changes according to selections or filter you put in your report. For example, try to add a slicer and see what happens.
请记住,视觉效果是完全交互式的,即数据会根据选择或您放入报表中的过滤器而变化。 例如,尝试添加切片器,看看会发生什么。
From the visual menu drag a slicer into your report then add Region to the Field bucket. I draw my slicer horizontally for the width of the page, over the map.
从可视菜单中将切片器拖到报告中,然后将“ 区域”添加到“字段”存储区。 我在地图上沿页面的宽度水平绘制切片器。
Keep sure the slicer is selected and select Format > General > Orientation > Horizontal.
确保选择了切片器,然后选择“ 格式”>“常规”>“方向”>“水平” 。
The outcome should look like the picture below.
结果应如下图所示。
Now select the map visual, swap to Format > Default Color > Color and choose a light grey or whatever color you prefer. This is the color of the areas where there is no match to the dataset, i.e. the areas with no data.
现在选择地图视觉,切换到“ 格式”>“默认颜色”>“颜色”,然后选择浅灰色或您喜欢的任何颜色。 这是与数据集不匹配的区域的颜色,即没有数据的区域的颜色。
Back to the report and select one region of your choice. The highlighted regions show up, while the others get the background color. Try to select another one or more regions (using CTRL) to have evidence of the interactivity between the visuals in the report.
返回报告,然后选择一个区域。 显示突出显示的区域,而其他区域则具有背景色。 尝试选择另一个或多个区域(使用CTRL)以得到报表中视觉效果之间交互性的证据。
参考资料 (References)
- Shape Maps in Power BI Desktop Power BI Desktop中的形状图
- Shapefile 形状文件
- Esri shapefiles Esri shapefile
- Map projections 地图投影
资料下载 ( Downloads )
目录 (Table of contents)
How to create geographic maps using Power BI – Filled and bubble maps |
How to create geographic maps in Power BI using built-in shape maps |
How to create geographic maps in Power BI using custom shape maps |
How to create geographic maps in Power BI using ArcGIS |
How to create geographic maps in Power BI using R |
Customized images with Synoptic Panel |
MapBox |
Geocoding |
如何使用Power BI创建地理地图-填充地图和气泡地图 |
如何使用内置形状图在Power BI中创建地理图 |
如何使用自定义形状图在Power BI中创建地理图 |
如何使用ArcGIS在Power BI中创建地理地图 |
如何使用R在Power BI中创建地理地图 |
使用Synoptic Panel定制图像 |
地图框 |
地理编码 |
翻译自: https://www.sqlshack.com/create-geographic-maps-power-bi-using-built-shape-maps/
power bi形状地图