FME中的栅格数据操作之十三——生成应用于网络制图平台的瓦片(一)

原文发布时间:2010-05-06

作者:毛毛虫

FME可以生成应用于网络制图平台Bing Maps 、Google Maps的瓦片。

使用转换器WebMapTiler,创建一系列Microsoft Virtual Earth可以使用的瓦片。这一操作通过重采样栅格到各种不同分辨率,然后把它们分成片。这个转换器与MSR MapCruncher产生相似的输出。

转换器各个参数如下所示:


其中,对于Zoom Level部分,这些参数指定了需要进行切片的级别。Level 1是最低的级别;Level 23是最高的详细级别,如果Minimum Zoom Level 没有指定,最小的缩放级别默认为1。如果Maximum Zoom Level 没有指定,最高的缩放级别将是最小的缩放级别。

对于Attributes部分中,Quadkeys是作为Bing Maps 的瓦片的唯一标志,zoom level、tile column和 tile row属性用来表示Google Maps瓦片。通常,通过这个转换器产生的栅格,对于Bing Maps按fanout方式以quadkey命名,对于Google Maps则是zoom level、 tile column和tile row组合的命名方式。

需要注意下面两点:

1、这个转换器只接受栅格几何要素。

2、这个转换器只接受EPSG:3785 (SPHERICAL_MERCATOR)、EPSG:900913(SPHERICAL_MERCATOR)或SPHERICAL_MERCATOR坐标系统。在使用这个转换器前,所有的要素必须重投影到这个坐标系统。

示例:

为了更好的理解这个转换器,先看一个别人做到一个例子,它是读入栅格数据,使用FME产生HTML文件,并对输入的栅格数据切片为PNG格式,加载到Virtual Earth的地图窗口。

下面是我们要生成的HTML代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

   <head>

      <title>FME for VE</title>

      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

 

      <script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5"></script>

      <script type="text/javascript">

         var map = null;

         var tileLayer;

        

         function GetMap()

         {

            map = new VEMap('myMap');

            map.LoadMap(new VELatLong(30.2619215931891,-97.7502715123838),15,'r' ,false);

            GetTiles();

         }  

        

         function GetTiles()

         {

            var bounds = [new VELatLongRectangle(new VELatLong(30.2744855353781,-97.7717410080526), new VELatLong(30.2493560433293,-97.7288020167142))];

 

 

            var tileSourceSpec = new VETileSourceSpecification("myMap", "./tiles/%4.png");

            tileSourceSpec.NumServers = 1;

            tileSourceSpec.Bounds = bounds;

            tileSourceSpec.MinZoomLevel = 10;

            tileSourceSpec.MaxZoomLevel = 18;

            tileSourceSpec.Opacity = 0.75;

            tileSourceSpec.ZIndex = 100;

 

            map.AddTileLayer(tileSourceSpec, true);

 

         } 

         function DeleteTileLayer()

         {

            map.DeleteTileLayer("myMap");

         }

        

         function ShowTileLayer()

         {

            map.ShowTileLayer("myMap");

            btnHide.disabled=null;

            btnShow.disabled="disabled";

         }

                 

         function HideTileLayer()

         {

            map.HideTileLayer("myMap");

            btnHide.disabled="disabled";

            btnShow.disabled=null;

         }

           

      </script>

   </head>

   <body οnlοad="GetMap();">

                  <H3>FME and Microsoft Virtual Earth</H3>

       <P>This is an example showing results produced by <a href='http://www.fmepedia.com/index.php/VirtualEarthTiler'>VirtualEarthTiler</a> transformer and <a href='http://www.fmepedia.com/index.php/VirtualEarthHTMLCreator'>VirtualEarthHTMLCreator</a> custom transformer.</P>

       <P><a href='http://www.microsoft.com/virtualearth/'>More information about Microsoft Virtual Earth</a>.</P>

       <P><a href='http://dev.live.com/virtualearth/sdk/'>Virtual Earth Interactive SDK</a></P>

       <div id='myMap' style="position:relative; width:800px; height:600px;"></div>

     

      <input id="btnHide" type="button" οnclick="HideTileLayer()" value="Hide Layer"/>

      <input id="btnShow" type="button" οnclick="ShowTileLayer()" value="Show Layer"/>

     

   </body>

</html>

