Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible workflow for viewing GML files with QGIS #3

Open
heidivanparys opened this issue Dec 20, 2018 · 10 comments
Open

Possible workflow for viewing GML files with QGIS #3

heidivanparys opened this issue Dec 20, 2018 · 10 comments

Comments

@heidivanparys
Copy link

heidivanparys commented Dec 20, 2018

Prerequisites

QGIS is installed (includes OSGeo4W).

Workflow

  1. Open the OSGeo4W Shell application.
  2. Go to the folder where the GML file is located by using the cd command: cd C:\path\to\folder
  3. Run the ogrinfo command: ogrinfo -al -oo GML_ATTRIBUTES_TO_OGR_FIELDS=YES gml_file_name.gml
  4. A file gml_file_name.gfs is created. Edit it if desired.
  5. Add the GML file to QGIS via the Add Vector Layer menu option.

Notes

.gfs files

Example:

<PropertyDefn>
	<!-- display name in QGIS -->
      <Name>endDesignationPeriod_indeterminate</Name>
	<!-- use | to access the value of a nested XML element -->
	<!-- use @ to access the value of an attribute -->
      <ElementPath>designationPeriod|TimePeriod|endPosition@indeterminatePosition</ElementPath>
	<!-- a Condition element may be added here, see documentation. -->
      <Type>String</Type>
      <Width>10</Width>
 </PropertyDefn>

Note: When editing the GML file again, the corresponding .gfs file must be resaved so it has a later timestamp than the GML file, else it will not be taken into account.

It is possible to specify the location of the .gfs file to use via a registry for GML application schemas, but you need administrator rights on your computer to edit gml_registry.xml (it is possible to point to a custom registry file, but QGIS does not support yet setting options for OGR, see below).

<gml_registry>
    <namespace prefix="am" uri="http://inspire.ec.europa.eu/schemas/am/4.0" useGlobalSRSName="true">
        <featureType elementName="ManagementRestrictionOrRegulationZone"
                 gfsSchemaLocation="am_config.gfs"/>
    </namespace>
</gml_registry>

ogrinfo

The ogrinfo command is documented on https://www.gdal.org/ogrinfo.html
ogrinfo will recognize the file as a GML file and will therefore use the GML driver to open it, documented on https://www.gdal.org/drv_gml.html
A "configuration option", see also https://trac.osgeo.org/gdal/wiki/ConfigOptions, can be set by using the following syntax (thus without equal sign):
ogrinfo --config CONFIG_OPTION_NAME CONFIG_OPTION_VALUE

A "open option", also called "dataset open option", which is format specific, is set by using the following syntax (thus with equal sign):
ogrinfo --oo OPEN_OPTION_NAME=OPEN_OPTION_VALUE

Certain functionalities in OGR are available both as a configuration option and as an open option, sometimes with a different name for the option, so double-check the documentation.

QGIS does not yet support setting these options via the UI (see https://issues.qgis.org/issues/20825), therefore ogrinfo must be run with the OSGeo4W Shell application, and the layer added with QGIS afterwards.

When open option GML_ATTRIBUTES_TO_OGR_FIELDS is set YES, attributes of GML elements are also taken into account (e.g. xlink:href). Note that this currently does not work for the nilReason attribute: OSGeo/gdal#1154

@heidivanparys
Copy link
Author

I added this issue because I only recently became aware of the possibility of this way of viewing GML files (as opposed to seeing only few attributes, or having to use the GML application schema toolbox plugin).

Ideas for tests for GML:

@PeterParslow
Copy link

These are three of the ideas that we (OS) came up with (in 2015) as 'things we would like to see' in desktop GIS clients viewing GML, after the OGC UK Interoperability Plugfest. See https://www.ordnancesurvey.co.uk/about/governance/policies/gml-design.html and https://portal.opengeospatial.org/files/?artifact_id=61057

@sMorrone
Copy link
Collaborator

sMorrone commented Jan 3, 2019

In QGIS 2.18 it is possible to view whether a property is nil and to display the nilReason attribute using the Complex GML Info plugin (not working for QGIS version 3) screenshot 2019-01-03 13 31 49

@alexanderkotsev
Copy link
Contributor

We opened an issue in the QGIS issue tracker proposing a feature for including the GML_ATTRIBUTES_TO_OGR_FIELDS=YES as default behaviour for GML loading.

@sgrellet
Copy link

sgrellet commented Jun 4, 2019

I don't see the other ogr/gdal driver for GML ('https://gdal.org/drivers/vector/gmlas.html#vector-gmlas') mentionned. That's surprising as there was an important EU investment (EEA, BRGM, others) both on the driver and the capacity for QGIS plugins to use it (see https://plugins.qgis.org/plugins/gml_application_schema_toolbox/).
Have you considered it ?

@alexanderkotsev
Copy link
Contributor

The QGIS plugin + associated OGR/GDAL driver are considered. Please take a look at the results from the tests with data discovered through the INSPIRE Geoportal. You would notice that for many of the tests in the case of QGIS 3.x the functionality is considered as supported because of the QGIS plugin + ogr/gdal driver.
Question is now how to ensure sustainability + continuity.

@sgrellet
Copy link

sgrellet commented Jun 4, 2019

My bad. Indeed it's written 'Notes: need to use the 'GML Application Schema Toolbox' plugin' when clicking on some '3.4.4-Madeira' cells. Thanks Alex I'm reasured then :)

@heidivanparys
Copy link
Author

I noticed that it actually is possible to have a setting in QGIS that makes the GML driver read XML attributes by default: GML_ATTRIBUTES_TO_OGR_FIELDS is both an open option as well as a configuration option. Configuration options can be set as environment variables, and environment variables can be set in QGIS: https://docs.qgis.org/testing/en/docs/user_manual/introduction/qgis_configuration.html#system-settings

2019-09-02 10_58_38-GML - Geography Markup Language — GDAL documentation

image

This means that the workflow becomes as simple as this once the above configuration is applied:

  1. Add the GML file to QGIS via the Add Vector Layer menu option.

@alexanderkotsev
Copy link
Contributor

Thanks @heidivanparys. Interesting way forward which would likely require a minimal modification.

@timlinux do you think it is feasible from a QGIS point of view to overwrite the default behavior of QGIS for the GML_ATTRIBUTES through the System settings instead of hard-coding the GML_ATTRIBUTES_TO_OGR_FIELDS=YES in order to change the default behavior of QGIS with INSPIRE GML?

2019-09-02 10_58_38-GML - Geography Markup Language — GDAL documentation

image

This means that the workflow becomes as simple as this once the above configuration is applied:

1. Add the GML file to QGIS via the Add Vector Layer menu option.

@heidivanparys
Copy link
Author

QGIS does not yet support setting these options via the UI (see https://issues.qgis.org/issues/20825)

Setting that option via the UI of QGIS has been fixed, see qgis/QGIS#28644 (comment) so GML_ATTRIBUTES_TO_OGR_FIELDS can be set on a dataset per dataset basis from within QGIS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants