0

The German state of Schleswig-Holstein has a geoportal, where they provide a link to their WFS service:

https://service.gdi-sh.de/SH_INSPIREDOWNLOAD_AI_CP_ALKIS?service=WFS&version=2.0.0&request=GetCapabilities

Making it possible to access the state's cadastral data. I would like to create GeoJSON files of parcels of a small area programmatically (i.e. without using the export capabilities of QGIS or anything else involving clicks). I connect to the service with QGIS and observe the requests sent with the Network Logger:

enter image description here

One of the requests:

6632 GET https://service.gdi-sh.de/SH_INSPIREDOWNLOAD_AI_CP_ALKIS?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=cp:CadastralParcel&COUNT=10000&SRSNAME=urn:ogc:def:crs:EPSG::25832&BBOX=499366.66208086209371686,6042488.79555566236376762,500991.50434459594544023,6044824.24658435396850109,urn:ogc:def:crs:EPSG::25832&NAMESPACES=xmlns(cp,http://inspire.ec.europa.eu/schemas/cp/4.0)&NAMESPACE=xmlns(cp,http://inspire.ec.europa.eu/schemas/cp/4.0)

Relying this answer and the question How does QGIS extract features from the XML response of an INSPIRE WFS server?, I try:

URL="https://service.gdi-sh.de/SH_INSPIREDOWNLOAD_AI_CP_ALKIS?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=cp:CadastralParcel&COUNT=10000&SRSNAME=urn:ogc:def:crs:EPSG::25832&BBOX=499366.66208086209371686,6042488.79555566236376762,500991.50434459594544023,6044824.24658435396850109,urn:ogc:def:crs:EPSG::25832&NAMESPACES=xmlns(cp,http://inspire.ec.europa.eu/schemas/cp/4.0)&NAMESPACE=xmlns(cp,http://inspire.ec.europa.eu/schemas/cp/4.0)"
curl $URL -o inspire.xml

So far so good, the xml file seems to contain parcel polygons:

enter image description here

Continue with:

ogr2ogr -f GeoJSON inspirecp.json GMLAS:inspire.xml cadastralparcel

Output:

ERROR 3: Cannot resolve http://lxtrspa011.dpaorinp.de/aaa-suite/schema/inspire.ec.europa.eu/schemas/cp/4.0/CadastralParcels.xsd
FAILURE:
Unable to open datasource `GMLAS:inspire.xml' with the following drivers.
  -> `FITS'
  -> `PCIDSK'
  -> `netCDF'
  -> `PDS4'
  -> `VICAR'
  -> `JP2OpenJPEG'
# and many more drivers

The link to the xsd file ogr2ogr is looking for (http://lxtrspa011.dpaorinp.de/aaa-suite/schema/inspire.ec.europa.eu/schemas/cp/4.0/CadastralParcels.xsd) indeed seems dead (failed to access it via browser too). If I follow the link at the end of the request sent by QGIS (http://inspire.ec.europa.eu/schemas/cp/4.0), there is a CadastralParcels.xsd file available:

https://inspire.ec.europa.eu/schemas/cp/4.0/CadastralParcels.xsd

I download this file (curl "https://inspire.ec.europa.eu/schemas/cp/4.0/CadastralParcels.xsd" -o CadastralParcels.xsd) and try to feed it to ogr2ogr using this answer:

ogr2ogr -f GeoJSON parcelsTest.geojson inspire.xml CadastralParcel -oo XSD=CadastralParcels.xsd

Output:

ERROR 1: No schema information loaded

(I also tried ogr2ogr -f GeoJSON -dialect sqlite -sql "SELECT * FROM CadastralParcel" parcelsTest.geojson inspire.xml -oo XSD=CadastralParcels.xsd, which failed too.)

The produced parcelsTest.geojson only contains reference points, not parcel polygons. head -c2000 parcelsTest.geojson:

{
"type": "FeatureCollection",
"name": "CadastralParcel",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::25832" } },
"features": [
{ "type": "Feature", "properties": { "gml_id": "CadastralParcel_01159600100548______", "identifier": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis/CadastralParcel_01159600100548______", "areaValue": 967.0, "beginLifespanVersion": "2011-05-31T17:01:14Z", "endLifespanVersion": "", "localId": "CadastralParcel_01159600100548______", "namespace": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis", "label": "548", "nationalCadastralReference": "01159600100548______", "validTo": "", "zoning": "" }, "geometry": { "type": "Point", "coordinates": [ 499537.314000000013039, 6042680.542999999597669 ] } },
{ "type": "Feature", "properties": { "gml_id": "CadastralParcel_01159600100571______", "identifier": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis/CadastralParcel_01159600100571______", "areaValue": 2024.0, "beginLifespanVersion": "2011-05-31T17:01:14Z", "endLifespanVersion": "", "localId": "CadastralParcel_01159600100571______", "namespace": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis", "label": "571", "nationalCadastralReference": "01159600100571______", "validTo": "", "zoning": "" }, "geometry": { "type": "Point", "coordinates": [ 499593.968999999982771, 6042767.157999999821186 ] } },
{ "type": "Feature", "properties": { "gml_id": "CadastralParcel_01159600100551______", "identifier": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis/CadastralParcel_01159600100551______", "areaValue": 1243.0, "beginLifespanVersion": "2011-05-31T17:01:14Z", "endLifespanVersion": "", "localId": "CadastralParcel_01159600100551______", "namespace": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis", "label": "551", "nationalCadastralReference": "01159600100551______", "validTo": "", "zoning": "" }, "geometry": { "type": "Point", "coordinates": [ 499546.956, 6042727.576999999582767 ] } },
{ "type": "F%   

QGIS is able to connect to the WFS endpoint and display parcel boundary information (along with metadata, if I use the Identify Features) tool. I would like to access the same information via ogr2ogr (or any other scriptable tool).

How can I use the WFS link to download parcel data into GeoJSON files?


A further observation. While in the referenced answer, ogrinfo GMLAS:inspire.xml works, in this case, ogrinfo GMLAS:inspire.xml returns:

ERROR 3: Cannot resolve http://lxtrspa011.dpaorinp.de/aaa-suite/schema/inspire.ec.europa.eu/schemas/cp/4.0/CadastralParcels.xsd
FAILURE:
Unable to open datasource `GMLAS:inspire.xml' with the following drivers.
  -> ESRIC
  -> FITS
  -> PCIDSK
  -> netCDF
  -> PDS4
  -> VICAR
  -> JP2OpenJPEG
