@@ -79,7 +79,7 @@ QString QgsGmlSchema::readAttribute( const QString& attributeName, const XML_Cha
79
79
{
80
80
return QString ( attr[i+1 ] );
81
81
}
82
- ++i ;
82
+ i += 2 ;
83
83
}
84
84
return QString ();
85
85
}
@@ -374,6 +374,7 @@ void QgsGmlSchema::startElement( const XML_Char* el, const XML_Char** attr )
374
374
// QgsDebugMsg( "ns = " + ns + " localName = " + localName );
375
375
376
376
ParseMode parseMode = modeStackTop ();
377
+ // QgsDebugMsg ( QString("localName = %1 parseMode = %2").arg(localName).arg(parseMode) );
377
378
378
379
if ( ns == GML_NAMESPACE && localName == " boundedBy" )
379
380
{
@@ -388,6 +389,7 @@ void QgsGmlSchema::startElement( const XML_Char* el, const XML_Char** attr )
388
389
// with 'Member' apart standard gml:featureMember, but it is quite usual to
389
390
// that the names ends with 'Member', e.g.: osgb:topographicMember, cityMember,...
390
391
// so this is really fail if the name does not contain 'Member'
392
+
391
393
else if ( localName.endsWith ( " member" , Qt::CaseInsensitive ) )
392
394
{
393
395
mParseModeStack .push ( QgsGmlSchema::featureMember );
@@ -398,12 +400,15 @@ void QgsGmlSchema::startElement( const XML_Char* el, const XML_Char** attr )
398
400
// do nothing, we catch _feature children
399
401
}
400
402
// UMN Mapserver simple GetFeatureInfo response feature element (ends with _feature)
401
- // or featureMember children
403
+ // or featureMember children.
404
+ // QGIS mapserver 2.2 GetFeatureInfo is using <Feature id="###"> for feature member,
405
+ // without any feature class distinction.
402
406
else if ( elementName.endsWith ( " _feature" )
403
407
|| parseMode == QgsGmlSchema::featureMember
404
- || parseMode == QgsGmlSchema::featureMembers )
408
+ || parseMode == QgsGmlSchema::featureMembers
409
+ || localName.compare ( " feature" , Qt::CaseInsensitive ) == 0 )
405
410
{
406
- // QgsDebugMsg ( "is feature path = " + path );
411
+ QgsDebugMsg ( " is feature path = " + path );
407
412
if ( mFeatureClassMap .count ( localName ) == 0 )
408
413
{
409
414
mFeatureClassMap .insert ( localName, QgsGmlFeatureClass ( localName, path ) );
@@ -425,9 +430,26 @@ void QgsGmlSchema::startElement( const XML_Char* el, const XML_Char** attr )
425
430
{
426
431
// An element in feature should be ordinary or geometry attribute
427
432
// QgsDebugMsg( "is attribute");
428
- mParseModeStack .push ( QgsGmlSchema::attribute );
429
- mAttributeName = localName;
430
- mStringCash .clear ();
433
+
434
+ // Usually localName is attribute name, e.g.
435
+ // <gml:desc>My description</gml:desc>
436
+ // but QGIS server (2.2) is using:
437
+ // <Attribute value="My description" name="desc"/>
438
+ QString name = readAttribute ( " name" , attr );
439
+ // QgsDebugMsg ( "attribute name = " + name );
440
+ if ( localName.compare ( " attribute" , Qt::CaseInsensitive ) == 0
441
+ && !name.isEmpty () )
442
+ {
443
+ QString value = readAttribute ( " value" , attr );
444
+ // QgsDebugMsg ( "attribute value = " + value );
445
+ addAttribute ( name, value );
446
+ }
447
+ else
448
+ {
449
+ mAttributeName = localName;
450
+ mParseModeStack .push ( QgsGmlSchema::attribute );
451
+ mStringCash .clear ();
452
+ }
431
453
}
432
454
}
433
455
@@ -466,41 +488,7 @@ void QgsGmlSchema::endElement( const XML_Char* el )
466
488
467
489
if ( mFeatureClassMap [mCurrentFeatureName ].geometryAttributes ().count ( mAttributeName ) == 0 )
468
490
{
469
- // It is not geometry attribute -> analyze value
470
- bool ok;
471
- mStringCash .toInt ( &ok );
472
- QVariant::Type type = QVariant::String;
473
- if ( ok )
474
- {
475
- type = QVariant::Int;
476
- }
477
- else
478
- {
479
- mStringCash .toDouble ( &ok );
480
- if ( ok )
481
- {
482
- type = QVariant::Double;
483
- }
484
- }
485
- // QgsDebugMsg( "mStringCash = " + mStringCash + " type = " + QVariant::typeToName( type ) );
486
- // QMap<QString, QgsField> & fields = mFeatureClassMap[mCurrentFeatureName].fields();
487
- QList<QgsField> & fields = mFeatureClassMap [mCurrentFeatureName ].fields ();
488
- int fieldIndex = mFeatureClassMap [mCurrentFeatureName ].fieldIndex ( mAttributeName );
489
- if ( fieldIndex == -1 )
490
- {
491
- QgsField field ( mAttributeName , type );
492
- fields.append ( field );
493
- }
494
- else
495
- {
496
- QgsField &field = fields[fieldIndex];
497
- // check if type is sufficient
498
- if (( field.type () == QVariant::Int && ( type == QVariant::String || type == QVariant::Double ) ) ||
499
- ( field.type () == QVariant::Double && type == QVariant::String ) )
500
- {
501
- field.setType ( type );
502
- }
503
- }
491
+ addAttribute ( mAttributeName , mStringCash );
504
492
}
505
493
}
506
494
else if ( ns == GML_NAMESPACE && localName == " boundedBy" )
@@ -531,6 +519,45 @@ void QgsGmlSchema::characters( const XML_Char* chars, int len )
531
519
}
532
520
}
533
521
522
+ void QgsGmlSchema::addAttribute ( const QString& name, const QString& value )
523
+ {
524
+ // It is not geometry attribute -> analyze value
525
+ bool ok;
526
+ value.toInt ( &ok );
527
+ QVariant::Type type = QVariant::String;
528
+ if ( ok )
529
+ {
530
+ type = QVariant::Int;
531
+ }
532
+ else
533
+ {
534
+ value.toDouble ( &ok );
535
+ if ( ok )
536
+ {
537
+ type = QVariant::Double;
538
+ }
539
+ }
540
+ // QgsDebugMsg( "mStringCash = " + mStringCash + " type = " + QVariant::typeToName( type ) );
541
+ // QMap<QString, QgsField> & fields = mFeatureClassMap[mCurrentFeatureName].fields();
542
+ QList<QgsField> & fields = mFeatureClassMap [mCurrentFeatureName ].fields ();
543
+ int fieldIndex = mFeatureClassMap [mCurrentFeatureName ].fieldIndex ( name );
544
+ if ( fieldIndex == -1 )
545
+ {
546
+ QgsField field ( name, type );
547
+ fields.append ( field );
548
+ }
549
+ else
550
+ {
551
+ QgsField &field = fields[fieldIndex];
552
+ // check if type is sufficient
553
+ if (( field.type () == QVariant::Int && ( type == QVariant::String || type == QVariant::Double ) ) ||
554
+ ( field.type () == QVariant::Double && type == QVariant::String ) )
555
+ {
556
+ field.setType ( type );
557
+ }
558
+ }
559
+ }
560
+
534
561
QStringList QgsGmlSchema::typeNames () const
535
562
{
536
563
return mFeatureClassMap .keys ();
0 commit comments