@@ -1214,6 +1214,17 @@ bool QgsWFSProvider::describeFeatureType( QString &geometryAttribute, QgsFields
1214
1214
QgsDebugMsg ( " Server does not accept TYPENAME parameter for DescribeFeatureType. Re-trying with TYPENAMES" );
1215
1215
bUsePlural = true ;
1216
1216
}
1217
+ // "http://services.cuzk.cz/wfs/inspire-cp-wfs.asp?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAME=cp:CadastralParcel" returns
1218
+ // <!--Generated by Marushka, version 4.2.5.0, GEOVAP, spol. s r.o., 31.05.2018.-->
1219
+ // <ExceptionReport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0.0" xml:lang="en-US" xmlns="http://www.opengis.net/ows/1.1">
1220
+ // <Exception exceptionCode="OperationProcessingFailed" />
1221
+ // </ExceptionReport>
1222
+ else if ( i == 0 && response.indexOf ( " <!--Generated by Marushka" ) >= 0 &&
1223
+ response.indexOf ( " OperationProcessingFailed" ) >= 0 )
1224
+ {
1225
+ QgsDebugMsg ( " Server does not accept TYPENAME parameter for DescribeFeatureType. Re-trying with TYPENAMES" );
1226
+ bUsePlural = true ;
1227
+ }
1217
1228
else
1218
1229
{
1219
1230
break ;
@@ -1234,6 +1245,7 @@ bool QgsWFSProvider::describeFeatureType( QString &geometryAttribute, QgsFields
1234
1245
mShared ->mURI .typeName (),
1235
1246
geometryAttribute, fields, geomType, errorMsg ) )
1236
1247
{
1248
+ QgsDebugMsg ( response );
1237
1249
QgsMessageLog::logMessage ( tr ( " Analysis of DescribeFeatureType response failed for url %1: %2" ).
1238
1250
arg ( dataSourceUri (), errorMsg ), tr ( " WFS" ) );
1239
1251
return false ;
@@ -1306,11 +1318,21 @@ bool QgsWFSProvider::readAttributesFromSchema( QDomDocument &schemaDoc,
1306
1318
QDomElement iter = schemaElement.firstChildElement ();
1307
1319
bool onlyIncludeOrImport = true ;
1308
1320
bool foundImport = false ;
1321
+ int countInclude = 0 ;
1322
+ QDomElement includeElement;
1309
1323
while ( !iter.isNull () )
1310
1324
{
1311
1325
if ( iter.tagName () == QLatin1String ( " import" ) )
1312
1326
foundImport = true ;
1313
- else if ( iter.tagName () != QLatin1String ( " include" ) )
1327
+ else if ( iter.tagName () == QLatin1String ( " include" ) )
1328
+ {
1329
+ countInclude++;
1330
+ if ( countInclude == 1 )
1331
+ {
1332
+ includeElement = iter;
1333
+ }
1334
+ }
1335
+ else
1314
1336
{
1315
1337
onlyIncludeOrImport = false ;
1316
1338
break ;
@@ -1321,6 +1343,41 @@ bool QgsWFSProvider::readAttributesFromSchema( QDomDocument &schemaDoc,
1321
1343
{
1322
1344
errorMsg = tr ( " It is probably a schema for Complex Features." );
1323
1345
}
1346
+ // e.g http://services.cuzk.cz/wfs/inspire-CP-wfs.asp?SERVICE=WFS&VERSION=2.0.0&REQUEST=DescribeFeatureType
1347
+ // which has a single <include schemaLocation="http://inspire.ec.europa.eu/schemas/cp/4.0/CadastralParcels.xsd"/>
1348
+ // In that case, follow the link.
1349
+ else if ( !foundImport && countInclude == 1 )
1350
+ {
1351
+ QString schemaLocation =
1352
+ includeElement.attribute ( QStringLiteral ( " schemaLocation" ) );
1353
+ QgsDebugMsg ( QStringLiteral ( " DescribeFeatureType response redirects to: %1" ).arg ( schemaLocation ) );
1354
+
1355
+ QgsWFSDescribeFeatureType describeFeatureType ( mShared ->mURI );
1356
+ if ( !describeFeatureType.sendGET ( schemaLocation, true , false ) )
1357
+ {
1358
+ errorMsg = tr ( " Cannot find schema indicated in DescribeFeatureType response." );
1359
+ QgsMessageLog::logMessage ( tr ( " DescribeFeatureType network request failed for url %1: %2" ).
1360
+ arg ( schemaLocation, describeFeatureType.errorMessage () ), tr ( " WFS" ) );
1361
+ return false ;
1362
+ }
1363
+
1364
+ QByteArray response = describeFeatureType.response ();
1365
+ QDomDocument describeFeatureDocument;
1366
+ if ( !describeFeatureDocument.setContent ( response, true , &errorMsg ) )
1367
+ {
1368
+ QgsDebugMsg ( response );
1369
+ errorMsg = tr ( " DescribeFeatureType XML parse failed for url %1: %2" ).
1370
+ arg ( schemaLocation, errorMsg );
1371
+ }
1372
+
1373
+ return readAttributesFromSchema ( describeFeatureDocument,
1374
+ prefixedTypename,
1375
+ geometryAttribute,
1376
+ fields,
1377
+ geomType,
1378
+ errorMsg );
1379
+
1380
+ }
1324
1381
else
1325
1382
{
1326
1383
errorMsg = tr ( " Cannot find element '%1'" ).arg ( unprefixedTypename );
0 commit comments