# and many more drivers 

Trying to follow the advice in this answer, I attempt:

#!/bin/bash

URL="https://service.gdi-sh.de/SH_INSPIREDOWNLOAD_AI_CP_ALKIS?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=cp:CadastralParcel&COUNT=10000&SRSNAME=urn:ogc:def:crs:EPSG::25832&BBOX=499366.66208086209371686,6042488.79555566236376762,500991.50434459594544023,6044824.24658435396850109,urn:ogc:def:crs:EPSG::25832&NAMESPACES=xmlns(cp,http://inspire.ec.europa.eu/schemas/cp/4.0)&NAMESPACE=xmlns(cp,http://inspire.ec.europa.eu/schemas/cp/4.0)"
curl $URL -o inspire.xml

right_schema_url="https://service.gdi-sh.de/SH_INSPIREDOWNLOAD_AI_CP_ALKIS?service=wfs&version=2.0.0&request=describeFeatureType&typename=cp:CadastralParcel"
curl $right_schema_url -o schema.xml

ogrinfo -so -al -oo XSD=schema.xml inspire.xml # <- works nicely

ogr2ogr -f GeoJSON parcelsTest.geojson inspire.xml CadastralParcel -oo XSD=schema.xml # <- still fails

which still fails, with head -c2000 parcelsTest.geojson giving

{
"type": "FeatureCollection",
"name": "CadastralParcel",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::25832" } },
"features": [
{ "type": "Feature", "properties": { "gml_id": "CadastralParcel_01159600100548______", "identifier": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis/CadastralParcel_01159600100548______", "areaValue": 967.0, "beginLifespanVersion": "2011-05-31T17:01:14Z", "endLifespanVersion": "", "localId": "CadastralParcel_01159600100548______", "namespace": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis", "label": "548", "nationalCadastralReference": "01159600100548______", "validTo": "", "zoning": "" }, "geometry": { "type": "Point", "coordinates": [ 499537.314000000013039, 6042680.542999999597669 ] } },
{ "type": "Feature", "properties": { "gml_id": "CadastralParcel_01159600100571______", "identifier": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis/CadastralParcel_01159600100571______", "areaValue": 2024.0, "beginLifespanVersion": "2011-05-31T17:01:14Z", "endLifespanVersion": "", "localId": "CadastralParcel_01159600100571______", "namespace": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis", "label": "571", "nationalCadastralReference": "01159600100571______", "validTo": "", "zoning": "" }, "geometry": { "type": "Point", "coordinates": [ 499593.968999999982771, 6042767.157999999821186 ] } },
{ "type": "Feature", "properties": { "gml_id": "CadastralParcel_01159600100551______", "identifier": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis/CadastralParcel_01159600100551______", "areaValue": 1243.0, "beginLifespanVersion": "2011-05-31T17:01:14Z", "endLifespanVersion": "", "localId": "CadastralParcel_01159600100551______", "namespace": "https://registry.gdi-de.org/id/de.sh.inspire.cp.alkis", "label": "551", "nationalCadastralReference": "01159600100551______", "validTo": "", "zoning": "" }, "geometry": { "type": "Point", "coordinates": [ 499546.956, 6042727.576999999582767 ] } },
{ "type": "F
1
  • The DescribeFeatureType schema is invalid according to oXygen XML validator. You should edit the schema.xml file and replace the http://lxtrspa011.dpaorinp.de/aaa-suite/schema/ogc/gml/3.2.1/gml.xsd schema location with https://schemas.opengis.net/gml/3.2.1/gml.xsd
    – nmtoken
    Jun 9, 2023 at 9:47

1 Answer 1

2

You can get the required schema for the layer by using:

https://service.gdi-sh.de/SH_INSPIREDOWNLOAD_AI_CP_ALKIS?service=wfs&version=2.0.0&request=describeFeatureType&typename=cp:CadastralParcel

You can then specify the open option XSD=filename to your OGR command to override the schema location.

ogrinfo -so -al -oo XSD=schema.xml inspire.xml

It is probably also worth notifying the owners of the portal that their output is broken.

2
  • Thanks! Attempting to make this work...
    – zabop
    Dec 31, 2022 at 11:19
  • The ogrinfocommand indeed works, thanks! I haven't been able to make the ogr2ogr bit work though (details: see appended question).
    – zabop
    Dec 31, 2022 at 15:53

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.