关键孔标记语言

keyhole标记语言(kml)是一种基于XML的用于管理三维地理空间数据显示的语言。KML是开放地理空间联盟(OGC)的一个标准。

数据访问/连接方法

MAPServer中的KML访问可通过OGR访问。看食人魔 driver page for specific driver information. Read support was initially added to GDAL/OGR version 1.5.0. A more complete KML reader was added to GDAL/OGR in version 1.8.0, through the libKML driver (包括读取多几何图形和kmz文件的能力)。

连接参数必须包含kml或kmz扩展名,数据参数应为层的名称。

CONNECTIONTYPE OGR
CONNECTION "filename.kml"
DATA "layername"

示例1:显示.kml文件

OGRINFO

首先,您应该确保您的GDAL/OGR构建包含“kml”驱动程序,方法是使用“--formats”命令:

>ogrinfo --formats

   Loaded OGR Format Drivers:
   ...
   -> "GML" (read/write)
   -> "GPX" (read/write)
   -> "KML" (read/write)
   ...

如果你没有司机,你可能想试试 FWToolsMS4W 包,其中包括驱动程序。

一旦您有了kml驱动程序,就可以尝试在文件上使用ogrinfo命令来获取可用层的列表:

>ogrinfo myplaces.kml

   INFO: Open of `myplaces.kml'
   using driver `KML' successful.
   1: Layer #0 (Point)

现在使用ogrinfo获取有关层结构的信息:

>ogrinfo fountains-hotel.kml "Layer #0" -summary

  Had to open data source read-only.
  INFO: Open of `fountains-hotel.kml'
    using driver `KML' successful.

  Layer name: Layer #0
  Geometry: Point
  Feature Count: 1
  Extent: (18.424930, -33.919627) - (18.424930, -33.919627)
  Layer SRS WKT:
  GEOGCS["WGS 84",
      DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
          AUTHORITY["EPSG","7030"]],
      AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
      AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.01745329251994328,
      AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
  Name: String (0.0)
  Description: String (0.0)

Mapfile 示例

 LAYER
   NAME "kml_example"
   TYPE POINT
   STATUS DEFAULT
   CONNECTIONTYPE OGR
   CONNECTION "kml/fountains-hotel.kml"
   DATA "Layer #0"
   LABELITEM "NAME"
   CLASS
     NAME "My Places"
     STYLE
       COLOR 250 0 0
       OUTLINECOLOR 255 255 255
       SYMBOL 'circle'
       SIZE 6
     END
   LABEL
     SIZE TINY
     COLOR 0 0 0
     OUTLINECOLOR 255 255 255
     POSITION AUTO
   END
  END
END

示例2:显示.kmz文件

OGRINFO

首先,您应该确保您的GDAL/OGR构建包含“libkml”驱动程序,方法是使用“--formats”命令:

>ogrinfo --formats

   Loaded OGR Format Drivers:
   ...
   -> "GML" (read/write)
   -> "GPX" (read/write)
   -> "LIBKML" (read/write)
   -> "KML" (read/write)
   ...

如果您没有驱动程序,您可能需要尝试 FWTools or MS4W packages, which include the driver. Or you can follow the compiling notes 用于libKML和GDAL/OGR。

一旦您有了libkml驱动程序,就可以尝试在文件上使用ogrinfo命令来获取可用层的列表:

>ogrinfo Lunenburg_Municipality.kmz

   INFO: Open of `Lunenburg_Municipality.kmz'
   using driver `LIBKML' successful.
   1: Lunenburg_Municipality

现在使用ogrinfo获取有关层结构的信息:

>ogrinfo Lunenburg_Municipality.kmz Lunenburg_Municipality -summary

   INFO: Open of `Lunenburg_Municipality.kmz'
      using driver `LIBKML' successful.

   Layer name: Lunenburg_Municipality
   Geometry: Unknown (any)
   Feature Count: 1
   Extent: (-64.946433, 44.133207) - (-64.230281, 44.735125)
   Layer SRS WKT:
   GEOGCS["WGS 84",
       DATUM["WGS_1984",
           SPHEROID["WGS 84",6378137,298.257223563,
               AUTHORITY["EPSG","7030"]],
           TOWGS84[0,0,0,0,0,0,0],
           AUTHORITY["EPSG","6326"]],
       PRIMEM["Greenwich",0,
           AUTHORITY["EPSG","8901"]],
       UNIT["degree",0.0174532925199433,
           AUTHORITY["EPSG","9108"]],
       AUTHORITY["EPSG","4326"]]
   Name: String (0.0)
   description: String (0.0)
   timestamp: DateTime (0.0)
   begin: DateTime (0.0)
   end: DateTime (0.0)
   altitudeMode: String (0.0)
   tessellate: Integer (0.0)
   extrude: Integer (0.0)
   visibility: Integer (0.0)

Mapfile 示例

LAYER
  NAME "lunenburg"
  TYPE POLYGON
  STATUS DEFAULT
  CONNECTIONTYPE OGR
  CONNECTION "Lunenburg_Municipality.kmz"
  DATA "Lunenburg_Municipality"
  CLASS
    NAME "Lunenburg"
    STYLE
      COLOR 244 244 16
      OUTLINECOLOR 199 199 199
    END
  END
END # layer

