# GML - Geography Markup Language

OGR has limited support for GML reading and writing. Update of existing files is not currently supported. OGR is based on GML 2.0. The reading only works if OGR is built with Xerces linked in. XML validation is disabled by default. GML writing is always supported, even without Xerces.

The GML driver has no coordinate system support at this time.

In contrast to most GML readers, the OGR GML reader makes no effort to read the format XML Schema definition of the feature classes in a GML file. Instead it attempts to automatically discover them and their associated properties by scanning the file and looking for "known" gml objects in the gml namespace to determine the organization. While this approach is error prone, it has the advantage of working for GML files even if the associated schema (.xsd) file has been lost.

The first time a GML file is opened it is completely scanned in order to determine the set of featuretypes, the attributes associated with each and other dataset level information. This information is stored in a .gfs file with the same basename as the target gml file. Subsequent accesses to the same GML file will use the .gfs file to predefine dataset level information accelerating access. To a limited extent the .gfs file can be manually edited to alter how the GML file will be parsed. Be warned that the .gfs file will be automatically regenerated if the associated .gml file has a newer timestamp.

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. Configuration options can be set via the CPLSetConfigOption() function or as environment variables.

## Creation Issues

On export all layers are written to a single GML file all in a single feature collection. Each layer's name is used as the element name for objects from that layer. Geometries are always written as the ogr:geometryProperty property on the feature.

The GML writer supports the following creation options:

- XSISCHEMAURI: If provided, this URI will be inserted as the schema location. Note that the schema file isn't actually accessed by OGR, so it is up to the user to ensure it will match the schema of the OGR produced GML data file.

- XSISCHEMA: This can be EXTERNAL, INTERNAL or OFF and defaults to EXTERNAL. This (attempts) to write a BXML compatible GML schema file to a corresponding .xsd file (with the same basename). The generated schema is still experimental. If INTERNAL is used the schema is written within the GML file, but this is even more experimental and almost certainly not valid XML. OFF disables schema generation (and is implicit if XSISCHEMAURI is used).

## Example

The ogr2ogr utility can be used to dump the results of a Oracle query to GML:

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

The ogr2ogr utility can be used to dump the results of a PostGIS query to GML:

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

## See Also

- GML Specifications

- Xerces