GML-地理标记语言

司机简称

GML

生成依赖项

(读取支持需要Xerces或libexpat)

OGR对GML读写的支持有限。不支持更新现有文件。

支持的GML口味:

GML2和GML3可以

GML 2.1.2或GML 3 SF-0

转化为简单的特征模型

(GML 3.1.1符合性等级SF-0)

从另一个驱动程序GDAL 2.2开始, GMLAS 对于由应用程序架构驱动的GML,也可以使用。GML和GMLAS驱动程序都有自己的用例。

驱动程序功能

Supports Create()

This driver supports the GDALDriver::Create() operation

Supports Georeferencing

This driver supports georeferencing

Supports VirtualIO

This driver supports virtual I/O operations (/vsimem/, etc.)

分析器

驱动程序的读取部分只有在OGR中链接了Xerces时才能工作。当Xerces不可用时,如果构建OGR时链接了Expat,那么读取支持也可以工作。默认情况下禁用XML验证。即使没有Xerces或Expat,也始终支持GML编写。

Note: if both Xerces and Expat are available at build time, the GML driver will preferentially select at runtime the Expat parser for cases where it is possible (GML file in a compatible encoding), and default back to Xerces parser in other cases. However, the choice of the parser can be overridden by specifying the GML_PARSER configuration option to EXPAT or XERCES.

CRS支持

The GML driver has coordinate system support. This is only reported when all the geometries of a layer have a srsName attribute, whose value is the same for all geometries. For srsName such as "urn:ogc:def:crs:EPSG:" (or "http://www.opengis.net/def/crs/EPSG/0/" starting with GDAL 2.1.2), for geographic coordinate systems (as returned by WFS 1.1.0 for example), the axis order should be (latitude, longitude) as required by the standards, but this is unusual and can cause issues with applications unaware of axis order. So by default, the driver will swap the coordinates so that they are in the (longitude, latitude) order and report a SRS without axis order specified. It is possible to get the original (latitude, longitude) order and SRS with axis order by setting the configuration option GML_INVERT_AXIS_ORDER_IF_LAT_LONG to NO.

There also situations where the srsName is of the form "EPSG:XXXX" (whereas "urn:ogc:def:crs:EPSG::XXXX" would have been more explicit on the intent) and the coordinates in the file are in (latitude, longitude) order. By default, OGR will not consider the EPSG axis order and will report the coordinates in (latitude,longitude) order. However, if you set the configuration option GML_CONSIDER_EPSG_AS_URN to YES, the rules explained in the previous paragraph will be applied.

以上也适用于EPSG优先轴顺序为(北距、东距)的投影坐标系。

Starting with GDAL 2.1.2, the SWAP_COORDINATES open option (or GML_SWAP_COORDINATES configuration option) can be set to AUTO/YES/NO. It controls whether the order of the x/y or long/lat coordinates should be swapped. In AUTO mode, the driver will determine if swapping must be done from the srsName and value of other options like CONSIDER_EPSG_AS_URN and INVERT_AXIS_ORDER_IF_LAT_LONG. When SWAP_COORDINATES is set to YES, coordinates will be always swapped regarding the order they appear in the GML, and when it set to NO, they will be kept in the same order. The default is AUTO.

图式

与大多数GML读取器不同,OGR GML读取器不需要存在特性类(扩展名为.xsd的文件)的XML模式定义就可以读取GML文件。如果.xsd文件不存在或OGR无法解析它,驱动程序将尝试通过扫描该文件并在gml命名空间中查找“已知”gml对象来确定组织,从而自动发现功能类及其相关属性。虽然这种方法容易出错,但它的优点是即使关联的架构(.xsd)文件已丢失,也可以处理GML文件。

可以通过使用“a”为XSD模式指定要使用的显式文件名_文件名.gml,xsd=另一个_文件名.xsd“作为连接字符串。XSD也可以指定为XSD open选项的值。

第一次打开GML文件时,如果关联的.xsd不存在或无法正确分析,则会对其进行完全扫描,以确定功能类型集、关联的属性以及其他数据集级别的信息。此信息存储在一个.gfs文件中,该文件的基名称与目标gml文件的基名称相同。对同一GML文件的后续访问将使用.gfs文件预定义加速访问的数据集级信息。在一定程度上,可以手动编辑.gfs文件,以改变GML文件的解析方式。请注意,如果关联的.gml文件具有较新的时间戳,则将忽略.gfs文件。

When prescanning the GML file to determine the list of feature types, and fields, the contents of fields are scanned to try and determine the type of the field. In some applications it is easier if all fields are just treated as string fields. This can be accomplished by setting the configuration option GML_FIELDTYPES to the value ALWAYS_STRING.

The GML_ATTRIBUTES_TO_OGR_FIELDS configuration option can be set to YES so that attributes of GML elements are also taken into account to create OGR fields.

The following configuration options are available:

configuration options can e.g. be set via the CPLSetConfigOption() function or as environment variables.

