斯潘8
span4
可以使用FME和Google's Chart API.在下面的示例中,坐标数据从ESRI形状文件中读取,并与包含在csv文件中的选举结果(逗号分隔的值)相联接。饼图是使用HTML代码生成的,结果输出到kml(在GoogleEarth中可查看)。
Vancouver neighborhood voting boundaries available as a polygon Shapefile.
选择结果以csv格式提供。
1。Read source CSV Data
在空白工作区中,添加一个csv阅读器,并添加vancouver2014electionresults.csv,the default parameters are ok.此csv文件包含用于填充饼图的选举结果数据。
2。分解属性
请注意,在源数据中,所有投票区域都存储为列标题。The best practice when designing databases is to store values that share a common theme (e.g.位置和投票计数)在单独的表格中-或对于FME,as separate attributes.为此,我们将使用一个attributeexploder变压器。在参数中,set the Attribute Name Label to LOCATION and the Attribute Value Label to VOTE_COUNT.我们仍然希望在制造新的属性之后保留所有的属性,所以将keep属性设置为yes。Connect an Inspector transformer and run the translation.
分解属性以存储共享公共主题的值。
三。删除FME格式属性
在幕后,FME为某些属性创建属性,usually,these attributes are ignored and don't affect the final output.查看attributeExploder的输出,您可以看到投票计数列中添加了各种功能,如csv2_1和fme_no_geom。Using a Tester transformer,set the Left Value to VOTE_COUNT,包含regex的运算符,and then set the Right Value to [0-9].此正则表达式检查数据以确保数据是数字。
Using regular expression,ensure VOTE_COUNT contains only numerical values
4。Create attribute for the HTML
Following the documentation forGoogle's Chart API,必须将数据转换为[数据',value]使用attributeCreator格式化。将attributeCreator变压器连接到检测仪上通过的输出端口。在参数中,创建一个名为“format”的新属性,并将该值设置为
['@value(候选者)',@value(投票数)]
5.按位置聚合属性
目标是为温哥华的每个投票区制作一个饼图,因此,我们需要按地点汇总我们的“格式”候选人。Add an Aggregator transformer to the canvas,set the Group By to LOCATION,并且模式仅限于属性。Then for Keep Input Attributes,选择“是”,并将属性设置为“连接”为“格式”候选项。
使用聚合器,按位置分组
6.创建包含饼图HTML的属性
Now to create the pie chart,这也可以使用ChartGenerator变压器完成,如果你想使用这个方法,你可以通过FME教程查看创建图表。对于这个例子,我们想利用谷歌地图API的力量,所以我们将编写自己的HTML和JavaScript。使用属性创建器,create three attributes,HTML1,_ HTML2和HTML3。
对于_html1,输入以下值:
使用attributeCreator创建HTML
7。Concatenate _html attributes to form one
既然我们已经创建了HTML属性,we need to concatenate them into one attribute to read into our chart.使用StringConcatenator,name the New Attribute _html,然后对于弦部分,将字符串类型设置为属性值三次,then next to each set the String Value to _html1,HTML2,和HTML3,分别。
使用StringConcatenator将所有三个HTML属性连接在一起
8。读取投票边界形状文件
Now we need to create the pins for our map to contain the pie chart popup when clicked.在画布中添加一个shapefile reader并在voting_boundary.shp中读取,the default parameters are ok.The polygon Shapefile is of municipal voting boundaries in the City of Vancouver which provides the coordinates for placing the pins which will contain the pie charts.
9。Create a larger polygon of voting boundaries
Because the election data from the CSV is organized into voting districts,the Dissolver transformer is used to create one larger polygon for each of the many voting boundaries contained in the Shapefile – this ensures only one pie chart for each district is created.在画布上添加一个溶解器,and connect it to the Shapefile Reader.在参数中,set the Group By to LOCAL_AREA and set the Accumulation Mode to Merge Incoming Features.
10。在每个多边形内创建一个中心点
我们需要在每个投票边界多边形内创建一个中心点,以便放置一个销,以便弹出包含图表的信息窗口。将CenterPointReplacer添加到画布,并将其连接到溶解器上的区域输出端口。
11。Extract the coordinates to store as attributes
既然已经建立了一个中心点,we need to extract its coordinates to create latitude and longitude attributes.Add a CoordinateExtractor transformer,and connect it to the Point Output port on the CenterPointReplacer.在参数中,set the Mode to Specify Coordinate,然后将x属性更改为经度,将y属性更改为纬度。
12.合并csv数据和中心点
既然已经创建了HTML饼图和中心点,我们需要将它们合并在一起。在画布上添加一个功能合并,将coordinatextractor上的输出端口连接到请求者输入端口,以及连接到供应商输入端口的StringConcatenator上的输出端口。在参数中,set the Requestor to LOCAL_AREA and the Supplier to LOCATION.然后将特征合并类型设置为属性和几何体。
13。重新投影数据
将数据重新投影到ll-wgs84中,与是一个谷歌地球兼容的格式,使用的是连接到功能合并上合并的输出端口的转发器。
14。创建放置标记销并插入饼图
Connect a KMLPropertySetter transformer to the Reprojected Output port on the Reprojector.在参数中,set the Name to LOCAL_AREA and then set the summary to:
温哥华2014年@value(location)区选举结果
对于描述气球,将内容类型设置为HTML,内容设置为HTML。然后将include属性表设置为no。这将创建放置标记销并将饼图插入信息气球中,单击PIN时可见。
15。创建背景多边形
要创建投票区的背景多边形,向溶解器上的区域输出端口添加一个attributekeeper变压器。在参数中,设置要保留到本地区域的属性。下一步,connect a KMLPropertySetter to the AttributeKeeper Output port.Then in the parameters set the Name to LOCAL_AREA and the Summary to:
@价值(当地)投票区
然后对于描述气球,将内容类型设置为文本,and the Content to Voting District.将include属性表设置为no。
16。(可选)样式销和多边形。
If you would like to change the style of your Pins and Voting District polygons,您可以向每个kmlpropertySetter添加一个kmlstyler,并将参数更改为您选择的样式。
17.Write to Google Earth KML
Add a Google KML writer to the canvas,将功能类型定义设置为自动…,单击确定。将要素类型名称更改为“选择”,然后单击“确定”完成添加编写器。Connect the Writer to the Output ports of both the KMLPropertySetters OR if you styled your data with the KMLStyler,将编写器连接到kmlstyler上的输出端口。
18。在Google Earth中查看输出
Run the translation,然后打开GoogleEarth中的选举kml查看结果。点击任意一个别针查看包含2014年选举数据的饼图。
Results in Google Earth
Data Attribution
此处使用的数据源于温哥华市,不列颠哥伦比亚省。它包含根据开放式政府许可证(温哥华)获得许可的信息。
非常感谢,so far,为了你的帮助
第二幅图像:
The line chart in the html file looks ok,然而,在kml中加入气球,它不出现。?2019安全亚搏在线软件公司|合法的