1.. _vector.gml: 2 3GML - Geography Markup Language 4=============================== 5 6.. shortname:: GML 7 8.. build_dependencies:: (read support needs Xerces or libexpat) 9 10OGR has limited support for GML reading and writing. Update of existing 11files is not supported. 12 13Supported GML flavors : 14 15======================================= ================================= 16Read Write 17======================================= ================================= 18GML2 and GML3 that can GML 2.1.2 or GML 3 SF-0 19be translated into simple feature model (GML 3.1.1 Compliance level SF-0) 20======================================= ================================= 21 22Starting with GDAL 2.2, another driver, :ref:`GMLAS <vector.gmlas>`, for 23GML driven by application schemas, is also available. Both GML and GMLAS 24drivers have their use cases. 25 26Driver capabilities 27------------------- 28 29.. supports_create:: 30 31.. supports_georeferencing:: 32 33.. supports_virtualio:: 34 35Parsers 36------- 37 38The reading part of the driver only works if OGR is built with Xerces 39linked in. When Xerces is unavailable, read 40support also works if OGR is built with Expat linked in. XML validation 41is disabled by default. GML writing is always supported, even without 42Xerces or Expat. 43 44Note: if both Xerces and Expat are available at 45build time, the GML driver will preferentially select at runtime the 46Expat parser for cases where it is possible (GML file in a compatible 47encoding), and default back to Xerces parser in other cases. However, 48the choice of the parser can be overridden by specifying the 49**GML_PARSER** configuration option to **EXPAT** or **XERCES**. 50 51CRS support 52----------- 53 54The GML driver has coordinate system support. This is 55only reported when all the geometries of a layer have a srsName 56attribute, whose value is the same for all geometries. For srsName such 57as "urn:ogc:def:crs:EPSG:" (or "http://www.opengis.net/def/crs/EPSG/0/" 58starting with GDAL 2.1.2), for geographic coordinate systems (as 59returned by WFS 1.1.0 for example), the axis order should be (latitude, 60longitude) as required by the standards, but this is unusual and can 61cause issues with applications unaware of axis order. So by default, the 62driver will swap the coordinates so that they are in the (longitude, 63latitude) order and report a SRS without axis order specified. It is 64possible to get the original (latitude, longitude) order and SRS with 65axis order by setting the configuration option 66**GML_INVERT_AXIS_ORDER_IF_LAT_LONG** to **NO**. 67 68There also situations where the srsName is of the form "EPSG:XXXX" 69(whereas "urn:ogc:def:crs:EPSG::XXXX" would have been more explicit on 70the intent) and the coordinates in the file are in (latitude, longitude) 71order. By default, OGR will not consider the EPSG axis order and will 72report the coordinates in (latitude,longitude) order. However, if you 73set the configuration option **GML_CONSIDER_EPSG_AS_URN** to **YES**, 74the rules explained in the previous paragraph will be applied. 75 76The above also applied for projected coordinate systems 77whose EPSG preferred axis order is (northing, easting). 78 79Starting with GDAL 2.1.2, the SWAP_COORDINATES open option (or 80GML_SWAP_COORDINATES configuration option) can be set to AUTO/YES/NO. It 81controls whether the order of the x/y or long/lat coordinates should be 82swapped. In AUTO mode, the driver will determine if swapping must be 83done from the srsName and value of other options like 84CONSIDER_EPSG_AS_URN and INVERT_AXIS_ORDER_IF_LAT_LONG. When 85SWAP_COORDINATES is set to YES, coordinates will be always swapped 86regarding the order they appear in the GML, and when it set to NO, they 87will be kept in the same order. The default is AUTO. 88 89Schema 90------ 91 92In contrast to most GML readers, the OGR GML reader does not require the 93presence of an XML Schema definition of the feature classes (file with 94.xsd extension) to be able to read the GML file. If the .xsd file is 95absent or OGR is not able to parse it, the driver attempts to 96automatically discover the feature classes and their associated 97properties by scanning the file and looking for "known" gml objects in 98the gml namespace to determine the organization. While this approach is 99error prone, it has the advantage of working for GML files even if the 100associated schema (.xsd) file has been lost. 101 102It is possible to specify an explicit filename 103for the XSD schema to use, by using 104"a_filename.gml,xsd=another_filename.xsd" as a connection string. 105The XSD can also be specified as the value of the 106XSD open option. 107 108The first time a GML file is opened, if the associated .xsd is absent or 109could not been parsed correctly, it is completely scanned in order to 110determine the set of featuretypes, the attributes associated with each 111and other dataset level information. This information is stored in a 112.gfs file with the same basename as the target gml file. Subsequent 113accesses to the same GML file will use the .gfs file to predefine 114dataset level information accelerating access. To a limited extent the 115.gfs file can be manually edited to alter how the GML file will be 116parsed. Be warned that the .gfs file will be ignored if the associated 117.gml file has a newer timestamp. 118 119When prescanning the GML file to determine the list of feature types, 120and fields, the contents of fields are scanned to try and determine the 121type of the field. In some applications it is easier if all fields are 122just treated as string fields. This can be accomplished by setting the 123configuration option **GML_FIELDTYPES** to the value **ALWAYS_STRING**. 124 125The **GML_ATTRIBUTES_TO_OGR_FIELDS** 126configuration option can be set to **YES** so that attributes of GML 127elements are also taken into account to create OGR fields. 128 129Configuration options can be set via the CPLSetConfigOption() function 130or as environment variables. 131 132You can use **GML_GFS_TEMPLATE** configuration option (or **GFS_TEMPLATE** 133open option) set to a **path_to_template.gfs** in order 134to unconditionally use a predefined GFS file. This option is 135really useful when you are planning to import many distinct GML 136files in subsequent steps [**-append**] and you absolutely want to 137preserve a fully consistent data layout for the whole GML set. 138Please, pay attention not to use the **-lco LAUNDER=yes** setting 139when using **GML_GFS_TEMPLATE**; this should break the correct 140recognition of attribute names between subsequent GML import runs. 141 142Particular GML application schemas 143---------------------------------- 144 145Feature attributes in nested GML elements (non-flat attribute hierarchy) that 146can be found in some GML profiles, such as UK Ordnance Survey MasterMap, are 147detected. IntegerList, RealList and StringList field types 148when a GML element has several occurrences are also supported. 149 150A specialized GML driver - the :ref:`NAS <vector.nas>` 151driver - is available to read German AAA GML Exchange Format 152(NAS/ALKIS). 153 154The GML driver has partial support for reading AIXM or 155CityGML files. 156 157The GML driver supports reading : 158 159- `Finnish National Land Survey GML files (a.k.a MTK GML) for 160 topographic 161 data. <http://xml.nls.fi/XML/Schema/Maastotietojarjestelma/MTK/201202/Maastotiedot.xsd>`__ 162- `Finnish National Land Survey GML files for cadastral 163 data <http://xml.nls.fi/XML/Schema/sovellus/ktjkii/modules/kiinteistotietojen_kyselypalvelu_WFS/Asiakasdokumentaatio/ktjkiiwfs/2010/02/>`__. 164- `Cadastral data in Inspire GML 165 schemas <http://inspire.ec.europa.eu/schemas/cp/3.0/CadastralParcels.xsd>`__. 166- `Czech RUIAN Exchange Format 167 (VFR) <http://www.cuzk.cz/Uvod/Produkty-a-sluzby/RUIAN/2-Poskytovani-udaju-RUIAN-ISUI-VDP/Vymenny-format-RUIAN/Vymenny-format-RUIAN-%28VFR%29.aspx>`__. 168 169The GML driver supports reading responses to CSW GetRecords queries. 170 171Since OGR 2.2, the GML driver supports reading Japanese FGD GML v4 172files. 173 174Geometry reading 175---------------- 176 177When reading a feature, the driver will by default only take into 178account the last recognized GML geometry found (in case they are 179multiples) in the XML subtree describing the feature. 180 181But, if the .xsd schema is understood by the XSD 182parser and declares several geometry fields, or the .gfs file declares 183several geometry fields, multiple geometry fields will be reported by 184the GML driver according to :ref:`rfc-41`. 185 186In case of multiple geometry occurrences, if a 187geometry is in a <geometry> element, this will be the one selected. This 188will make default behavior consistent with Inspire objects. 189 190The user can change the .gfs file to select the 191appropriate geometry by specifying its path with the 192<GeometryElementPath> element. See the description of the .gfs syntax 193below. 194 195GML geometries including TopoCurve, TopoSurface, MultiCurve are also supported. 196The TopoCurve type GML geometry can be 197interpreted as either of two types of geometries. The Edge elements in 198it contain curves and their corresponding nodes. By default only the 199curves, the main geometries, are reported as OGRMultiLineString. To 200retrieve the nodes, as OGRMultiPoint, the configuration option 201**GML_GET_SECONDARY_GEOM** should be set to the value **YES**. When this 202is set only the secondary geometries are reported. 203 204Arc, ArcString, ArcByBulge, ArcByCenterPoint, 205Circle and CircleByCenterPoints will be returned as circular string OGR 206geometries. If they are included in other GML elements such as 207CurveComposite, MultiCurve, Surface, corresponding non-linear OGR 208geometries will be returned as well. When reading GML3 application 209schemas, declarations of geometry fields such as CurvePropertyType, 210SurfacePropertyType, MultiCurvePropertyType or MultiSurfacePropertyType 211will be also interpreted as being potential non-linear geometries, and 212corresponding OGR geometry type will be used for the layer geometry 213type. 214 215gml:xlink resolving 216------------------- 217 218gml:xlink resolving is supported. When the resolver finds 219an element containing the tag xlink:href, it tries to find the 220corresponding element with the gml:id in the same gml file, other gml 221file in the file system or on the web using cURL. Set the configuration 222option **GML_SKIP_RESOLVE_ELEMS** to **NONE** to enable resolution. 223 224By default the resolved file will be saved in the same directory as the 225original file with the extension ".resolved.gml", if it doesn't exist 226already. This behavior can be changed using the configuration option 227**GML_SAVE_RESOLVED_TO**. Set it to **SAME** to overwrite the original 228file. Set it to a **filename ending with .gml** to save it to that 229location. Any other values are ignored. If the resolver cannot write to 230the file for any reason, it will try to save it to a temporary file 231generated using CPLGenerateTempFilename("ResolvedGML"); if it cannot, 232resolution fails. 233 234Note that the resolution algorithm is not optimized for large files. For 235files with more than a couple of thousand xlink:href tags, the process 236can go beyond a few minutes. A rough progress is displayed through 237CPLDebug() for every 256 links. It can be seen by setting the 238environment variable CPL_DEBUG. The resolution time can be reduced if 239you know any elements that will not be needed. Mention a comma separated 240list of names of such elements with the configuration option 241**GML_SKIP_RESOLVE_ELEMS**. Set it to **ALL** to skip resolving 242altogether (default action). Set it to **NONE** to resolve all the 243xlinks. 244 245An alternative resolution method is available. 246This alternative method will be activated using the configuration option 247**GML_SKIP_RESOLVE_ELEMS HUGE**. In this case any gml:xlink will be 248resolved using a temporary SQLite DB so to identify any corresponding 249gml:id relation. At the end of this SQL-based process, a resolved file 250will be generated exactly as in the **NONE** case but without their 251limits. The main advantages in using an external (temporary) DBMS so to 252resolve gml:xlink and gml:id relations are the following: 253 254- no memory size constraints. The **NONE** method stores the whole GML 255 node-tree in-memory; and this practically means that no GML file 256 bigger than 1 GB can be processed at all using a 32-bit platform, due 257 to memory allocation limits. Using a file-system based DBMS avoids at 258 all this issue. 259- by far better efficiency, most notably when huge GML files containing 260 many thousands (or even millions) of xlink:href / gml:id relational 261 pairs. 262- using the **GML_SKIP_RESOLVE_ELEMS HUGE** method realistically allows 263 to successfully resolve some really huge GML file (3GB+) containing 264 many millions xlink:href / gml:id in a reasonable time (about an hour 265 or so on). 266- The **GML_SKIP_RESOLVE_ELEMS HUGE** method supports the following 267 further configuration option: 268 269TopoSurface interpretation rules [polygons and internal holes] 270-------------------------------------------------------------- 271 272The GML driver is able to recognize two 273different interpretation rules for TopoSurface when a polygon contains 274any internal hole: 275 276- the previously supported interpretation rule assumed that: 277 278 - each TopoSurface may be represented as a collection of many Faces 279 - *positive* Faces [i.e. declaring **orientation="+"**] are assumed 280 to represent the Exterior Ring of some Polygon. 281 - *negative* Faces [i.e. declaring **orientation="-"**] are assumed 282 to represent an Interior Ring (aka *hole*) belonging to the latest 283 declared Exterior Ring. 284 - ordering any Edge used to represent each Ring is important: each 285 Edge is expected to be exactly adjacent to the next one. 286 287- the new interpretation rule now assumes that: 288 289 - each TopoSurface may be represented as a collection of many Faces 290 - the declared **orientation** for any Face has nothing to deal with 291 Exterior/Interior Rings 292 - each Face is now intended to represent a complete Polygon, 293 eventually including any possible Interior Ring (*holes*) 294 - the relative ordering of any Edge composing the same Face is 295 completely not relevant 296 297The newest interpretation seems to fully match GML 3 standard 298recommendations; so this latest is now assumed to be the default 299interpretation supported by OGR. 300 301**NOTE** : Using the newest interpretation requires GDAL/OGR to be built 302against the GEOS library. 303 304Using the **GML_FACE_HOLE_NEGATIVE** configuration option you can anyway 305select the actual interpretation to be applied when parsing GML 3 306Topologies: 307 308- setting **GML_FACE_HOLE_NEGATIVE NO** (*default* option) will 309 activate the newest interpretation rule 310- but explicitly setting **GML_FACE_HOLE_NEGATIVE YES** still enables 311 to activate the old interpretation rule 312 313Encoding issues 314--------------- 315 316Expat library supports reading the following built-in encodings : 317 318- US-ASCII 319- UTF-8 320- UTF-16 321- ISO-8859-1 322- Windows-1252 323 324The content returned by OGR will be encoded in UTF-8, after the 325conversion from the encoding mentioned in the file header is. 326 327If the GML file is not encoded in one of the previous encodings and the 328only parser available is Expat, it will not be parsed by the GML driver. 329You may convert it into one of the supported encodings with the *iconv* 330utility for example and change accordingly the *encoding* parameter 331value in the XML header. 332 333When writing a GML file, the driver expects UTF-8 content to be passed 334in. 335 336Note: The .xsd schema files are parsed with an integrated XML parser 337which does not currently understand XML encodings specified in the XML 338header. It expects encoding to be always UTF-8. If attribute names in 339the schema file contains non-ascii characters, it is better to use 340*iconv* utility and convert the .xsd file into UTF-8 encoding first. 341 342Feature id (fid / gml:id) 343------------------------- 344 345The driver exposes the content of the gml:id 346attribute as a string field called *gml_id*, when reading GML WFS 347documents. When creating a GML3 document, if a field is called *gml_id*, 348its content will also be used to write the content of the gml:id 349attribute of the created feature. 350 351The driver autodetects the presence of a fid 352(GML2) (resp. gml:id (GML3)) attribute at the beginning of the file, 353and, if found, exposes it by default as a *fid* (resp. *gml_id*) field. 354The autodetection can be overridden by specifying the **GML_EXPOSE_FID** 355or **GML_EXPOSE_GML_ID** configuration option to **YES** or **NO**. 356 357When creating a GML2 document, if a field is 358called *fid*, its content will also be used to write the content of the 359fid attribute of the created feature. 360 361Performance issues with large multi-layer GML files. 362---------------------------------------------------- 363 364There is only one GML parser per GML datasource shared among the various 365layers. By default, the GML driver will restart reading from the 366beginning of the file, each time a layer is accessed for the first time, 367which can lead to poor performance with large GML files. 368 369The **GML_READ_MODE** configuration option can 370be set to **SEQUENTIAL_LAYERS** if all features belonging to the same 371layer are written sequentially in the file. The reader will then avoid 372unnecessary resets when layers are read completely one after the other. 373To get the best performance, the layers must be read in the order they 374appear in the file. 375 376If no .xsd and .gfs files are found, the parser will detect the layout 377of layers when building the .gfs file. If the layers are found to be 378sequential, a *<SequentialLayers>true</SequentialLayers>* element will 379be written in the .gfs file, so that the GML_READ_MODE will be 380automatically initialized to SEQUENTIAL_LAYERS if not explicitly set by 381the user. 382 383The GML_READ_MODE configuration option can be 384set to INTERLEAVED_LAYERS to be able to read a GML file whose features 385from different layers are interleaved. In the case, the semantics of the 386GetNextFeature() will be slightly altered, in a way where a NULL return 387does not necessarily mean that all features from the current layer have 388been read, but it could also mean that there is still a feature to read, 389but that belongs to another layer. In that case, the file should be read 390with code similar to the following one : 391 392:: 393 394 int nLayerCount = poDS->GetLayerCount(); 395 int bFoundFeature; 396 do 397 { 398 bFoundFeature = FALSE; 399 for( int iLayer = 0; iLayer < nLayerCount; iLayer++ ) 400 { 401 OGRLayer *poLayer = poDS->GetLayer(iLayer); 402 OGRFeature *poFeature; 403 while((poFeature = poLayer->GetNextFeature()) != NULL) 404 { 405 bFoundFeature = TRUE; 406 poFeature->DumpReadable(stdout, NULL); 407 OGRFeature::DestroyFeature(poFeature); 408 } 409 } 410 } while (bInterleaved && bFoundFeature); 411 412Open options 413------------ 414 415- **XSD=filename**: to specify an explicit filename for 416 the XSD application schema to use. 417- **WRITE_GFS=AUTO/YES/NO**: (GDAL >= 3.2) whether to write a .gfs file. 418 In AUTO mode, the .gfs file is only written if there is no recognized .xsd 419 file, no existing .gfs file and for non-network file systems. This option 420 can be set to YES for force .gfs file writing in situations where AUTO would 421 not attempt to do it. Or it can be set to NO to disable .gfs file writing. 422- **GFS_TEMPLATE=filename**: to unconditionally use a predefined GFS file. 423 This option is really useful when you are planning to import many distinct GML 424 files in subsequent steps [**-append**] and you absolutely want to 425 preserve a fully consistent data layout for the whole GML set. 426 Please, pay attention not to use the **-lco LAUNDER=yes** setting 427 when this option; this should break the correct 428 recognition of attribute names between subsequent GML import runs. 429- **FORCE_SRS_DETECTION=YES/NO**: Force a full scan to 430 detect the SRS of layers. This option may be needed in the case where 431 the .gml file is accompanied with a .xsd. Normally in that situation, 432 OGR would not detect the SRS, because this requires to do a full scan 433 of the file. Defaults to NO 434- **EMPTY_AS_NULL=YES/NO**: By default 435 (EMPTY_AS_NULL=YES), fields with empty content will be reported as 436 being NULL, instead of being an empty string. This is the historic 437 behavior. However this will prevent such fields to be declared as 438 not-nullable if the application schema declared them as mandatory. So 439 this option can be set to NO to have both empty strings being report 440 as such, and mandatory fields being reported as not nullable. 441- **GML_ATTRIBUTES_TO_OGR_FIELDS=YES/NO**: Whether GML 442 attributes should be reported as OGR fields. Note that this option 443 has only an effect the first time a GML file is opened (before the 444 .gfs file is created), and if it has no valid associated .xsd. 445 Defaults to NO. 446- **INVERT_AXIS_ORDER_IF_LAT_LONG=YES/NO**: Whether to 447 present SRS and coordinate ordering in traditional GIS order. 448 Defaults to YES. 449- **CONSIDER_EPSG_AS_URN=YES/NO/AUTO**: Whether to 450 consider srsName like EPSG:XXXX as respecting EPSG axis order. 451 Defaults to AUTO. 452- **SWAP_COORDINATES**\ =AUTO/YES/NO: (GDAL >= 2.1.2) Whether the order 453 of the x/y or long/lat coordinates should be swapped. In AUTO mode, 454 the driver will determine if swapping must be done from the srsName 455 and value of other options like CONSIDER_EPSG_AS_URN and 456 INVERT_AXIS_ORDER_IF_LAT_LONG. When SWAP_COORDINATES is set to YES, 457 coordinates will be always swapped regarding the order they appear in 458 the GML, and when it set to NO, they will be kept in the same order. 459 The default is AUTO. 460- **READ_MODE=AUTO/STANDARD/SEQUENTIAL_LAYERS/INTERLEAVED_LAYERS**: 461 Read mode. Defaults to AUTO. 462- **EXPOSE_GML_ID=YES/NO/AUTO**: Whether to make feature 463 gml:id as a gml_id attribute. Defaults to AUTO. 464- **EXPOSE_FID=YES/NO/AUTO**: Whether to make feature fid 465 as a fid attribute. Defaults to AUTO. 466- **DOWNLOAD_SCHEMA=YES/NO**: Whether to download the 467 remote application schema if needed (only for WFS currently). 468 Defaults to YES. 469- **REGISTRY=filename**: Filename of the registry with 470 application schemas. Defaults to {GDAL_DATA}/gml_registry.xml. 471 472Creation Issues 473--------------- 474 475On export all layers are written to a single GML file all in a single 476feature collection. Each layer's name is used as the element name for 477objects from that layer. Geometries are always written as the 478ogr:geometryProperty element on the feature. 479 480The GML writer supports the following dataset creation options: 481 482- **XSISCHEMAURI**: If provided, this URI will be inserted as the 483 schema location. Note that the schema file isn't actually accessed by 484 OGR, so it is up to the user to ensure it will match the schema of 485 the OGR produced GML data file. 486- **XSISCHEMA**: This can be EXTERNAL, INTERNAL or OFF and defaults to 487 EXTERNAL. This writes a GML application schema file to a 488 corresponding .xsd file (with the same basename). If INTERNAL is used 489 the schema is written within the GML file, but this is experimental 490 and almost certainly not valid XML. OFF disables schema generation 491 (and is implicit if XSISCHEMAURI is used). 492- **PREFIX** Defaults to 'ogr'. This is the prefix for 493 the application target namespace. 494- **STRIP_PREFIX** Defaults to FALSE. Can be set to TRUE 495 to avoid writing the prefix of the application target namespace in 496 the GML file. 497- **TARGET_NAMESPACE** Defaults to 498 'http://ogr.maptools.org/'. This is the application target namespace. 499- **FORMAT**: This can be set to : 500 501 - *GML3* in order to write GML files that follow GML 3.1.1 SF-0 502 profile. 503 - *GML3Deegree* in order to produce a GML 3.1.1 .XSD 504 schema, with a few variations with respect to what is recommended 505 by GML3 SF-0 profile, but that will be better accepted by some 506 software (such as Deegree 3). 507 - *GML3.2*\ in order to write GML files that follow 508 GML 3.2.1 SF-0 profile. 509 510 If not specified, GML2 will be used. 511 Non-linear geometries can be written. This is 512 only compatible with selecting on of that above GML3 format variant. 513 Otherwise, such geometries will be approximating into their closest 514 matching linear geometry. 515 Note: fields of type StringList, RealList or 516 IntegerList can be written. This will cause to advertise the SF-1 517 profile in the .XSD schema (such types are not supported by SF-0). 518- **GML_FEATURE_COLLECTION**\ =YES/NO (OGR >= 2.3) Whether to use the 519 gml:FeatureCollection, instead of creating a dedicated container 520 element in the target namespace. Only valid for FORMAT=GML3/GML3.2. 521 Note that gml:FeatureCollection has been deprecated in GML 3.2, and 522 is not allowed by the OGC 06-049r1 "Geography Markup Language (GML) 523 simple features profile" (for GML 3.1.1) and OGC 10-100r3 "Geography 524 Markup Language (GML) simple features profile (with Corrigendum)" 525 (for GML 3.2) specifications. 526- **GML3_LONGSRS**\ =YES/NO. (only valid when 527 FORMAT=GML3/GML3Degree/GML3.2) Deprecated by SRSNAME_FORMAT in GDAL 528 2.2. Default to YES. If YES, SRS with EPSG authority will be written 529 with the "urn:ogc:def:crs:EPSG::" prefix. In the case the SRS is a 530 SRS without explicit AXIS order, but that the same SRS authority code 531 imported with ImportFromEPSGA() should be treated as lat/long or 532 northing/easting, then the function will take care of coordinate 533 order swapping. If set to NO, SRS with EPSG authority will be written 534 with the "EPSG:" prefix, even if they are in lat/long order. 535- **SRSNAME_FORMAT**\ =SHORT/OGC_URN/OGC_URL (Only valid for 536 FORMAT=GML3/GML3Degree/GML3.2, GDAL >= 2.2). Defaults to OGC_URN. If 537 SHORT, then srsName will be in the form AUTHORITY_NAME:AUTHORITY_CODE 538 If OGC_URN, then srsName will be in the form 539 urn:ogc:def:crs:AUTHORITY_NAME::AUTHORITY_CODE If OGC_URL, then 540 srsName will be in the form 541 http://www.opengis.net/def/crs/AUTHORITY_NAME/0/AUTHORITY_CODE For 542 OGC_URN and OGC_URL, in the case the SRS is a SRS without explicit 543 AXIS order, but that the same SRS authority code imported with 544 ImportFromEPSGA() should be treated as lat/long or northing/easting, 545 then the function will take care of coordinate order swapping. 546- **SRSDIMENSION_LOC**\ =POSLIST/GEOMETRY/GEOMETRY,POSLIST. (Only valid 547 for FORMAT=GML3/GML3Degree/GML3.2) Default to POSLIST. 548 For 2.5D geometries, define the location where to attach the 549 srsDimension attribute. There are diverging implementations. Some put 550 in on the <gml:posList> element, other on the top geometry element. 551- **WRITE_FEATURE_BOUNDED_BY**\ =YES/NO. (only valid when 552 FORMAT=GML3/GML3Degree/GML3.2) Default to YES. If set to NO, the 553 <gml:boundedBy> element will not be written for each feature. 554- **SPACE_INDENTATION**\ =YES/NO. Default to YES. If 555 YES, the output will be indented with spaces for more readability, 556 but at the expense of file size. 557- **GML_ID**\ =string. (Only valid for GML 3.2) Value of 558 feature collection gml:id. Default value is "aFeatureCollection". 559- **NAME**\ =string. Content of GML name element. Can also be set as 560 the NAME metadata item on the dataset. 561- **DESCRIPTION**\ =string. Content of GML description element. Can 562 also be set as the DESCRIPTION metadata item on the dataset. 563 564VSI Virtual File System API support 565----------------------------------- 566 567The driver supports reading and writing to files managed by VSI Virtual 568File System API, which include "regular" files, as well as files in the 569/vsizip/ (read-write) , /vsigzip/ (read-write) , /vsicurl/ (read-only) 570domains. 571 572Writing to /dev/stdout or /vsistdout/ is also supported. Note that in 573that case, only the content of the GML file will be written to the 574standard output (and not the .xsd). The <boundedBy> element will not be 575written. This is also the case if writing in /vsigzip/ 576 577Syntax of .gfs file by example 578------------------------------ 579 580Let's consider the following test.gml file : 581 582.. code-block:: XML 583 584 <?xml version="1.0" encoding="UTF-8"?> 585 <gml:FeatureCollection xmlns:gml="http://www.opengis.net/gml"> 586 <gml:featureMember> 587 <LAYER> 588 <attrib1>attrib1_value</attrib1> 589 <attrib2container> 590 <attrib2>attrib2_value</attrib2> 591 </attrib2container> 592 <location1container> 593 <location1> 594 <gml:Point><gml:coordinates>3,50</gml:coordinates></gml:Point> 595 </location1> 596 </location1container> 597 <location2> 598 <gml:Point><gml:coordinates>2,49</gml:coordinates></gml:Point> 599 </location2> 600 </LAYER> 601 </gml:featureMember> 602 </gml:FeatureCollection> 603 604and the following associated .gfs file. 605 606.. code-block:: XML 607 608 <GMLFeatureClassList> 609 <GMLFeatureClass> 610 <Name>LAYER</Name> 611 <ElementPath>LAYER</ElementPath> 612 <GeometryElementPath>location1container|location1</GeometryElementPath> 613 <PropertyDefn> 614 <Name>attrib1</Name> 615 <ElementPath>attrib1</ElementPath> 616 <Type>String</Type> 617 <Width>13</Width> 618 </PropertyDefn> 619 <PropertyDefn> 620 <Name>attrib2</Name> 621 <ElementPath>attrib2container|attrib2</ElementPath> 622 <Type>String</Type> 623 <Width>13</Width> 624 </PropertyDefn> 625 </GMLFeatureClass> 626 </GMLFeatureClassList> 627 628Note the presence of the '|' character in the <ElementPath> and 629<GeometryElementPath> elements to specify the wished field/geometry 630element that is a nested XML element. Nested field elements are supported, 631as well as specifying <GeometryElementPath> If 632GeometryElementPath is not specified, the GML driver will use the last 633recognized geometry element. 634 635The <GeometryType> element can be specified to force the geometry type. 636Accepted values are : 0 (any geometry type), 1 (point), 2 (linestring), 6373 (polygon), 4 (multipoint), 5 (multilinestring), 6 (multipolygon), 7 638(geometrycollection). 639 640The <GeometryElementPath> and <GeometryType> can 641be specified as many times as there are geometry fields in the GML file. 642Another possibility is to define a <GeomPropertyDefn>element as many 643times as necessary: 644 645.. code-block:: XML 646 647 <GMLFeatureClassList> 648 <GMLFeatureClass> 649 <Name>LAYER</Name> 650 <ElementPath>LAYER</ElementPath> 651 <GeomPropertyDefn> 652 <Name>geometry</Name> <!-- OGR geometry name --> 653 <ElementPath>geometry</ElementPath> <!-- XML element name possibly with '|' to specify the path --> 654 <Type>MultiPolygon</Type> 655 </GeomPropertyDefn> 656 <GeomPropertyDefn> 657 <Name>referencePoint</Name> 658 <ElementPath>referencePoint</ElementPath> 659 <Type>Point</Type> 660 </GeomPropertyDefn> 661 </GMLFeatureClass> 662 </GMLFeatureClassList> 663 664The output of *ogrinfo test.gml -ro -al* is: 665 666:: 667 668 Layer name: LAYER 669 Geometry: Unknown (any) 670 Feature Count: 1 671 Extent: (3.000000, 50.000000) - (3.000000, 50.000000) 672 Layer SRS WKT: 673 (unknown) 674 Geometry Column = location1container|location1 675 attrib1: String (13.0) 676 attrib2: String (13.0) 677 OGRFeature(LAYER):0 678 attrib1 (String) = attrib1_value 679 attrib2 (String) = attrib2_value 680 POINT (3 50) 681 682Advanced .gfs syntax 683-------------------- 684 685Specifying ElementPath to find objects embedded into top level objects 686~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 687 688Let's consider the following test.gml file : 689 690.. code-block:: XML 691 692 <?xml version="1.0" encoding="utf-8"?> 693 <gml:FeatureCollection xmlns:xlink="http://www.w3.org/1999/xlink" 694 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 695 gml:id="foo" xmlns:gml="http://www.opengis.net/gml/3.2"> 696 <gml:featureMember> 697 <TopLevelObject gml:id="TopLevelObject.1"> 698 <content> 699 <Object gml:id="Object.1"> 700 <geometry> 701 <gml:Polygon gml:id="Object.1.Geometry" srsName="urn:ogc:def:crs:EPSG::4326"> 702 <gml:exterior> 703 <gml:LinearRing> 704 <gml:posList srsDimension="2">48 2 49 2 49 3 48 3 48 2</gml:posList> 705 </gml:LinearRing> 706 </gml:exterior> 707 </gml:Polygon> 708 </geometry> 709 <foo>bar</foo> 710 </Object> 711 </content> 712 <content> 713 <Object gml:id="Object.2"> 714 <geometry> 715 <gml:Polygon gml:id="Object.2.Geometry" srsName="urn:ogc:def:crs:EPSG::4326"> 716 <gml:exterior> 717 <gml:LinearRing> 718 <gml:posList srsDimension="2">-48 2 -49 2 -49 3 -48 3 -48 2</gml:posList> 719 </gml:LinearRing> 720 </gml:exterior> 721 </gml:Polygon> 722 </geometry> 723 <foo>baz</foo> 724 </Object> 725 </content> 726 </TopLevelObject> 727 </gml:featureMember> 728 </gml:FeatureCollection> 729 730By default, only the TopLevelObject object would be reported and it 731would only use the second geometry. This is not the desired behavior in 732that instance. You can edit the generated .gfs and modify it like the 733following in order to specify a full path to the element (top level XML 734element being omitted) : 735 736.. code-block:: XML 737 738 <GMLFeatureClassList> 739 <GMLFeatureClass> 740 <Name>Object</Name> 741 <ElementPath>featureMember|TopLevelObject|content|Object</ElementPath> 742 <GeometryType>3</GeometryType> 743 <PropertyDefn> 744 <Name>foo</Name> 745 <ElementPath>foo</ElementPath> 746 <Type>String</Type> 747 </PropertyDefn> 748 </GMLFeatureClass> 749 </GMLFeatureClassList> 750 751Getting XML attributes as OGR fields 752~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 753 754The element@attribute syntax can be used in the <ElementPath> to specify 755that the value of attribute 'attribute' of element 'element' must be 756fetched. 757 758Let's consider the following test.gml file : 759 760.. code-block:: XML 761 762 <?xml version="1.0" encoding="UTF-8"?> 763 <gml:FeatureCollection xmlns:gml="http://www.opengis.net/gml"> 764 <gml:featureMember> 765 <LAYER> 766 <length unit="m">5</length> 767 </LAYER> 768 </gml:featureMember> 769 </gml:FeatureCollection> 770 771and the following associated .gfs file. 772 773.. code-block:: XML 774 775 <GMLFeatureClassList> 776 <GMLFeatureClass> 777 <Name>LAYER</Name> 778 <ElementPath>LAYER</ElementPath> 779 <GeometryType>100</GeometryType> <!-- no geometry --> 780 <PropertyDefn> 781 <Name>length</Name> 782 <ElementPath>length</ElementPath> 783 <Type>Real</Type> 784 </PropertyDefn> 785 <PropertyDefn> 786 <Name>length_unit</Name> 787 <ElementPath>length@unit</ElementPath> 788 <Type>String</Type> 789 </PropertyDefn> 790 </GMLFeatureClass> 791 </GMLFeatureClassList> 792 793The output of *ogrinfo test.gml -ro -al* is: 794 795:: 796 797 Layer name: LAYER 798 Geometry: None 799 Feature Count: 1 800 Layer SRS WKT: 801 (unknown) 802 gml_id: String (0.0) 803 length: Real (0.0) 804 length_unit: String (0.0) 805 OGRFeature(LAYER):0 806 gml_id (String) = (null) 807 length (Real) = 5 808 length_unit (String) = m 809 810Using conditions on XML attributes 811~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 812 813A <Condition> element can be specified as a child element of a 814<PropertyDefn>. The content of the Condition follows a minimalistic 815XPath syntax. It must be of the form @attrname[=|!=]'attrvalue' [and|or 816other_cond]*. Note that 'and' and 'or' operators cannot be mixed (their 817precedence is not taken into account). 818 819Several <PropertyDefn> can be defined with the same <ElementPath>, but 820with <Condition> that must be mutually exclusive. 821 822Let's consider the following testcondition.gml file : 823 824.. code-block:: XML 825 826 <?xml version="1.0" encoding="utf-8" ?> 827 <ogr:FeatureCollection 828 xmlns:ogr="http://ogr.maptools.org/" 829 xmlns:gml="http://www.opengis.net/gml"> 830 <gml:featureMember> 831 <ogr:testcondition fid="testcondition.0"> 832 <ogr:name lang="en">English name</ogr:name> 833 <ogr:name lang="fr">Nom francais</ogr:name> 834 <ogr:name lang="de">Deutsche name</ogr:name> 835 </ogr:testcondition> 836 </gml:featureMember> 837 </ogr:FeatureCollection> 838 839and the following associated .gfs file. 840 841.. code-block:: XML 842 843 <GMLFeatureClassList> 844 <GMLFeatureClass> 845 <Name>testcondition</Name> 846 <ElementPath>testcondition</ElementPath> 847 <GeometryType>100</GeometryType> 848 <PropertyDefn> 849 <Name>name_en</Name> 850 <ElementPath>name</ElementPath> 851 <Condition>@lang='en'</Condition> 852 <Type>String</Type> 853 </PropertyDefn> 854 <PropertyDefn> 855 <Name>name_fr</Name> 856 <ElementPath>name</ElementPath> 857 <Condition>@lang='fr'</Condition> 858 <Type>String</Type> 859 </PropertyDefn> 860 <PropertyDefn> 861 <Name>name_others_lang</Name> 862 <ElementPath>name@lang</ElementPath> 863 <Condition>@lang!='en' and @lang!='fr'</Condition> 864 <Type>StringList</Type> 865 </PropertyDefn> 866 <PropertyDefn> 867 <Name>name_others</Name> 868 <ElementPath>name</ElementPath> 869 <Condition>@lang!='en' and @lang!='fr'</Condition> 870 <Type>StringList</Type> 871 </PropertyDefn> 872 </GMLFeatureClass> 873 </GMLFeatureClassList> 874 875The output of *ogrinfo testcondition.gml -ro -al* is: 876 877:: 878 879 Layer name: testcondition 880 Geometry: None 881 Feature Count: 1 882 Layer SRS WKT: 883 (unknown) 884 fid: String (0.0) 885 name_en: String (0.0) 886 name_fr: String (0.0) 887 name_others_lang: StringList (0.0) 888 name_others: StringList (0.0) 889 OGRFeature(testcondition):0 890 fid (String) = testcondition.0 891 name_en (String) = English name 892 name_fr (String) = Nom francais 893 name_others_lang (StringList) = (1:de) 894 name_others (StringList) = (1:Deutsche name) 895 896Registry for GML application schemas 897------------------------------------ 898 899The "data" directory of the GDAL installation contains a 900"gml_registry.xml" file that links feature types of GML application 901schemas to .xsd or .gfs files that contain their definition. This is 902used in case no valid .gfs or .xsd file is found next to the GML file. 903 904An alternate location for the registry file can be defined by setting 905its full pathname to the GML_REGISTRY configuration option. 906 907An example of such a file is : 908 909.. code-block:: XML 910 911 <gml_registry> 912 <!-- Finnish National Land Survey cadastral data --> 913 <namespace prefix="ktjkiiwfs" uri="http://xml.nls.fi/ktjkiiwfs/2010/02" useGlobalSRSName="true"> 914 <featureType elementName="KiinteistorajanSijaintitiedot" 915 schemaLocation="http://xml.nls.fi/XML/Schema/sovellus/ktjkii/modules/kiinteistotietojen_kyselypalvelu_WFS/Asiakasdokumentaatio/ktjkiiwfs/2010/02/KiinteistorajanSijaintitiedot.xsd"/> 916 <featureType elementName="PalstanTunnuspisteenSijaintitiedot" 917 schemaLocation="http://xml.nls.fi/XML/Schema/sovellus/ktjkii/modules/kiinteistotietojen_kyselypalvelu_WFS/Asiakasdokumentaatio/ktjkiiwfs/2010/02/palstanTunnuspisteenSijaintitiedot.xsd"/> 918 <featureType elementName="RekisteriyksikonTietoja" 919 schemaLocation="http://xml.nls.fi/XML/Schema/sovellus/ktjkii/modules/kiinteistotietojen_kyselypalvelu_WFS/Asiakasdokumentaatio/ktjkiiwfs/2010/02/RekisteriyksikonTietoja.xsd"/> 920 <featureType elementName="PalstanTietoja" 921 schemaLocation="http://xml.nls.fi/XML/Schema/sovellus/ktjkii/modules/kiinteistotietojen_kyselypalvelu_WFS/Asiakasdokumentaatio/ktjkiiwfs/2010/02/PalstanTietoja.xsd"/> 922 </namespace> 923 924 <!-- Inspire CadastralParcels schema --> 925 <namespace prefix="cp" uri="urn:x-inspire:specification:gmlas:CadastralParcels:3.0" useGlobalSRSName="true"> 926 <featureType elementName="BasicPropertyUnit" 927 gfsSchemaLocation="inspire_cp_BasicPropertyUnit.gfs"/> 928 <featureType elementName="CadastralBoundary" 929 gfsSchemaLocation="inspire_cp_CadastralBoundary.gfs"/> 930 <featureType elementName="CadastralParcel" 931 gfsSchemaLocation="inspire_cp_CadastralParcel.gfs"/> 932 <featureType elementName="CadastralZoning" 933 gfsSchemaLocation="inspire_cp_CadastralZoning.gfs"/> 934 </namespace> 935 936 <!-- Czech RUIAN (VFR) schema (v1) --> 937 <namespace prefix="vf" 938 uri="urn:cz:isvs:ruian:schemas:VymennyFormatTypy:v1 ../ruian/xsd/vymenny_format/VymennyFormatTypy.xsd" 939 useGlobalSRSName="true"> 940 <featureType elementName="TypSouboru" 941 elementValue="OB" 942 gfsSchemaLocation="ruian_vf_ob_v1.gfs"/> 943 <featureType elementName="TypSouboru" 944 elementValue="ST" 945 gfsSchemaLocation="ruian_vf_st_v1.gfs"/> 946 </namespace> 947 </gml_registry> 948 949XML schema definition (.xsd) files are pointed by the schemaLocation 950attribute, whereas OGR .gfs files are pointed by the gfsSchemaLocation 951attribute. In both cases, the filename can be a URL (http://, https://), 952an absolute filename, or a relative filename (relative to the location 953of gml_registry.xml). 954 955The schema is used if and only if the namespace prefix and URI are found 956in the first bytes of the GML file (e.g. 957*xmlns:ktjkiiwfs="http://xml.nls.fi/ktjkiiwfs/2010/02"*), and that the 958feature type is also detected in the first bytes of the GML file (e.g. 959*ktjkiiwfs:KiinteistorajanSijaintitiedot*). If the element value is 960defined than the schema is used only if the feature type together with 961the value is found in the first bytes of the GML file (e.g. 962*vf:TypSouboru>OB_UKSH*). 963 964Building junction tables 965------------------------ 966 967The 968`ogr_build_junction_table.py <https://github.com/OSGeo/gdal/blob/master/gdal/swig/python/gdal-utils/osgeo_utils/samples/ogr_build_junction_table.py>`__ 969script can be used to build a `junction 970table <http://en.wikipedia.org/wiki/Junction_table>`__ from OGR layers 971that contain "XXXX_href" fields. Let's considering the following output 972of a GML file with links to other features : 973 974:: 975 976 OGRFeature(myFeature):1 977 gml_id (String) = myFeature.1 978 [...] 979 otherFeature_href (StringList) = (2:#otherFeature.10,#otherFeature.20) 980 981 OGRFeature(myFeature):2 982 gml_id (String) = myFeature.2 983 [...] 984 otherFeature_href (StringList) = (2:#otherFeature.30,#otherFeature.10) 985 986After running 987 988:: 989 990 ogr2ogr -f PG PG:dbname=mydb my.gml 991 992to import it into PostGIS and 993 994:: 995 996 python ogr_build_junction_table.py PG:dbname=mydb 997 998, a *myfeature_otherfeature* table will be created and will contain the 999following content : 1000 1001================ =================== 1002myfeature_gml_id otherfeature_gml_id 1003================ =================== 1004myFeature.1 otherFeature.10 1005myFeature.1 otherFeature.20 1006myFeature.2 otherFeature.30 1007myFeature.2 otherFeature.10 1008================ =================== 1009 1010Reading datasets resulting from a WFS 2.0 join queries 1011------------------------------------------------------ 1012 1013The GML driver can read datasets resulting from a WFS 2.0 join queries. 1014 1015Such datasets typically look like: 1016 1017.. code-block:: XML 1018 1019 1020 <wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema" 1021 xmlns:app="http://app.com" 1022 xmlns:wfs="http://www.opengis.net/wfs/2.0" 1023 xmlns:gml="http://www.opengis.net/gml/3.2" 1024 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1025 numberMatched="unknown" numberReturned="2" timeStamp="2015-01-01T00:00:00.000Z" 1026 xsi:schemaLocation="http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd 1027 http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd"> 1028 <wfs:member> 1029 <wfs:Tuple> 1030 <wfs:member> 1031 <app:table1 gml:id="table1-1"> 1032 <app:foo>1</app:foo> 1033 </app:table1> 1034 </wfs:member> 1035 <wfs:member> 1036 <app:table2 gml:id="table2-1"> 1037 <app:bar>2</app:bar> 1038 <app:baz>foo</app:baz> 1039 <app:geometry><gml:Point gml:id="table2-2.geom.0"><gml:pos>2 49</gml:pos></gml:Point></app:geometry> 1040 </app:table2> 1041 </wfs:member> 1042 </wfs:Tuple> 1043 </wfs:member> 1044 <wfs:member> 1045 <wfs:Tuple> 1046 <wfs:member> 1047 <app:table1 gml:id="table1-2"> 1048 <app:bar>2</app:bar> 1049 <app:geometry><gml:Point gml:id="table1-1.geom.0"><gml:pos>3 50</gml:pos></gml:Point></app:geometry> 1050 </app:table1> 1051 </wfs:member> 1052 <wfs:member> 1053 <app:table2 gml:id="table2-2"> 1054 <app:bar>2</app:bar> 1055 <app:baz>bar</app:baz> 1056 <app:geometry><gml:Point gml:id="table2-2.geom.0"><gml:pos>2 50</gml:pos></gml:Point></app:geometry> 1057 </app:table2> 1058 </wfs:member> 1059 </wfs:Tuple> 1060 </wfs:member> 1061 </wfs:FeatureCollection> 1062 1063OGR will group together the attributes from the layers participating to 1064the join and will prefix them with the layer name. So the above example 1065will be read as the following: 1066 1067:: 1068 1069 OGRFeature(join_table1_table2):0 1070 table1.gml_id (String) = table1-1 1071 table1.foo (Integer) = 1 1072 table1.bar (Integer) = (null) 1073 table2.gml_id (String) = table2-1 1074 table2.bar (Integer) = 2 1075 table2.baz (String) = foo 1076 table2.geometry = POINT (2 49) 1077 1078 OGRFeature(join_table1_table2):1 1079 table1.gml_id (String) = table1-2 1080 table1.foo (Integer) = (null) 1081 table1.bar (Integer) = 2 1082 table2.gml_id (String) = table2-2 1083 table2.bar (Integer) = 2 1084 table2.baz (String) = bar 1085 table1.geometry = POINT (3 50) 1086 table2.geometry = POINT (2 50) 1087 1088Examples 1089-------- 1090 1091The ogr2ogr utility can be used to dump the results of a Oracle query to 1092GML: 1093 1094:: 1095 1096 ogr2ogr -f GML output.gml OCI:usr/pwd@db my_feature -where "id = 0" 1097 1098The ogr2ogr utility can be used to dump the results of a PostGIS query 1099to GML: 1100 1101:: 1102 1103 ogr2ogr -f GML output.gml PG:'host=myserver dbname=warmerda' -sql "SELECT pop_1994 from canada where province_name = 'Alberta'" 1104 1105See Also 1106-------- 1107 1108- `GML Specifications <http://www.opengeospatial.org/standards/gml>`__ 1109- `GML 3.1.1 simple features profile - OGC(R) 1110 06-049r1 <http://portal.opengeospatial.org/files/?artifact_id=15201>`__ 1111- `Geography Markup Language (GML) simple features profile (with 1112 Corrigendum) (GML 3.2.1) - OGC(R) 1113 10-100r3 <https://portal.opengeospatial.org/files/?artifact_id=42729>`__ 1114- `Xerces <http://xml.apache.org/xerces2-j/index.html>`__ 1115- :ref:`GMLAS - Geography Markup Language (GML) driven by application 1116 schemas <vector.gmlas>` 1117- :ref:`NAS/ALKIS : specialized GML driver for cadastral data in 1118 Germany <vector.nas>` 1119 1120Credits 1121------- 1122 1123- Implementation for **GML_SKIP_RESOLVE_ELEMS HUGE** was contributed by 1124 A.Furieri, with funding from Regione Toscana 1125- Support for cadastral data in Finnish National Land Survey GML and 1126 Inspire GML was funded by The Information Centre of the Ministry of 1127 Agriculture and Forestry (Tike) 1128