示例3:显示“超级覆盖”kml文件

超级覆盖是一个包含平铺数据的kml文件,它被分解为“区域”;这是显示大型图像的有效方法。有关超级覆盖的更多背景信息,请参见谷歌开发人员 KML Tutorial .

MapServer可以通过 GDAL .

备注

以下内容在2016-01-17使用gdal 2.0.2-dev进行了测试;在测试此超级覆盖时对gdal进行了一些增强(请参见票据 63106311

GDALINFO

首先,应使用“--formats”命令确保GDAL/OGR构建包含“kmlsuperoverlay”驱动程序:

>gdalinfo --formats

   Supported Formats:
   ...
   R -raster- (rwv): R Object Data Store
   MAP -raster- (rov): OziExplorer .MAP
   KMLSUPEROVERLAY -raster- (rwv): Kml Super Overlay
   PDF -raster,vector- (rw+vs): Geospatial PDF
   ...

如果没有驱动程序,您可能需要检查平台是否有现成的软件包/安装程序(Windows用户请参见 MS4W ,包括驱动程序。

备注

对于这个例子,我们将使用谷歌开发者教程(http://mw1.google.com/mw earth vectordb/kml samples/mv doqq.kml)中引用的远程kml文件。我们还将直接通过 vsicurl ,从1.8.0开始在GDAL中提供

现在使用gdalinfo获取有关层结构的信息:

>gdalinfo /vsicurl/http://mw1.google.com/mw-earth-vectordb/kml-samples/mv-doqq.kml

Driver: KMLSUPEROVERLAY/Kml Super Overlay
Files: none associated
Size is 16384, 16384
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
Origin = (-122.129312658577720,37.439803353779496)
Pixel Size = (0.000004270647777,-0.000004095141704)
Metadata:
  DESCRIPTION=The original is a 7008 x 6720 DOQQ of Mountain View in 1991. (Source:
      http://gis.ca.gov/). This is a Region NetworkLink hierarchy of 900+
      GroundOverlays each of 256 x 256 pixels arranged in a hierarchy such
      that more detailed images are loaded and shown as the viewpoint nears.
      Enable the "Boxes" NetworkLink to see a LineString for
      each Region. Tour the "Boxes" to visit each tile. Visit the
      "A" and "B" Placemarks to see multiple levels of
      hierarchy together. Use the slider on various images in the hierarchy
      to see how the resolution varies and of the entire hierarchy to see
      the imagery below. (Find the Google Campus...).

  NAME=SuperOverlay: MV DOQQ
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (-122.1293127,  37.4398034) (122d 7'45.53"W, 37d26'23.29"N)
Lower Left  (-122.1293127,  37.3727086) (122d 7'45.53"W, 37d22'21.75"N)
Upper Right (-122.0593424,  37.4398034) (122d 3'33.63"W, 37d26'23.29"N)
Lower Right (-122.0593424,  37.3727086) (122d 3'33.63"W, 37d22'21.75"N)
Center      (-122.0943275,  37.4062560) (122d 5'39.58"W, 37d24'22.52"N)
Band 1 Block=256x256 Type=Byte, ColorInterp=Red
  Overviews: 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256
  Mask Flags: PER_DATASET ALPHA
  Overviews of mask band: 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
  Overviews: 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256
  Mask Flags: PER_DATASET ALPHA
  Overviews of mask band: 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
  Overviews: 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256
  Mask Flags: PER_DATASET ALPHA
  Overviews of mask band: 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256
Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha
Overviews: 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256

Mapfile 示例

最后,使用 栅格类型, 就像其他的锉刀一样,比如:

MAP
  NAME "superoverlay"
  STATUS ON
  SIZE 400 300
  EXTENT -122.1293127 37.3727086 -122.0593424 37.4398034
  UNITS DD
  IMAGECOLOR 255 255 255

  LAYER
    NAME "mountain-view-superoverlay"
    TYPE RASTER
    STATUS ON
    DATA "/vsicurl/http://mw1.google.com/mw-earth-vectordb/kml-samples/mv-doqq.kml"
    CLASS
      NAME "Superoverlay"
      STYLE
      END #style
    END #class
  END #layer

END #Map

使用shp2img命令测试映射文件

测试超级覆盖映射文件的最简单方法是使用mapserver shp2img utility .

>shp2img -m superoverlay-kml.map -o ttt.png -all_debug 3

msLoadMap(): 0.000s
msDrawMap(): rendering using outputformat named png (AGG/PNG).
msDrawMap(): WMS/WFS set-up and query, 0.000s
msDrawRasterLayerLow(mountain-view-superoverlay): entering.
msDrawRasterLayerGDAL(): Entering transform.
msDrawRasterLayerGDAL(): src=0,0,16384,16384, dst=44,0,312,300
msDrawRasterLayerGDAL(): source raster PL (-4.888,-27.409) for dst PL (44,0).
msDrawRasterLayerGDAL(): red,green,blue,alpha bands = 1,2,3,4
msDrawMap(): Layer 0 (mountain-view-superoverlay), 4.314s
msDrawMap(): Drawing Label Cache, 0.008s
msDrawMap() total time: 4.347s
msSaveImage(ttt.png) total time: 0.090s
shp2img total time: 4.441s

应生成以下地图图像:

../../_images/kml-superoverlay.png