这段代码主要是用于加载Microsoft Virtual Earth (http://www.microsoft.com/virtualearth/)环境环境,并从输入的栅格数据中生成png格式的瓦片,然后加载到Virtual Earth的地图窗口中。

我们先查看下这个初始的栅格数据,如果不是SPHERICAL_MERCATOR坐标系统,要重投影到这个坐标系统。

重投影后的栅格数据如下:


相关属性:


读取这个数据的属性,比如中心点X、Y,切片数据需要的坐标点,Xmax,Xmin,Ymax和Ymin等,主要用到转换器BoundsExtractor、ExpressionEvaluator来读取和计算相关的坐标、范围信息,使用AttributeCreator和/或AttributeSetter转换器来写入相关的代码(也可以使用AttributeFileReader转换器)和属性,最后用StringConcatenator转换器按顺序连接所有的信息,使用AttributeFileWriter转换器写入到一个HTML文件中去。在这个过程中,我们也可以把一些关键信息,如HTML page title、Virtual Earth 地图窗口大小、显示的最到最小级别等做成发布参数,可以针对不同的需求修改相关信息。

接下来使用WebMapTiler转换器,设置好切片的最大最小缩放级别后,进行切片处理。

在FME中产生的HTML文件内容如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

   <head>

      <title>FME for VE</title>

      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

 

      <script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5"></script>

      <script type="text/javascript">

         var map = null;

         var tileLayer;

        

         function GetMap()

         {

            map = new VEMap('myMap');

            map.LoadMap(new VELatLong(29.5569406570875,106.54751480051),15,'r' ,false);

            GetTiles();

         }  

        

         function GetTiles()

         {

            var bounds = [new VELatLongRectangle(new VELatLong(29.6018664802093,106.496118568782), new VELatLong(29.5119948486472,106.598911032237))];

 

 

            var tileSourceSpec = new VETileSourceSpecification("myMap", "./tiles/%4.png");

            tileSourceSpec.NumServers = 1;

            tileSourceSpec.Bounds = bounds;

            tileSourceSpec.MinZoomLevel = 10;

            tileSourceSpec.MaxZoomLevel = 18;

            tileSourceSpec.Opacity = 0.75;

            tileSourceSpec.ZIndex = 100;

 

            map.AddTileLayer(tileSourceSpec, true);

 

         } 

         function DeleteTileLayer()

         {

            map.DeleteTileLayer("myMap");

         }

        

         function ShowTileLayer()

         {

            map.ShowTileLayer("myMap");

            btnHide.disabled=null;

            btnShow.disabled="disabled";

         }

                 

         function HideTileLayer()

         {

            map.HideTileLayer("myMap");

            btnHide.disabled="disabled";

            btnShow.disabled=null;

         }

           

      </script>

   </head>

   <body οnlοad="GetMap();">

                  <H3>FME and Microsoft Virtual Earth</H3>

       <P>This is an example showing results produced by <a href='http://www.fmepedia.com/index.php/VirtualEarthTiler'>VirtualEarthTiler</a> transformer and <a href='http://www.fmepedia.com/index.php/VirtualEarthHTMLCreator'>VirtualEarthHTMLCreator</a> custom transformer.</P>

       <P><a href='http://www.microsoft.com/virtualearth/'>More information about Microsoft Virtual Earth</a>.</P>

       <P><a href='http://dev.live.com/virtualearth/sdk/'>Virtual Earth Interactive SDK</a></P>

       <div id='myMap' style="position:relative; width:800px; height:600px;"></div>

     

      <input id="btnHide" type="button" οnclick="HideTileLayer()" value="Hide Layer"/>

      <input id="btnShow" type="button" οnclick="ShowTileLayer()" value="Show Layer"/>

     

   </body>

</html>

 

我在测试时,把WebMapTiler转换器的最小缩放级别设置没有设置,也就是默认1,最大缩放级别设置为15,初始数据是150M,结果该模板执行了8个多小时还没有执行完,我终止了程序,没有完成切片。部分切片如图:


可见PNG文件是根据Virtual Earth Tile的quadtree key来命名。

打开HTML文件得到的效果如下:



WebMapTiler

从上面可以看到使用WebMapTiler可能会花费很长时间,在下面部分将会说一下解决这一问题的可能方案。下一部分主要是说一下如何在FME根据缩放级别显示不同的数据,并栅格化切片后发布到Bing Maps上。






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值