基于OGR的WFS输出格式

基于ogr2ogr的输出格式利用了ogr2ogr命令的可用性,允许生成比geoserver本机可以生成的输出格式更多的输出格式。基本思想是将一个文件转储到文件系统,Og2ogr可以翻译、调用、压缩并返回翻译的输出。

开箱即用的行为

插件开箱即用,假设如下:

  • 路径中提供了ogr2ogr

  • gdal_数据变量指向gdal数据目录(该目录存储gdal的空间参考信息)

在默认配置中,支持以下格式:

  • 选项卡格式的地图信息

  • MIF格式的mapinfo

  • 非样式KML

  • csv(无几何数据转储)

如果不是在支持上述格式的情况下构建ogr2ogr,则列表可能会更短。

一旦安装到GeoServer中,将提供四种新的GetFeature输出格式,特别是, OGR-TABOGR-MIFOGR-KMLOGR-CSV .

ogr2ogr转换能力

ogr2ogr实用程序通常能够转换比此输出格式的默认设置允许的格式更多的格式,但确切的列表取决于该实用程序是如何从源代码构建的。要获取您的ogr2ogr构建可用格式的完整列表,请运行:

ogr2ogr --help

您将获得程序可用的完整选项集,以及支持的格式。例如,上面使用fwtools 2.2.8发行版(其中包括其他有用信息和转换工具中的ogr2ogr)生成以下输出:

Usage: ogr2ogr [--help-general] [-skipfailures] [-append] [-update] [-gt n]
            [-select field_list] [-where restricted_where]
            [-sql <sql statement>]
            [-spat xmin ymin xmax ymax] [-preserve_fid] [-fid FID]
            [-a_srs srs_def] [-t_srs srs_def] [-s_srs srs_def]
            [-f format_name] [-overwrite] [[-dsco NAME=VALUE] ...]
            [-segmentize max_dist]
            dst_datasource_name src_datasource_name
            [-lco NAME=VALUE] [-nln name] [-nlt type] [layer [layer ...]]

-f format_name: output file format name, possible values are:
  -f "ESRI Shapefile"
  -f "MapInfo File"
  -f "TIGER"
  -f "S57"
  -f "DGN"
  -f "Memory"
  -f "BNA"
  -f "CSV"
  -f "GML"
  -f "GPX"
  -f "KML"
  -f "GeoJSON"
  -f "Interlis 1"
  -f "Interlis 2"
  -f "GMT"
  -f "SQLite"
  -f "ODBC"
  -f "PostgreSQL"
  -f "MySQL"
  -f "Geoconcept"
-append: Append to existing layer instead of creating new if it exists
-overwrite: delete the output layer and recreate it empty
-update: Open existing output datasource in update mode
-select field_list: Comma-delimited list of fields from input layer to
                    copy to the new layer (defaults to all)
-where restricted_where: Attribute query (like SQL WHERE)
-sql statement: Execute given SQL statement and save result.
-skipfailures: skip features or layers that fail to convert
-gt n: group n features per transaction (default 200)
-spat xmin ymin xmax ymax: spatial query extents
-segmentize max_dist: maximum distance between 2 nodes.
                      Used to create intermediate points
-dsco NAME=VALUE: Dataset creation option (format specific)
-lco  NAME=VALUE: Layer creation option (format specific)
-nln name: Assign an alternate name to the new layer
-nlt type: Force a geometry type for new layer.  One of NONE, GEOMETRY,
     POINT, LINESTRING, POLYGON, GEOMETRYCOLLECTION, MULTIPOINT,
     MULTIPOLYGON, or MULTILINESTRING.  Add "25D" for 3D layers.
     Default is type of source layer.
-a_srs srs_def: Assign an output SRS
-t_srs srs_def: Reproject/transform to this SRS on output
-s_srs srs_def: Override source SRS

Srs_def can be a full WKT definition (hard to escape properly),
or a well known definition (ie. EPSG:4326) or a file with a WKT
definition.

ogr2ogr能够支持的格式的完整列表可以在 OGR site . 请注意,此输出格式只能处理基于文件且支持创建的输出。因此,例如,您将无法使用Postgres输出(因为它基于数据库)或ArcInfo二进制覆盖率(不支持创建)。

定制

如果ogr2ogr在默认路径中不可用,则不设置GDAL_数据,或者如果输出格式需要调整,则 ogr2ogr.xml 文件可以放在GeoServer数据目录的根目录中以自定义输出格式。

默认的geoserver配置等效于以下XML文件:

<OgrConfiguration>
  <ogr2ogrLocation>ogr2ogr</ogr2ogrLocation>
  <!-- <gdalData>...</gdalData> -->
  <formats>
    <Format>
      <ogrFormat>MapInfo File</ogrFormat>
      <formatName>OGR-TAB</formatName>
      <fileExtension>.tab</fileExtension>
    </Format>
    <Format>
      <ogrFormat>MapInfo File</ogrFormat>
      <formatName>OGR-MIF</formatName>
      <fileExtension>.mif</fileExtension>
      <option>-dsco</option>
      <option>FORMAT=MIF</option>
    </Format>
    <Format>
      <ogrFormat>CSV</ogrFormat>
      <formatName>OGR-CSV</formatName>
      <fileExtension>.csv</fileExtension>
      <singleFile>true</singleFile>
      <mimeType>text/csv</mimeType>
    </Format>
    <Format>
      <ogrFormat>KML</ogrFormat>
      <formatName>OGR-KML</formatName>
      <fileExtension>.kml</fileExtension>
      <singleFile>true</singleFile>
      <mimeType>application/vnd.google-earth.kml</mimeType>
    </Format>
  </formats>
</OgrConfiguration>

该文件展示了配置元素的所有可能用法:

  • ogr2ogrLocation 如果命令在路径中,则只能是ogr2ogr,否则它应该是可执行文件的完整路径。例如,在安装了FWTools的Windows框上,它可能是:

    <ogr2ogrLocation>c:\Programmi\FWTools2.2.8\bin\ogr2ogr.exe</ogr2ogrLocation>
    
  • gdalData 必须指向GDAL数据目录。例如,在安装了FWTools的Windows框上,它可能是:

    <gdalData>c:\Programmi\FWTools2.2.8\data</gdalData>
    
  • Format 定义单个格式,该格式由以下标记定义:

    • ogrFormat :要通过-f选项传递给ogr2ogr的格式的名称(区分大小写)。

    • formatName :是GeoServer公布的输出格式的名称

    • fileExtension :是翻译后生成的文件的扩展名(如果有)(可以省略)

    • option :可用于向ogr2ogr命令行添加一个或多个选项。正如您在mif示例中看到的,每个项都必须包含在自己的标记中。通过运行ogr2ogr--help或访问ogr2ogr网页,您可以获得完整的选项列表。还要考虑每个格式都支持特定的创建选项,这些选项列在每个格式的描述页面中(例如,这里是mapinfo one)。

    • singleFile (从2.0.3开始):如果为true,那么转换的输出应该是一个可以直接流回的文件,而无需将其包装成zip文件

    • mimeType (从2.0.3开始):使用 singleFile . 如果未指定 application/octet-stream 将用作默认值。

基于OGR的WPS输出格式

基于OGR的WPS输出格式提供了将特征集合(矢量层)输出类型转换为OGR支持的格式的能力,使用OGR WFS输出格式提供的相同配置和相同的机制(也应为WPS部分安装该输出格式)。

与WFS的情况不同,当客户端选择的执行响应样式为“document”时,WPS输出格式在WPS响应中接收不同的处理,这取决于它们是二进制、文本还是XML:

  • 二进制类型需要进行base64编码才能嵌入XML

  • 文本类型需要包含在CDATA节中

  • XML类型可以按原样集成到响应中

为了理解输出格式的性质一个新的可选配置元素, <type> ,可以添加到 ogr2ogr.xml 配置文件以指定输出性质。可能的值是 binarytextxml ,以防该值丢失, binary 是假设的。下面是一个显示所有可能组合的示例:

<OgrConfiguration>
    <ogr2ogrLocation>ogr2ogr</ogr2ogrLocation>
    <!-- <gdalData>...</gdalData> -->
    <formats>
        <Format>
            <ogrFormat>MapInfo File</ogrFormat>
            <formatName>OGR-TAB</formatName>
            <fileExtension>.tab</fileExtension>
            <type>binary</type> <!-- not really required, it’s the default -->
        </Format>
        <Format>
            <ogrFormat>MapInfo File</ogrFormat>
            <formatName>OGR-MIF</formatName>
            <fileExtension>.mif</fileExtension>
            <option>-dsco</option>
            <option>FORMAT=MIF</option>
        </Format>
        <Format>
            <ogrFormat>CSV</ogrFormat>
            <formatName>OGR-CSV</formatName>
            <fileExtension>.csv</fileExtension>
            <singleFile>true</singleFile>
            <mimeType>text/csv</mimeType>
            <option>-lco</option>
            <option>GEOMETRY=AS_WKT</option>
            <type>text</type>
        </Format>
        <Format>
            <ogrFormat>KML</ogrFormat>
            <formatName>OGR-KML</formatName>
            <fileExtension>.kml</fileExtension>
            <singleFile>true</singleFile>
            <mimeType>application/vnd.google-earth.kml</mimeType>
            <type>xml</type>
        </Format>
    </formats>
</OgrConfiguration>