tile4ms

目的

创建用于MapServer的TileIndex功能的平铺索引形状数据集。程序从[metafile]中列出的所有形状数据集的范围(每行一个形状数据集名称)和关联的dbf创建一个矩形形状数据集,其中每个形状图块的文件名为mapserv所需的location列。

注解

类似的功能可以在gdal命令行实用程序中找到 ogrtindex (对于矢量)和 gdaltindex (为栅格)。

描述

该实用程序创建一个包含所提供文件中所有形状的MBR(最小边界矩形)的形状数据集,然后可以在图层对象的mapfile的tileindex参数中使用。使用此命令创建的新文件由MapServer用于仅加载与该范围(或图块)关联的文件。

句法

tile4ms <meta-file> <tile-file> [-tile-path-only]
<meta-file>     INPUT  file containing list of Shape data set names
                (complete paths 255 chars max, no extension)
<tile-file>     OUTPUT shape file of extent rectangles and names
                of tiles in <tile-file>.dbf
-tile-path-only Optional flag.  If specified then only the path to the
                shape files will be stored in the LOCATION field
                instead of storing the full filename.

简短例子

为/path/to/data目录下的所有磁贴创建tileindex.shp:

   <on Unix>

cd /path/to/data
find . -name "/*.shp" -print > metafile.txt
tile4ms metafile.txt tileindex

   <on Windows>

dir /b /s *.shp > metafile.txt
tile4ms metafile.txt tileindex

长例

本例使用老虎普查数据,其中数据包含按县划分的文件(实际上有3200多个县,实际上是一个非常大的数据集)。在这个例子中,我们将展示如何显示明尼苏达州的所有湖泊。(请注意,我们已经将老虎数据转换为形状格式,但您可以将数据保留为老虎格式,并使用ogrtindex实用程序代替)明尼苏达州的老虎普查数据由87个不同的县组成,每个县都包含自己的湖泊文件(“wp.shp”)。

  1. 我们需要为tile4ms命令创建“meta文件”。这是指向mn状态的所有“wp.shp”文件的路径的文本文件。要创建此文件,我们可以使用以下几个简单命令:

    DOS: dir wp.shp /b /s > wp_list.txt
    (this includes full paths to the data, you might want to edit the txt
    file to remove the full path)
    
    UNIX: find -name *wp.shp -print > wp_list.txt
    

    新创建的文件可能如下所示(删除完整路径后):

    001\wp.shp
    003\wp.shp
    005\wp.shp
    007\wp.shp
    009\wp.shp
    011\wp.shp
    013\wp.shp
    015\wp.shp
    017\wp.shp
    019\wp.shp
    ...
    
  2. 使用新创建的元文件执行tile4ms命令以创建索引文件:

    tile4ms wp_list.txt index
      Processed 87 of 87 files
    
  3. 创建了一个名为“index.shp”的新文件。这是一个索引文件,其中包含整个状态下所有“wp.shp”文件的MBR,如图1所示。该文件的属性表包含一个名为“location”的字段,该字段包含每个“wp.shp文件”的路径,如图2所示。

    图1:tile4ms实用程序创建的索引文件

    ../_images/tile4ms-view.png

    图2:tile4ms实用程序创建的索引文件的属性

    ../_images/tile4ms-attributes.png
  4. 最后一步是在 Mapfile 中使用它。

    • 层对象的tileindex-必须指向索引文件的位置

    • 层对象的tileItem-指定包含路径的索引文件中字段的名称(默认为“location”)。

    • 不需要使用层的数据参数

    例如:

    LAYER
      NAME 'mn-lakes'
      STATUS ON
      TILEINDEX "index"
      TILEITEM "location"
      TYPE POLYGON
      CLASS
        NAME "mn-lakes"
        STYLE
          COLOR 0 0 255
        END
      END
    END
    

当您在MapServer应用程序中查看层时,您会注意到,当您放大到州的一个小区域时,只有这些湖泊层被加载,这会加快应用程序的速度。