码迷,mamicode.com
首页 > Web开发 > 详细

WebGIS中通过行列号来换算出多种瓦片的URL 之离线地图(转载)

时间:2016-09-20 16:24:51      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

WebGIS中通过行列号来换算出多种瓦片的URL 之离线地图

1.前言

在前面我花了两个篇幅来讲解行列号的获取,也解释了为什么要获取行列号。在这一章,我将把常见的几种请求瓦片时的URL样式罗列出来,并且给出大致的解释。

我在这里将地图分为离线地图和在线地图。所谓离线地图,即保存在本地而没有发布的地图。在线地图即发布与网上,可以通过浏览器访问的地图。

2.ArcGIS切图——exploded类型

在前面章节中我已经贴出了exploded类型的切图图片,这里再次给出。

 技术分享

那么如何通过行列号来换算出此瓦片的URL呢。我们首先可以通过观察得出三个结论:

(1)L开头的代表了Level,R开头的代表了row,C开头的代表了Col。

(2)确定这个后,我们再继续观察,可以发现L后的数字是两位字符串,R后的是八位字符串,C后的也是八位字符串。

(3)英文后的数字均是16进制数,然后不足位数的用0补充。

我想大家在知道了这三个结论后,通过行列号来获得离线松散瓦片的地址该不难了吧,我们只需把级别、行列号换算成16进制后,不足位数的再用0补位,最后加上英文标识,于是这个瓦片的地址也便可以额找到了。

3.ArcGIS 切图——bundle类型

这里我也首先贴出这种瓦片类型的样式:

 技术分享

这个瓦片的获取咋一看确实是毫无头绪,因为arcgis的这种紧凑型格式将图片进行了包装,并不能直观的看到图片。ArcGIS号称这种格式目前是不公开解析方法的,并且同样在网上也很难收到对应的解析方法。但是,我的一个很有想法的同事,在去年时花了些时间后已经将这种格式下的瓦片获取方法破解了,并且我们已经成功运用到多个项目中。

这里我就只给出几个提示吧,根据我的这几个提示,我想读者只要再加一把劲一定可以破解的:

(1)同样,L、R、C后的是地图的级别、行号、列号。

(2)R、C后的字符串固定是4位。

(3)R、C后的数字是通过行列号除以128后再转成16进制,然后将不足的位数补零。

(4)Bundle文件中存放的是图片二进制流,BundleX文件中存放的是对应瓦片在Bundle中的地址,是一个索引文件。

(5)然后…..

然后就是如何在索引文件中找到应该读取的地方,获得瓦片在Bundle中所在的地址后,再去Bundle中的相应地址里读取图片。不过,这里补充一下,Bundle中也不是只有瓦片的,它里面还包含了每个瓦片的大小,也就是你读这个瓦片需要读取多少个二进制的数目。

 技术分享

这里再次感谢我的同事的智慧的结晶,否则这篇文章一定是不完整的。

4.非常见瓦片格式——国土局的瓦片

在我们项目中经常可以见到非ArcGIS的瓦片系列,比如超图的、中地的等等。这里我给出某国土局的瓦片格式,其实目前很多国土局自己的瓦片均是这个组织格式。

同样我先给出瓦片的样式图:

 技术分享

大家是不是很奇怪,明明该是三个层次的呀,Level、Row、Col的呀,怎么这个就有四个层次呢。是的,国土局的瓦片中除了这三个参数外,还有一个FileID参数。

这里我直接给出换算公式:

FixedLevel=Level;

FixedRow=Math.floor(Row/4);

FixedCol=Math.floor(Col/4);

FileID=(Row)%4)+ 4*((Col)%4);

其URL的地址就是\FixedLevel\FixedRow\FixedCol\FileID.png。

5.总结

在这一节里我们针对两种常见离线地图格式和一种特殊的离线地图格式进行了解析。从这个解析中我们可以看出,不管是什么地图,行列号都是必须的条件。所以对行列号如何得到还不是很清楚的读者,请将我这个系列中的第二节和第三节再次专心的读一遍,相信你和我一样一定有不一样的收获的。

下一节里,我们将对在线的地图的URL解析进行讲解,在线的地图的URL获取相对简单。我们同样会对符合OGC标准的在线地图以及特殊的在线地图服务进行分析。欢迎持续关注。

 

 

ArcGIS Flex API读取自定义瓦片地图

PortlandTiledMapServiceLayer.as 