You can use GML_GFS_TEMPLATE configuration option (or GFS_TEMPLATE open option) set to a path_to_template.gfs in order to unconditionally use a predefined GFS file. This option is really useful when you are planning to import many distinct GML files in subsequent steps [-append] and you absolutely want to preserve a fully consistent data layout for the whole GML set. Please, pay attention not to use the -lco LAUNDER=yes setting when using GML_GFS_TEMPLATE; this should break the correct recognition of attribute names between subsequent GML import runs.

特定的GML应用程序架构

在嵌套的GML元素(非平面属性层次结构)中的特征属性可以在一些GML配置文件中找到,例如英国地形测量总图。当一个GML元素出现多次时,还支持IntegerList、RealList和StringList字段类型。

一个专门的GML驱动程序 NAS 驱动程序-可用于读取德语AAA GML交换格式(NAS/ALKIS)。

GML驱动程序部分支持读取AIXM或CityGML文件。

GML驱动程序支持读取:

GML驱动程序支持读取对CSW GetRecords查询的响应。

自OGR 2.2以来,GML驱动程序支持读取日语FGD GML v4文件。

几何阅读

读取特征时,默认情况下,驱动程序将只考虑在描述特征的XML子树中找到的最后一个识别的GML几何体(如果它们是多个)。

但是,如果.xsd模式被xsd解析器理解并声明了几个几何字段,或者.gfs文件声明了几个几何字段,那么GML驱动程序将根据 RFC 41:支持OGR中的多个几何字段 .

如果存在多个几何体引用,如果某个几何体位于<geometry>元素中,则该几何体将是选定的几何体。这将使默认行为与Inspire对象一致。

用户可以通过使用<GeometryElementPath>元素指定其路径来更改.gfs文件以选择适当的几何体。请参见下面对.gfs语法的描述。

GML geometries including TopoCurve, TopoSurface, MultiCurve are also supported. The TopoCurve type GML geometry can be interpreted as either of two types of geometries. The Edge elements in it contain curves and their corresponding nodes. By default only the curves, the main geometries, are reported as OGRMultiLineString. To retrieve the nodes, as OGRMultiPoint, the configuration option GML_GET_SECONDARY_GEOM should be set to the value YES. When this is set only the secondary geometries are reported.

Arc、ArcString、ArcByBulge、ArcByCenterPoint、Circle和CircleByCenterPoints将作为圆形字符串OGR几何体返回。如果它们包含在其他GML元素中,如CurveComposite、MultiCurve、Surface,则相应的非线性OGR几何也将返回。在读取GML3应用程序架构时,几何字段的声明(如CurvePropertyType、SurfacePropertyType、MultiCurvePropertyType或MultiSurfacePropertyType)也将被解释为潜在的非线性几何体,相应的OGR几何体类型将用于层几何体类型。

地表解释规则 [多边形和内部孔]

当多边形包含任何内部孔时,GML驱动程序能够识别地形表面的两种不同解释规则:

  • 先前支持的解释规则假定:

    • 每个地形表面可以表示为许多面的集合

    • 积极的 面孔 [i.e. declaring orientation="+"] 假设表示某个多边形的外环。

    • ** 面孔 [i.e. declaring orientation="-"] 假设代表一个内环(aka hole )属于最新公布的外环。

    • 对用于表示每个环的任何边进行排序是很重要的:每个边都应与下一个边完全相邻。

  • 新的解释规则现在假定:

    • 每个地形表面可以表示为许多面的集合

    • 声明的 方向 因为任何一个面都与外部/内部环无关

    • 现在,每个面都要表示一个完整的多边形,最终包括任何可能的内环(

    • 构成同一面的任何边的相对顺序完全不相关

最新的解释似乎完全符合GML 3标准建议;因此,现在假设这一最新的解释是OGR支持的默认解释。

NOTE :使用最新的解释需要针对GEOS库构建GDAL/OGR。

Using the GML_FACE_HOLE_NEGATIVE configuration option you can anyway select the actual interpretation to be applied when parsing GML 3 topologies:

  • setting GML_FACE_HOLE_NEGATIVE =NO (default option) will activate the newest interpretation rule

  • but explicitly setting GML_FACE_HOLE_NEGATIVE =YES still enables to activate the old interpretation rule

编码问题

Expat库支持读取以下内置编码:

  • US-ASCII码

  • UTF-8

  • UTF-16型

  • ISO-859-1

  • Windows-1252

OGR返回的内容将在从文件头中提到的编码转换为后用UTF-8编码。

如果GML文件没有在以前的编码中进行编码,并且唯一可用的解析器是Expat,则GML驱动程序将不会对其进行解析。您可以使用 iconv公司 例如实用程序,并相应地更改 编码 XML头中的参数值。

编写GML文件时,驱动程序希望传入UTF-8内容。

注意:使用集成的XML解析器解析.xsd架构文件,该解析器当前不理解XML头中指定的XML编码。它希望编码始终是UTF-8。如果模式文件中的属性名包含非ascii字符,则最好使用 iconv公司 实用程序并首先将.xsd文件转换为UTF-8编码。

特征标识(fid/gml:id)

驱动程序公开gml:id属性作为名为 gml_id ,当读取GML WFS文档时。创建GML3文档时,如果调用了字段 gml_id ,其内容还将用于编写所创建功能的gml:id属性的内容。

The driver autodetects the presence of a fid (GML2) (resp. gml:id (GML3)) attribute at the beginning of the file, and, if found, exposes it by default as a fid (resp. gml_id) field. The autodetection can be overridden by specifying the GML_EXPOSE_FID or GML_EXPOSE_GML_ID configuration option to YES or NO.

创建GML2文档时,如果调用 fid ,其内容还将用于编写所创建要素的fid属性的内容。

大型多层GML文件的性能问题。

每个GML数据源只有一个GML解析器在各个层之间共享。默认情况下,GML驱动程序将从文件的开头重新开始读取,每次第一次访问一个层时,这可能会导致使用大型GML文件时性能不佳。

The GML_READ_MODE configuration option can be set to SEQUENTIAL_LAYERS if all features belonging to the same layer are written sequentially in the file. The reader will then avoid unnecessary resets when layers are read completely one after the other. To get the best performance, the layers must be read in the order they appear in the file.

If no .xsd and .gfs files are found, the parser will detect the layout of layers when building the .gfs file. If the layers are found to be sequential, a <SequentialLayers>true</SequentialLayers> element will be written in the .gfs file, so that the GML_READ_MODE will be automatically initialized to SEQUENTIAL_LAYERS if not explicitly set by the user.

The GML_READ_MODE configuration option can be set to INTERLEAVED_LAYERS to be able to read a GML file whose features from different layers are interleaved. In the case, the semantics of the GetNextFeature() will be slightly altered, in a way where a NULL return does not necessarily mean that all features from the current layer have been read, but it could also mean that there is still a feature to read, but that belongs to another layer. In that case, the file should be read with code similar to the following one :

int nLayerCount = poDS->GetLayerCount();
int bFoundFeature;
do
{
    bFoundFeature = FALSE;
    for( int iLayer = 0; iLayer < nLayerCount; iLayer++ )
    {
        OGRLayer   *poLayer = poDS->GetLayer(iLayer);
        OGRFeature *poFeature;
        while((poFeature = poLayer->GetNextFeature()) != NULL)
        {
            bFoundFeature = TRUE;
            poFeature->DumpReadable(stdout, NULL);
            OGRFeature::DestroyFeature(poFeature);
        }
    }
} while (bInterleaved && bFoundFeature);

打开选项

  • XSD=filename :指定XSD应用程序架构要使用的显式文件名。

  • WRITE_GFS=AUTO/YES/NO :(GDAL>=3.2)是否写入.gfs文件。在自动模式下,只有在没有可识别的.xsd文件、没有现有的.gfs文件以及非网络文件系统的情况下,才会写入.gfs文件。在AUTO不尝试写入force.gfs文件的情况下,可以将此选项设置为YES。也可以将其设置为“否”以禁用.gfs文件写入。

  • GFS_TEMPLATE=filename :无条件使用预定义的GFS文件。当您计划在后续步骤中导入许多不同的GML文件时,此选项非常有用 [-append] 您绝对希望为整个GML集保留完全一致的数据布局。请注意不要使用 -lco LAUNDER=yes 设置此选项时;这将中断后续GML导入运行之间对属性名称的正确识别。

  • FORCE_SRS_DETECTION=YES/NO :强制全扫描以检测层的SRS。如果.gml文件附带.xsd,则可能需要此选项。通常在这种情况下,OGR不会检测到SRS,因为这需要对文件进行完全扫描。默认为“否”

  • EMPTY_AS_NULL=YES/NO :默认情况下(EMPTY_AS_NULL=YES),内容为空的字段将报告为NULL,而不是空字符串。这是历史性的行为。但是,如果应用程序架构将这些字段声明为强制字段,则这将防止这些字段被声明为不可为null。因此,可以将此选项设置为NO,以使空字符串和强制字段都被报告为不可为空。

  • GML_ATTRIBUTES_TO_OGR_FIELDS=YES/NO :GML属性是否应报告为OGR字段。请注意,此选项仅在第一次打开GML文件时(在创建.gfs文件之前)以及没有有效关联的.xsd时有效。默认为“否”。

  • INVERT_AXIS_ORDER_IF_LAT_LONG=YES/NO :是否在传统GIS顺序中显示SRS和坐标顺序。默认为“是”。

  • CONSIDER_EPSG_AS_URN=YES/NO/AUTO :是否考虑srsName-likeEPSG:XXXX as公司关于EPSG轴顺序。默认为自动。

  • SWAP_COORDINATES =AUTO/YES/NO:(GDAL>=2.1.2)是否应交换x/y或long/lat坐标的顺序。在自动模式下,驱动程序将确定是否必须从srsName和其他选项的值进行交换,如将EPSG视为URN和反转轴顺序(如果长)。当SWAPu COORDINATES设置为YES时,坐标将始终按照它们在GML中出现的顺序进行交换,当设置为NO时,坐标将保持相同的顺序。默认值为“自动”。

  • READ_MODE=AUTO/STANDARD/SEQUENTIAL_LAYERS/INTERLEAVED_LAYERS :读取模式。默认为自动。

  • EXPOSE_GML_ID=YES/NO/AUTO :是否制作功能gml:id as公司gmlu id属性。默认为自动。

  • EXPOSE_FID=YES/NO/AUTO :是否将特征fid设为fid属性。默认为自动。

  • DOWNLOAD_SCHEMA=YES/NO :如果需要,是否下载远程应用程序架构(目前仅适用于WFS)。默认为“是”。

  • REGISTRY=filename: Filename of the registry with application schemas. Defaults to {GDAL_DATA}/gml_registry.xml.

创建问题

导出时,所有图层都将写入单个GML文件,所有图层都位于单个要素集合中。每个层的名称用作该层对象的元素名称。几何图形始终作为要素上的ogr:geometryProperty元素写入。

数据集创建选项

  • XSISCHEMAURI :如果提供,则此URI将作为架构位置插入。注意,OGR实际上并不访问模式文件,因此由用户来确保它与OGR生成的GML数据文件的模式匹配。

  • XSISCHEMA :可以是外部、内部或关闭,默认为外部。这会将GML应用程序架构文件写入相应的.xsd文件(具有相同的基名)。如果使用INTERNAL,模式将写入GML文件中,但这是实验性的,几乎肯定不是有效的XML。OFF禁用模式生成(如果使用XSISCHEMAURI则是隐式的)。

  • PREFIX 默认为“ogr”。这是应用程序目标命名空间的前缀。

  • STRIP_PREFIX 默认为FALSE。可以设置为TRUE,以避免在GML文件中写入应用程序目标命名空间的前缀。

  • TARGET_NAMESPACE 默认为'http://ogr.maptools.org/'. 这是应用程序目标命名空间。

  • FORMAT :可设置为:

    • GML2 in order to write GML files that follow GML 2.1.2 (Default before GDAL 3.4)

    • GML3 以便编写遵循GML 3.1.1 SF-0配置文件的GML文件。

    • GML3Deegree公司 为了生成GML3.1.1.XSD模式,与GML3 SF-0概要文件推荐的内容相比有一些变化,但这将被一些软件(如Deegree3)更好地接受。

    • GML3.2in order to write GML files that follow GML 3.2.1 SF-0 profile. (Default since GDAL 3.4)

    Non-linear geometries can be written. This is only compatible with selecting on of that above GML3 format variant. Otherwise, such geometries will be approximating into their closest matching linear geometry. Note: fields of type StringList, RealList or IntegerList can be written. This will cause to advertise the SF-1 profile in the .XSD schema (such types are not supported by SF-0).

  • GML_FEATURE_COLLECTION =YES/NO(OGR>=2.3)是否使用gml:FeatureCollection,而不是在目标命名空间中创建专用容器元素。仅对FORMAT=GML3/GML3.2有效。注意,gml:FeatureCollection在gml 3.2中已被弃用,OGC 06-049r1“地理标记语言(gml)简单功能配置文件”(对于gml3.1.1)和OGC 10-100r3“地理标记语言(gml)简单功能配置文件(带勘误)”规范(对于gml3.2)不允许使用。

  • GML3_LONGSRS =YES/NO(仅当FORMAT=GML3/GML3Degree/GML3.2时有效)被GDAL 2.2中的SRSNAMEu格式否决。默认为“是”。如果是,则具有EPSG权限的SRS将使用骨灰盒:ogc:定义:crs:EPSG::“前缀。如果SRS是没有明确轴顺序的SRS,但使用ImportFromEPSGA()导入的同一SRS授权代码应被视为lat/long或northing/easting,则该函数将负责坐标顺序交换。如果设置为NO,则具有EPSG权限的SRS将以“EPSG:”前缀写入,即使它们是按lat/long顺序写入。

  • SRSNAME_FORMAT =SHORT/OGC_URN/OGC_URL(仅对FORMAT=GML3/GML3Degree/GML3.2,GDAL>=2.2有效)。默认为OGC_URN。如果短,则SRS NAME的格式为AUTHORITY_NAME:AUTHORITY_CODE如果是OGC_URN,则srsName的格式为URN:OGC:def:crs:AUTHORITY_NAME::AUTHORITY_CODE如果是OGC_URL,则srsName的格式为http://www.opengis.net/def/crs/AUTHORITY_NAME/0/AUTHORITY_CODE,如果SRS是没有显式轴的SRSorder,但是用ImportFromEPSGA()导入的同一SRS权限代码应该被视为lat/long或northing/easting,然后函数将负责坐标顺序交换。

  • SRSDIMENSION_LOC =POSLIST/GEOMETRY/GEOMETRY,POSLIST。(仅对FORMAT=GML3/GML3Degree/GML3.2有效)默认为POSLIST。对于2.5D几何图形,请定义要附加srsDimension属性的位置。有不同的实现。一些放在桌子上<gml:posList文件>元素,其他位于顶部几何图元上。

  • WRITE_FEATURE_BOUNDED_BY =YES/NO(仅当FORMAT=GML3/GML3Degree/GML3.2时有效)默认为YES。如果设置为“否”<gml:边界>不会为每个功能编写元素。

  • SPACE_INDENTATION =是/否。默认为是。如果是,输出将以空格缩进以提高可读性,但以牺牲文件大小为代价。

  • GML_ID =字符串。(仅对GML 3.2有效)特征集合的值gml:id.默认值值为“aFeatureCollection”。

  • NAME =字符串。GML name元素的内容。也可以设置为数据集上的名称元数据项。

  • DESCRIPTION =字符串。GML描述元素的内容。也可以设置为数据集上的描述元数据项。

VSI虚拟文件系统API支持

驱动程序支持读取和写入由VSI虚拟文件系统API管理的文件,这些文件包括“常规”文件以及/vsizip/(读写)、/vsigzip/(读写)、/vsicurl/(只读)域中的文件。

还支持写入/dev/stdout或/vsistdout/。注意,在这种情况下,只有GML文件的内容才会写入标准输出(而不是.xsd)。不会写入<boundedBy>元素。如果在/vsigzip中写入/

.gfs文件语法示例

让我们考虑以下test.gml文件:

<?xml version="1.0" encoding="UTF-8"?>
<gml:FeatureCollection xmlns:gml="http://www.opengis.net/gml">
  <gml:featureMember>
    <LAYER>
      <attrib1>attrib1_value</attrib1>
      <attrib2container>
        <attrib2>attrib2_value</attrib2>
      </attrib2container>
      <location1container>
        <location1>
            <gml:Point><gml:coordinates>3,50</gml:coordinates></gml:Point>
        </location1>
      </location1container>
      <location2>
        <gml:Point><gml:coordinates>2,49</gml:coordinates></gml:Point>
      </location2>
    </LAYER>
  </gml:featureMember>
</gml:FeatureCollection>

以及以下相关的.gfs文件。

<GMLFeatureClassList>
  <GMLFeatureClass>
    <Name>LAYER</Name>
    <ElementPath>LAYER</ElementPath>
    <GeometryElementPath>location1container|location1</GeometryElementPath>
    <PropertyDefn>
      <Name>attrib1</Name>
      <ElementPath>attrib1</ElementPath>
      <Type>String</Type>
      <Width>13</Width>
    </PropertyDefn>
    <PropertyDefn>
      <Name>attrib2</Name>
      <ElementPath>attrib2container|attrib2</ElementPath>
      <Type>String</Type>
      <Width>13</Width>
    </PropertyDefn>
  </GMLFeatureClass>
</GMLFeatureClassList>

请注意<ElementPath>和<GeometryElementPath>元素中存在“|”字符,以指定所需的字段/几何体元素,该元素是嵌套的XML元素。支持嵌套字段元素,并指定<GeometryElementPath>如果未指定GeometryElementPath,GML驱动程序将使用最后识别的几何元素。

可以指定<geometry type>元素来强制几何体类型。接受的值为:0(任何几何类型)、1(点)、2(线串)、3(多边形)、4(多点)、5(多线串)、6(多多边形)、7(几何集合)。

可以指定<GeometryElementPath>和<GeometryType>的次数与GML文件中的几何体字段的次数相同。另一种可能性是根据需要多次定义<GeomPropertyDefn>元素:

<GMLFeatureClassList>
  <GMLFeatureClass>
    <Name>LAYER</Name>
    <ElementPath>LAYER</ElementPath>
    <GeomPropertyDefn>
        <Name>geometry</Name> <!-- OGR geometry name -->
        <ElementPath>geometry</ElementPath> <!-- XML element name possibly with '|' to specify the path -->
        <Type>MultiPolygon</Type>
    </GeomPropertyDefn>
    <GeomPropertyDefn>
        <Name>referencePoint</Name>
        <ElementPath>referencePoint</ElementPath>
        <Type>Point</Type>
    </GeomPropertyDefn>
  </GMLFeatureClass>
</GMLFeatureClassList>

产量 ogrinfo test.gml -ro -al 是:

Layer name: LAYER
Geometry: Unknown (any)
Feature Count: 1
Extent: (3.000000, 50.000000) - (3.000000, 50.000000)
Layer SRS WKT:
(unknown)
Geometry Column = location1container|location1
attrib1: String (13.0)
attrib2: String (13.0)
OGRFeature(LAYER):0
  attrib1 (String) = attrib1_value
  attrib2 (String) = attrib2_value
  POINT (3 50)

高级.gfs语法

指定ElementPath以查找嵌入顶级对象的对象

让我们考虑以下test.gml文件:

<?xml version="1.0" encoding="utf-8"?>
<gml:FeatureCollection xmlns:xlink="http://www.w3.org/1999/xlink"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       gml:id="foo" xmlns:gml="http://www.opengis.net/gml/3.2">
  <gml:featureMember>
    <TopLevelObject gml:id="TopLevelObject.1">
      <content>
        <Object gml:id="Object.1">
          <geometry>
            <gml:Polygon gml:id="Object.1.Geometry" srsName="urn:ogc:def:crs:EPSG::4326">
              <gml:exterior>
                <gml:LinearRing>
                  <gml:posList srsDimension="2">48 2 49 2 49 3 48 3 48 2</gml:posList>
                </gml:LinearRing>
              </gml:exterior>
            </gml:Polygon>
          </geometry>
          <foo>bar</foo>
        </Object>
      </content>
      <content>
        <Object gml:id="Object.2">
          <geometry>
            <gml:Polygon gml:id="Object.2.Geometry" srsName="urn:ogc:def:crs:EPSG::4326">
              <gml:exterior>
                <gml:LinearRing>
                  <gml:posList srsDimension="2">-48 2 -49 2 -49 3 -48 3 -48 2</gml:posList>
                </gml:LinearRing>
              </gml:exterior>
            </gml:Polygon>
          </geometry>
          <foo>baz</foo>
        </Object>
      </content>
    </TopLevelObject>
  </gml:featureMember>
</gml:FeatureCollection>

默认情况下,只报告TopLevelObject,并且只使用第二个几何体。在那个实例中,这不是期望的行为。您可以编辑生成的.gfs并按以下方式修改它,以便指定元素的完整路径(省略顶级XML元素):

<GMLFeatureClassList>
  <GMLFeatureClass>
    <Name>Object</Name>
    <ElementPath>featureMember|TopLevelObject|content|Object</ElementPath>
    <GeometryType>3</GeometryType>
    <PropertyDefn>
      <Name>foo</Name>
      <ElementPath>foo</ElementPath>
      <Type>String</Type>
    </PropertyDefn>
  </GMLFeatureClass>
</GMLFeatureClassList>

获取XML属性作为OGR字段

element@attribute语法可用于<ElementPath>中,以指定必须获取element'element'的attribute'attribute'的值。

让我们考虑以下test.gml文件:

<?xml version="1.0" encoding="UTF-8"?>
<gml:FeatureCollection xmlns:gml="http://www.opengis.net/gml">
  <gml:featureMember>
    <LAYER>
      <length unit="m">5</length>
    </LAYER>
  </gml:featureMember>
</gml:FeatureCollection>

以及以下相关的.gfs文件。

<GMLFeatureClassList>
  <GMLFeatureClass>
    <Name>LAYER</Name>
    <ElementPath>LAYER</ElementPath>
    <GeometryType>100</GeometryType> <!-- no geometry -->
    <PropertyDefn>
      <Name>length</Name>
      <ElementPath>length</ElementPath>
      <Type>Real</Type>
    </PropertyDefn>
    <PropertyDefn>
      <Name>length_unit</Name>
      <ElementPath>length@unit</ElementPath>
      <Type>String</Type>
    </PropertyDefn>
  </GMLFeatureClass>
</GMLFeatureClassList>

产量 ogrinfo test.gml -ro -al 是:

Layer name: LAYER
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
gml_id: String (0.0)
length: Real (0.0)
length_unit: String (0.0)
OGRFeature(LAYER):0
  gml_id (String) = (null)
  length (Real) = 5
  length_unit (String) = m

对XML属性使用条件

<Condition>元素可以指定为<PropertyDefn>的子元素。条件的内容遵循一种最简的XPath语法。必须是@attrname格式 [=|!=] '属性值' [and|or other_cond] *. 请注意,不能混合使用“and”和“or”运算符(不考虑它们的优先级)。

可以用相同的<ElementPath>定义多个<PropertyDefn>,但必须用互斥的<Condition>定义。

让我们考虑以下testcondition.gml文件:

<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
     xmlns:ogr="http://ogr.maptools.org/"
     xmlns:gml="http://www.opengis.net/gml">
  <gml:featureMember>
    <ogr:testcondition fid="testcondition.0">
      <ogr:name lang="en">English name</ogr:name>
      <ogr:name lang="fr">Nom francais</ogr:name>
      <ogr:name lang="de">Deutsche name</ogr:name>
    </ogr:testcondition>
  </gml:featureMember>
</ogr:FeatureCollection>

以及以下相关的.gfs文件。

<GMLFeatureClassList>
  <GMLFeatureClass>
    <Name>testcondition</Name>
    <ElementPath>testcondition</ElementPath>
    <GeometryType>100</GeometryType>
    <PropertyDefn>
      <Name>name_en</Name>
      <ElementPath>name</ElementPath>
      <Condition>@lang='en'</Condition>
      <Type>String</Type>
    </PropertyDefn>
    <PropertyDefn>
      <Name>name_fr</Name>
      <ElementPath>name</ElementPath>
      <Condition>@lang='fr'</Condition>
      <Type>String</Type>
    </PropertyDefn>
    <PropertyDefn>
      <Name>name_others_lang</Name>
      <ElementPath>name@lang</ElementPath>
      <Condition>@lang!='en' and @lang!='fr'</Condition>
      <Type>StringList</Type>
    </PropertyDefn>
    <PropertyDefn>
      <Name>name_others</Name>
      <ElementPath>name</ElementPath>
      <Condition>@lang!='en' and @lang!='fr'</Condition>
      <Type>StringList</Type>
    </PropertyDefn>
  </GMLFeatureClass>
</GMLFeatureClassList>

产量 ogrinfo testcondition.gml -ro -al 是:

Layer name: testcondition
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
fid: String (0.0)
name_en: String (0.0)
name_fr: String (0.0)
name_others_lang: StringList (0.0)
name_others: StringList (0.0)
OGRFeature(testcondition):0
  fid (String) = testcondition.0
  name_en (String) = English name
  name_fr (String) = Nom francais
  name_others_lang (StringList) = (1:de)
  name_others (StringList) = (1:Deutsche name)

GML应用程序架构的注册表

GDAL安装的“data”目录包含一个“gml_registry.xml”文件,该文件将gml应用程序架构的功能类型链接到包含其定义的.xsd或.gfs文件。如果在GML文件旁边找不到有效的.gfs或.xsd文件,则使用此选项。

通过将注册表文件的完整路径名设置为GML_注册表配置选项,可以定义注册表文件的备用位置。

这种文件的一个例子是:

<gml_registry>
    <!-- Finnish National Land Survey cadastral data -->
    <namespace prefix="ktjkiiwfs" uri="http://xml.nls.fi/ktjkiiwfs/2010/02" useGlobalSRSName="true">
        <featureType elementName="KiinteistorajanSijaintitiedot"
                 schemaLocation="http://xml.nls.fi/XML/Schema/sovellus/ktjkii/modules/kiinteistotietojen_kyselypalvelu_WFS/Asiakasdokumentaatio/ktjkiiwfs/2010/02/KiinteistorajanSijaintitiedot.xsd"/>
        <featureType elementName="PalstanTunnuspisteenSijaintitiedot"
                 schemaLocation="http://xml.nls.fi/XML/Schema/sovellus/ktjkii/modules/kiinteistotietojen_kyselypalvelu_WFS/Asiakasdokumentaatio/ktjkiiwfs/2010/02/palstanTunnuspisteenSijaintitiedot.xsd"/>
        <featureType elementName="RekisteriyksikonTietoja"
                 schemaLocation="http://xml.nls.fi/XML/Schema/sovellus/ktjkii/modules/kiinteistotietojen_kyselypalvelu_WFS/Asiakasdokumentaatio/ktjkiiwfs/2010/02/RekisteriyksikonTietoja.xsd"/>
        <featureType elementName="PalstanTietoja"
                 schemaLocation="http://xml.nls.fi/XML/Schema/sovellus/ktjkii/modules/kiinteistotietojen_kyselypalvelu_WFS/Asiakasdokumentaatio/ktjkiiwfs/2010/02/PalstanTietoja.xsd"/>
    </namespace>

    <!-- Inspire CadastralParcels schema -->
    <namespace prefix="cp" uri="urn:x-inspire:specification:gmlas:CadastralParcels:3.0" useGlobalSRSName="true">
        <featureType elementName="BasicPropertyUnit"
                     gfsSchemaLocation="inspire_cp_BasicPropertyUnit.gfs"/>
        <featureType elementName="CadastralBoundary"
                     gfsSchemaLocation="inspire_cp_CadastralBoundary.gfs"/>
        <featureType elementName="CadastralParcel"
                     gfsSchemaLocation="inspire_cp_CadastralParcel.gfs"/>
        <featureType elementName="CadastralZoning"
                     gfsSchemaLocation="inspire_cp_CadastralZoning.gfs"/>
    </namespace>

    <!-- Czech RUIAN (VFR) schema (v1) -->
    <namespace prefix="vf"
               uri="urn:cz:isvs:ruian:schemas:VymennyFormatTypy:v1 ../ruian/xsd/vymenny_format/VymennyFormatTypy.xsd"
               useGlobalSRSName="true">
        <featureType elementName="TypSouboru"
                     elementValue="OB"
                     gfsSchemaLocation="ruian_vf_ob_v1.gfs"/>
        <featureType elementName="TypSouboru"
                     elementValue="ST"
                     gfsSchemaLocation="ruian_vf_st_v1.gfs"/>
    </namespace>
</gml_registry>

XML架构定义(.xsd)文件由schemaLocation属性指向,而OGR.gfs文件由gfsSchemaLocation属性指向。在这两种情况下,文件名都可以是URL(http://https://)、绝对文件名或相对文件名(相对于gml_registry.xml的位置)。

当且仅当在GML文件的第一个字节中找到名称空间前缀和URI时(例如。 xmlns:ktjkiiwfs="http://xml.nls.fi/ktjkiiwfs/2010/02" ),并且在GML文件的第一个字节(例如。 ktjkiiwfs:Kiintestorajansijiaintitiedot公司 ). 如果定义了元素值,则仅当在GML文件的第一个字节中找到特征类型和值时才使用模式(例如。 vf:TypSouboru>OB_UKSH

建立连接表

The ogr_build_junction_table.py script can be used to build a junction table from OGR layers that contain "XXXX_href" fields. Let's considering the following output of a GML file with links to other features :

OGRFeature(myFeature):1
  gml_id (String) = myFeature.1
  [...]
  otherFeature_href (StringList) = (2:#otherFeature.10,#otherFeature.20)

OGRFeature(myFeature):2
  gml_id (String) = myFeature.2
  [...]
  otherFeature_href (StringList) = (2:#otherFeature.30,#otherFeature.10)

运行后

ogr2ogr -f PG PG:dbname=mydb my.gml

将其导入PostGIS和

python ogr_build_junction_table.py PG:dbname=mydb

,A myfeature_otherfeature 将创建表并包含以下内容:

myfeature_gml_id

otherfeature_gml_id

myFeature.1

otherFeature.10

myFeature.1

otherFeature.20

myFeature.2

otherFeature.30

myFeature.2

otherFeature.10

读取WFS 2.0联接查询产生的数据集

GML驱动程序可以读取wfs2.0连接查询产生的数据集。

这些数据集通常看起来像:

<wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:app="http://app.com"
    xmlns:wfs="http://www.opengis.net/wfs/2.0"
    xmlns:gml="http://www.opengis.net/gml/3.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    numberMatched="unknown" numberReturned="2" timeStamp="2015-01-01T00:00:00.000Z"
    xsi:schemaLocation="http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd
                        http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd">
  <wfs:member>
    <wfs:Tuple>
      <wfs:member>
        <app:table1 gml:id="table1-1">
          <app:foo>1</app:foo>
        </app:table1>
      </wfs:member>
      <wfs:member>
        <app:table2 gml:id="table2-1">
          <app:bar>2</app:bar>
          <app:baz>foo</app:baz>
          <app:geometry><gml:Point gml:id="table2-2.geom.0"><gml:pos>2 49</gml:pos></gml:Point></app:geometry>
        </app:table2>
      </wfs:member>
    </wfs:Tuple>
  </wfs:member>
  <wfs:member>
    <wfs:Tuple>
      <wfs:member>
        <app:table1 gml:id="table1-2">
          <app:bar>2</app:bar>
          <app:geometry><gml:Point gml:id="table1-1.geom.0"><gml:pos>3 50</gml:pos></gml:Point></app:geometry>
        </app:table1>
      </wfs:member>
      <wfs:member>
        <app:table2 gml:id="table2-2">
          <app:bar>2</app:bar>
          <app:baz>bar</app:baz>
          <app:geometry><gml:Point gml:id="table2-2.geom.0"><gml:pos>2 50</gml:pos></gml:Point></app:geometry>
        </app:table2>
      </wfs:member>
    </wfs:Tuple>
  </wfs:member>
</wfs:FeatureCollection>

OGR将把参与连接的层中的属性组合在一起,并在它们前面加上层名称。因此,上面的示例将被理解为以下内容:

OGRFeature(join_table1_table2):0
  table1.gml_id (String) = table1-1
  table1.foo (Integer) = 1
  table1.bar (Integer) = (null)
  table2.gml_id (String) = table2-1
  table2.bar (Integer) = 2
  table2.baz (String) = foo
  table2.geometry = POINT (2 49)

OGRFeature(join_table1_table2):1
  table1.gml_id (String) = table1-2
  table1.foo (Integer) = (null)
  table1.bar (Integer) = 2
  table2.gml_id (String) = table2-2
  table2.bar (Integer) = 2
  table2.baz (String) = bar
  table1.geometry = POINT (3 50)
  table2.geometry = POINT (2 50)

实例

ogr2ogr实用程序可用于将Oracle查询的结果转储到GML:

ogr2ogr -f GML output.gml OCI:usr/pwd@db my_feature -where "id = 0"

ogr2ogr实用程序可用于将PostGIS查询的结果转储到GML:

ogr2ogr -f GML output.gml PG:'host=myserver dbname=warmerda' -sql "SELECT pop_1994 from canada where province_name = 'Alberta'"

也见

信用

  • 实施 GML_SKIP_RESOLVE_ELEMS HUGE 由A.Furieri出资,资金来自Regione Toscana

  • 芬兰国家土地调查GML和Inspire GML中的地籍数据支持由农业和林业部信息中心(Tike)资助