2

I am working with this WFS endpoint:

https://wxs-gpu.mongeoportail.ign.fr/externe/39wtxmgtn23okfbbs1al2lz3/wfs

In QGIS, I do: Layer -> Add Layer -> Add WFS Layer..., then add the above endpoint. I am interested in the layer with the Title Communes, Name wfs_du:municipality:

enter image description here

I successfully add this layer to Canvas. Then I use the Identify Features functionality (I on Mac), click on a polygon, and successfully get the properties of the clicked polygon:

enter image description here

The property fields loaded:

name, gid, insee, is_rnu, is_deleted

I try to download the polygons & the property fields using ogr2ogr. As an example, I attempt to download 5 such polygons:

url="https://wxs-gpu.mongeoportail.ign.fr/externe/39wtxmgtn23okfbbs1al2lz3/wfs"
ogr2ogr output.geojson WFS:"$url" -dialect sqlite -sql "SELECT * FROM 'wfs_du:municipality' LIMIT 5"

The resulting output.geojson won't have the name property. The first 500 characters of output.geojson (via head -c500 output.geojson):

{
"type": "FeatureCollection",
"name": "SELECT",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "gml_id": "municipality.34248971", "gid": 34248971, "insee": "65252", "is_rnu": false, "is_deleted": false }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -0.1252042315, 43.167289121099998 ], [ -0.1249586084, 43.167386257899999 ], [ -0.1245957926, 43.167317557300002 ], [ -0.1226253882, 43.17097534

The properties are:

gml_id, gid, insee, is_rnu, is_deleted

The name field above got replaced by the gml_id. Somehow QGIS seems to be able to map gml_id to name, but ogr2ogr is not doing the same. I would like to have the name fields too, not the gml_id, when downloading data using ogr2ogr. In other words:

How can I download the same property fields as QGIS is showing?

1 Answer 1

3

Your issue has something to do with the attribute with a name "name". Name has some special meaning in GML3 but unfortunately I don't exactly understand what. I can only show by examples what happens with it.

GDAL is using by default the highest WFS version that the service supports, so WFS 2.0.0 in this case. Some test data can be downloaded with request

https://wxs-gpu.mongeoportail.ign.fr/externe/39wtxmgtn23okfbbs1al2lz3/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&TYPENAMES=wfs_du:municipality&STARTINDEX=0&COUNT=10

From the data it can be seen that "name" appears in the data as a GML attribute

<gml:name>LANNE</gml:name>

Other attributes are in the "https://wxs-gpu.mongeoportail.ign.fr/datastore/wfs_du" namespace

<wfs_du:gid>34248972</wfs_du:gid>
<wfs_du:insee>65257</wfs_du:insee>
<wfs_du:is_rnu>false</wfs_du:is_rnu>
<wfs_du:is_deleted>false</wfs_du:is_deleted>

Also the WFS 2.0 DescribeFeatureType shows that "name" does not belong to the attributes of the FeatureType

https://wxs-gpu.mongeoportail.ign.fr/externe/39wtxmgtn23okfbbs1al2lz3/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=DescribeFeaturetype&TYPENAME=wfs_du:municipality

<xsd:complexType name="municipalityType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="gid" nillable="false" type="xsd:int"/>
<xsd:element maxOccurs="1" minOccurs="0" name="insee" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="is_rnu" nillable="true" type="xsd:boolean"/>
<xsd:element maxOccurs="1" minOccurs="0" name="is_deleted" nillable="true" type="xsd:boolean"/>
<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:GeometryPropertyType"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

The easiest workaround is to use WFS version 1.0.0. That version is using GML2, and there "name" does not have a special meaning. Also the WFS 1.0.0 DescribeFeatureType shows "name" in the list of attributes

https://wxs-gpu.mongeoportail.ign.fr/externe/39wtxmgtn23okfbbs1al2lz3/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeaturetype&TYPENAME=wfs_du:municipality

<xsd:complexType name="municipalityType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="gid" nillable="false" type="xsd:int"/>
<xsd:element maxOccurs="1" minOccurs="0" name="insee" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="name" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="is_rnu" nillable="true" type="xsd:boolean"/>
<xsd:element maxOccurs="1" minOccurs="0" name="is_deleted" nillable="true" type="xsd:boolean"/>
<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:GeometryPropertyType"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

GDAL can be forced to use WFS 1.0.0 this way:

ogrinfo WFS:"https://wxs-gpu.mongeoportail.ign.fr/externe/39wtxmgtn23okfbbs1al2lz3/wfs?service=WFS&version=1.0.0" -sql "select * from \"wfs_du:municipality\" limit 5"
...
OGRFeature(wfs_du:municipality):34248974
  gml_id (String) = municipality.34248974
  gid (Integer) = 34248974
  insee (String) = 69052
  name (String) = CHAZAY-D'AZERGUES
  is_rnu (Integer(Boolean)) = 0
  is_deleted (Integer(Boolean)) = 0
  MULTIPOLYGON (((4.7299 45.8877,4.7302 45.88

Another workaround is to download the GML from the WFS server into a local file. The GDAL WFS driver trusts that the WFS DescribeFeatureType is reporting the schema correctly. However, when GDAL opens a GML file with the GML driver it is scanning the contents of the file and it finds also the gml:name attribute. If id does not, there is a special open option https://gdal.org/drivers/vector/gml.html#open-options for forcing that behavior GML_ATTRIBUTES_TO_OGR_FIELDS=[YES/NO].

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.