Java代码  技术分享
package com.esri.ags.samples
{

import com.esri.ags.SpatialReference;
import com.esri.ags.geometry.Extent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.layers.supportClasses.LOD;
import com.esri.ags.layers.supportClasses.TileInfo;
import com.esri.ags.layers.TiledMapServiceLayer;

import flash.net.URLRequest;

/**
 * PortlandTiledMapServiceLayer
 */
public class PortlandTiledMapServiceLayer extends TiledMapServiceLayer
{
    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new PortlandTiledMapServiceLayer object.
     */
    public function PortlandTiledMapServiceLayer()
    {
        super();

        buildTileInfo(); // to create our hardcoded tileInfo

        setLoaded(true); // Map will only use loaded layers
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

    private var _tileInfo:TileInfo = new TileInfo(); // see buildTileInfo()
    private var _baseURL:String = "http://sampleserver1.arcgisonline.com/arcgiscache/Portland_Portland_ESRI_LandBase_AGO/Portland/_alllayers";

    //--------------------------------------------------------------------------
    //
    //  Overridden properties
    //      fullExtent()
    //      initialExtent()
    //      spatialReference()
    //      tileInfo()
    //      units()
    //
    //--------------------------------------------------------------------------


    //----------------------------------
    //  fullExtent
    //  - required to calculate the tiles to use
    //----------------------------------

    override public function get fullExtent():Extent
    {
        return new Extent(-123.596895130725, 44.297575737946, -121.553757125519, 46.3683237161949, new SpatialReference(4326));
    }

    //----------------------------------
    //  initialExtent
    //  - needed if Map doesn‘t have an extent
    //----------------------------------

    override public function get initialExtent():Extent
    {
        return new Extent(-122.539, 45.500, -122.540, 45.501, new SpatialReference(4326));
    }

    //----------------------------------
    //  spatialReference
    //  - needed if Map doesn‘t have a spatialReference
    //----------------------------------

    override public function get spatialReference():SpatialReference
    {
        return new SpatialReference(4326);
    }

    //----------------------------------
    //  tileInfo
    //----------------------------------

    override public function get tileInfo():TileInfo
    {
        return _tileInfo;
    }

    //----------------------------------
    //  units
    //  - needed if Map doesn‘t have it set
    //----------------------------------

    override public function get units():String
    {
        return "esriDecimalDegrees";
    }

    //--------------------------------------------------------------------------
    //
    //  Overridden methods
    //      getTileURL(level:Number, row:Number, col:Number):URLRequest
    //
    //--------------------------------------------------------------------------

    override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest
    {
        // Use virtual cache directory
        // This assumes the cache‘s virtual directory is exposed, which allows you access
        // to tile from the Web server via the public cache directory.
        // Example of a URL for a tile retrieved from the virtual cache directory:
        // http://serverx.esri.com/arcgiscache/dgaerials/Layers/_alllayers/L01/R0000051f/C000004e4.jpg
        var url:String = _baseURL
            + "/L" + padString(String(level), 2, "0")
            + "/R" + padString(row.toString(16), 8, "0")
            + "/C" + padString(col.toString(16), 8, "0") + ".png";
        return new URLRequest(url);
    }

    //--------------------------------------------------------------------------
    //
    //  Private Methods
    //
    //--------------------------------------------------------------------------

    private function buildTileInfo():void
    {
        _tileInfo.height = 512;
        _tileInfo.width = 512;
        _tileInfo.origin = new MapPoint(-180, 90);
        _tileInfo.spatialReference = new SpatialReference(4326);
        _tileInfo.lods =
            [
            new LOD(0, 0.351562499999999, 147748799.285417),
            new LOD(1, 0.17578125, 73874399.6427087),
            new LOD(2, 0.0878906250000001, 36937199.8213544),
            new LOD(3, 0.0439453125, 18468599.9106772),
            new LOD(4, 0.02197265625, 9234299.95533859),
            new LOD(5, 0.010986328125, 4617149.97766929),
            new LOD(6, 0.0054931640625, 2308574.98883465),
            new LOD(7, 0.00274658203124999, 1154287.49441732),
            new LOD(8, 0.001373291015625, 577143.747208662),
            new LOD(9, 0.0006866455078125, 288571.873604331),
            new LOD(10, 0.000343322753906249, 144285.936802165),
            new LOD(11, 0.000171661376953125, 72142.9684010827),
            new LOD(12, 0.0000858306884765626, 36071.4842005414),
            new LOD(13, 0.0000429153442382813, 18035.7421002707),
            new LOD(14, 0.0000214576721191406, 9017.87105013534),
            new LOD(15, 0.0000107288360595703, 4508.93552506767)
            ];
    }

    private function padString(text:String, size:int, ch:String):String
    {
        while (text.length < size)
        {
            text = ch + text;
        }
        return text;
    }
}

}

customtiled.mxml 

Java代码  技术分享
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:esri="http://www.esri.com/2008/ags"
               xmlns:samples="com.esri.ags.samples.*"
               pageTitle="Extending TiledMapServiceLayer in Flex API">
    <!--
         @@includeFiles com/esri/ags/samples/PortlandTiledMapServiceLayer.as

         This sample shows how tiles can be used without the REST endpoint.

         The ArcGIS API for Flex allows for extending the API
         to access layer types not included as part of the API.
         In this example, tiled layers (TiledMapServiceLayer) is extended
         to access tiles created in 9.2 or above and made accessible
         in the standard virtual directory.

         Steps involved:
         1. Creating new ActionScript class that extends TiledMapServiceLayer.
         2. Hardcoding some of the configuration settings:
         fullExtent, initialExtent, spatialReference, tileInfo, and units.
         3. Overriding the protected function getTileURL() to obtain the appropriate
         tiles and place them accurately on the map.
         4. Using the extended class with MXML or ActionScript :)
    -->

    <esri:Map id="myMap">
        <samples:PortlandTiledMapServiceLayer id="virtualTiles" fadeInFrameCount="12"/>
    </esri:Map>

    <s:Label width="85%"
             backgroundColor="0xFFFF00"
             color="0x000000"
             fontSize="14"
             fontWeight="bold"
             horizontalCenter="0"
             paddingBottom="10"
             paddingLeft="10"
             paddingRight="10"
             paddingTop="10"
             text="By extending TiledMapServiceLayer, this application can access tiles from an ArcGIS 9.2 (or above) virtual directory.  This specific service is in the {virtualTiles.spatialReference.wkid} spatialReference and has {virtualTiles.tileInfo.lods.length} scale levels."/>
</s:Application>

 

WebGIS中通过行列号来换算出多种瓦片的URL 之离线地图(转载)

标签:

原文地址:http://www.cnblogs.com/Vae1990Silence/p/5889182.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!