21 #include <QDomDocument> 
   22 #include <QTextDocumentFragment> 
   27   const QDomElement metadataElem = document.firstChildElement( QStringLiteral( 
"metadata" ) );
 
   29   const QDomElement esri = metadataElem.firstChildElement( QStringLiteral( 
"Esri" ) );
 
   30   const QDomElement dataProperties = esri.firstChildElement( QStringLiteral( 
"DataProperties" ) );
 
   31   const QDomElement itemProps = dataProperties.firstChildElement( QStringLiteral( 
"itemProps" ) );
 
   32   metadata.
setIdentifier( itemProps.firstChildElement( QStringLiteral( 
"itemName" ) ).text() );
 
   34   const QDomElement dataIdInfo = metadataElem.firstChildElement( QStringLiteral( 
"dataIdInfo" ) );
 
   35   const QDomElement idInfo = metadataElem.firstChildElement( QStringLiteral( 
"idinfo" ) );
 
   38   const QDomElement idCitation = dataIdInfo.firstChildElement( QStringLiteral( 
"idCitation" ) );
 
   39   const QString title = idCitation.firstChildElement( QStringLiteral( 
"resTitle" ) ).text();
 
   43   if ( metadata.
identifier().isEmpty()  && !title.isEmpty() )
 
   47   const QDomElement idAbs = dataIdInfo.firstChildElement( QStringLiteral( 
"idAbs" ) );
 
   48   const QString abstractPlainText = QTextDocumentFragment::fromHtml( idAbs.text() ).toPlainText();
 
   52   const QDomElement idPurp = dataIdInfo.firstChildElement( QStringLiteral( 
"idPurp" ) );
 
   53   const QString purposePlainText = QTextDocumentFragment::fromHtml( idPurp.text() ).toPlainText();
 
   54   if ( !metadata.
abstract().isEmpty() )
 
   60   const QDomElement descript = idInfo.firstChildElement( QStringLiteral( 
"descript" ) );
 
   61   if ( !descript.isNull() )
 
   63     const QDomElement 
abstract = descript.firstChildElement( QStringLiteral( 
"abstract" ) );
 
   64     const QString abstractPlainText = QTextDocumentFragment::fromHtml( 
abstract.text() ).toPlainText();
 
   65     if ( !abstractPlainText.isEmpty() )
 
   67       if ( !metadata.
abstract().isEmpty() )
 
   73     const QDomElement purpose = descript.firstChildElement( QStringLiteral( 
"purpose" ) );
 
   74     const QString purposePlainText = QTextDocumentFragment::fromHtml( purpose.text() ).toPlainText();
 
   75     if ( !purposePlainText.isEmpty() )
 
   77       if ( !metadata.
abstract().isEmpty() )
 
   83     const QDomElement supplinf = descript.firstChildElement( QStringLiteral( 
"supplinf" ) );
 
   84     const QString supplinfPlainText = QTextDocumentFragment::fromHtml( supplinf.text() ).toPlainText();
 
   85     if ( !supplinfPlainText.isEmpty() )
 
   87       if ( !metadata.
abstract().isEmpty() )
 
   95   const QDomElement suppInfo = dataIdInfo.firstChildElement( QStringLiteral( 
"suppInfo" ) );
 
   96   const QString suppInfoPlainText = QTextDocumentFragment::fromHtml( suppInfo.text() ).toPlainText();
 
   97   if ( !suppInfoPlainText.isEmpty() )
 
   99     if ( !metadata.
abstract().isEmpty() )
 
  100       metadata.
setAbstract( metadata.
abstract() + QStringLiteral( 
"\n\n" ) + suppInfoPlainText );
 
  106   const QDomElement dataLang = dataIdInfo.firstChildElement( QStringLiteral( 
"dataLang" ) );
 
  107   const QDomElement languageCode = dataLang.firstChildElement( QStringLiteral( 
"languageCode" ) );
 
  108   const QString language = languageCode.attribute( QStringLiteral( 
"value" ) ).toUpper();
 
  112   QDomElement searchKeys = dataIdInfo.firstChildElement( QStringLiteral( 
"searchKeys" ) );
 
  113   QStringList keywords;
 
  114   while ( !searchKeys.isNull() )
 
  116     QDomElement keyword = searchKeys.firstChildElement( QStringLiteral( 
"keyword" ) );
 
  117     while ( !keyword.isNull() )
 
  119       keywords << keyword.text();
 
  120       keyword = keyword.nextSiblingElement( QStringLiteral( 
"keyword" ) );
 
  123     searchKeys = searchKeys.nextSiblingElement( QStringLiteral( 
"searchKeys" ) );
 
  127   QDomElement themeKeys = dataIdInfo.firstChildElement( QStringLiteral( 
"themeKeys" ) );
 
  128   QStringList categories;
 
  129   while ( !themeKeys.isNull() )
 
  131     const QDomElement thesaName = themeKeys.firstChildElement( QStringLiteral( 
"thesaName" ) );
 
  132     const QString thesaTitle = thesaName.firstChildElement( QStringLiteral( 
"resTitle" ) ).text();
 
  134     const bool isSearchKeyWord = thesaTitle.compare( QLatin1String( 
"Common Search Terms" ), Qt::CaseInsensitive ) == 0;
 
  136     QDomElement themeKeyword = themeKeys.firstChildElement( QStringLiteral( 
"keyword" ) );
 
  137     while ( !themeKeyword.isNull() )
 
  139       if ( isSearchKeyWord )
 
  141         keywords.append( themeKeyword.text().split( 
',' ) );
 
  145         categories << themeKeyword.text();
 
  147       themeKeyword = themeKeyword.nextSiblingElement( QStringLiteral( 
"keyword" ) );
 
  149     themeKeys = themeKeys.nextSiblingElement( QStringLiteral( 
"themeKeys" ) );
 
  153   QDomElement keywordsElem = idInfo.firstChildElement( QStringLiteral( 
"keywords" ) );
 
  154   while ( !keywordsElem.isNull() )
 
  156     QDomElement theme = keywordsElem.firstChildElement( QStringLiteral( 
"theme" ) );
 
  157     while ( !theme.isNull() )
 
  159       categories << theme.firstChildElement( QStringLiteral( 
"themekey" ) ).text();
 
  160       theme = theme.nextSiblingElement( QStringLiteral( 
"theme" ) );
 
  163     keywordsElem = keywordsElem.nextSiblingElement( QStringLiteral( 
"keywords" ) );
 
  166   if ( !categories.isEmpty() )
 
  169   if ( !keywords.empty() )
 
  170     metadata.
addKeywords( QObject::tr( 
"Search keys" ), keywords );
 
  175   const QDomElement date = idCitation.firstChildElement( QStringLiteral( 
"date" ) );
 
  176   const QString pubDate = date.firstChildElement( QStringLiteral( 
"pubDate" ) ).text();
 
  177   const QDateTime publicationDate = QDateTime::fromString( pubDate, Qt::ISODate );
 
  178   if ( publicationDate.isValid() )
 
  185     QDomElement timeperd = idInfo.firstChildElement( QStringLiteral( 
"timeperd" ) );
 
  186     while ( !timeperd.isNull() )
 
  188       if ( timeperd.firstChildElement( QStringLiteral( 
"current" ) ).text().compare( QLatin1String( 
"publication date" ) ) == 0 )
 
  190         const QDomElement timeinfo = timeperd.firstChildElement( QStringLiteral( 
"timeinfo" ) );
 
  191         const QDomElement sngdate = timeinfo.firstChildElement( QStringLiteral( 
"sngdate" ) );
 
  192         if ( !sngdate.isNull() )
 
  194           const QDomElement caldate = sngdate.firstChildElement( QStringLiteral( 
"caldate" ) );
 
  195           const QString caldateString = caldate.text();
 
  196           const QDateTime publicationDate = QDateTime::fromString( caldateString, QStringLiteral( 
"MMMM yyyy" ) );
 
  197           if ( publicationDate.isValid() )
 
  203         const QDomElement rngdates = timeinfo.firstChildElement( QStringLiteral( 
"rngdates" ) );
 
  204         if ( !rngdates.isNull() )
 
  206           const QDomElement begdate = rngdates.firstChildElement( QStringLiteral( 
"begdate" ) );
 
  207           const QDomElement enddate = rngdates.firstChildElement( QStringLiteral( 
"enddate" ) );
 
  208           const QString begdateString = begdate.text();
 
  209           const QString enddateString = enddate.text();
 
  212           for ( 
const QString format : { 
"yyyy-MM-dd", 
"dd/MM/yyyy" } )
 
  214             if ( !begin.isValid() )
 
  215               begin = QDateTime::fromString( begdateString, format );
 
  216             if ( !end.isValid() )
 
  217               end = QDateTime::fromString( enddateString, format );
 
  220           if ( begin.isValid() || end.isValid() )
 
  228       timeperd = timeperd.nextSiblingElement( QStringLiteral( 
"timeperd" ) );
 
  234   QDomElement refSysInfo = metadataElem.firstChildElement( QStringLiteral( 
"refSysInfo" ) );
 
  235   while ( !refSysInfo.isNull() )
 
  237     const QDomElement refSystem = refSysInfo.firstChildElement( QStringLiteral( 
"RefSystem" ) );
 
  238     const QDomElement refSysID = refSystem.firstChildElement( QStringLiteral( 
"refSysID" ) );
 
  239     const QDomElement identAuth = refSysID.firstChildElement( QStringLiteral( 
"identAuth" ) );
 
  240     if ( !identAuth.isNull() )
 
  242       if ( identAuth.firstChildElement( QStringLiteral( 
"resTitle" ) ).text().compare( QLatin1String( 
"EPSG Geodetic Parameter Dataset" ) ) == 0 )
 
  244         const QString code = refSysID.firstChildElement( QStringLiteral( 
"identCode" ) ).attribute( QStringLiteral( 
"code" ) );
 
  250       const QString code = refSysID.firstChildElement( QStringLiteral( 
"identCode" ) ).attribute( QStringLiteral( 
"code" ) );
 
  251       const QString auth = refSysID.firstChildElement( QStringLiteral( 
"idCodeSpace" ) ).text();
 
  260     refSysInfo = refSysInfo.nextSiblingElement( QStringLiteral( 
"refSysInfo" ) );
 
  264   QDomElement dataExt = dataIdInfo.firstChildElement( QStringLiteral( 
"dataExt" ) );
 
  265   while ( !dataExt.isNull() )
 
  267     const QDomElement geoEle = dataExt.firstChildElement( QStringLiteral( 
"geoEle" ) );
 
  268     if ( !geoEle.isNull() )
 
  270       const QDomElement geoBndBox = geoEle.firstChildElement( QStringLiteral( 
"GeoBndBox" ) );
 
  271       const double west = geoBndBox.firstChildElement( QStringLiteral( 
"westBL" ) ).text().toDouble();
 
  272       const double east = geoBndBox.firstChildElement( QStringLiteral( 
"eastBL" ) ).text().toDouble();
 
  273       const double south = geoBndBox.firstChildElement( QStringLiteral( 
"northBL" ) ).text().toDouble();
 
  274       const double north = geoBndBox.firstChildElement( QStringLiteral( 
"southBL" ) ).text().toDouble();
 
  278       spatialExtent.
bounds = 
QgsBox3d( west, south, 0, east, north, 0 );
 
  283     dataExt = dataExt.nextSiblingElement( QStringLiteral( 
"dataExt" ) );
 
  289   QStringList licenses;
 
  292   QDomElement resConst = dataIdInfo.firstChildElement( QStringLiteral( 
"resConst" ) );
 
  293   while ( !resConst.isNull() )
 
  295     QDomElement legConsts = resConst.firstChildElement( QStringLiteral( 
"LegConsts" ) );
 
  296     while ( !legConsts.isNull() )
 
  298       const QString restrictCd = legConsts.firstChildElement( QStringLiteral( 
"useConsts" ) ).firstChildElement( QStringLiteral( 
"RestrictCd" ) ).attribute( QStringLiteral( 
"value" ) );
 
  300       if ( restrictCd.compare( QLatin1String( 
"005" ) ) == 0 )
 
  302         licenses << QTextDocumentFragment::fromHtml( legConsts.firstChildElement( QStringLiteral( 
"useLimit" ) ).text() ).toPlainText();
 
  304       else if ( restrictCd.compare( QLatin1String( 
"006" ) ) == 0 )
 
  306         rights << QTextDocumentFragment::fromHtml( legConsts.firstChildElement( QStringLiteral( 
"useLimit" ) ).text() ).toPlainText();
 
  308       legConsts = legConsts.nextSiblingElement( QStringLiteral( 
"LegConsts" ) );
 
  311     QDomElement secConsts = resConst.firstChildElement( QStringLiteral( 
"SecConsts" ) );
 
  312     while ( !secConsts.isNull() )
 
  315       constraint.
type = QObject::tr( 
"Security constraints" );
 
  316       constraint.
constraint = QTextDocumentFragment::fromHtml( secConsts.firstChildElement( QStringLiteral( 
"userNote" ) ).text() ).toPlainText();
 
  317       constraints << constraint;
 
  318       secConsts = secConsts.nextSiblingElement( QStringLiteral( 
"SecConsts" ) );
 
  321     QDomElement consts = resConst.firstChildElement( QStringLiteral( 
"Consts" ) );
 
  322     while ( !consts.isNull() )
 
  325       constraint.
type = QObject::tr( 
"Limitations of use" );
 
  326       constraint.
constraint = QTextDocumentFragment::fromHtml( consts.firstChildElement( QStringLiteral( 
"useLimit" ) ).text() ).toPlainText();
 
  327       constraints << constraint;
 
  328       consts = consts.nextSiblingElement( QStringLiteral( 
"Consts" ) );
 
  331     resConst = resConst.nextSiblingElement( QStringLiteral( 
"resConst" ) );
 
  334   const QDomElement idCredit = dataIdInfo.firstChildElement( QStringLiteral( 
"idCredit" ) );
 
  335   const QString credit = idCredit.text();
 
  336   if ( !credit.isEmpty() )
 
  340   QDomElement accconst = idInfo.firstChildElement( QStringLiteral( 
"accconst" ) );
 
  341   while ( !accconst.isNull() )
 
  344     constraint.
type = QObject::tr( 
"Access" );
 
  345     constraint.
constraint = QTextDocumentFragment::fromHtml( accconst.text() ).toPlainText();
 
  346     constraints << constraint;
 
  348     accconst = accconst.nextSiblingElement( QStringLiteral( 
"accconst" ) );
 
  350   QDomElement useconst = idInfo.firstChildElement( QStringLiteral( 
"useconst" ) );
 
  351   while ( !useconst.isNull() )
 
  353     rights << QTextDocumentFragment::fromHtml( useconst.text() ).toPlainText();
 
  354     useconst = useconst.nextSiblingElement( QStringLiteral( 
"useconst" ) );
 
  362   const QDomElement distInfo = metadataElem.firstChildElement( QStringLiteral( 
"distInfo" ) );
 
  363   const QDomElement distributor = distInfo.firstChildElement( QStringLiteral( 
"distributor" ) );
 
  365   QDomElement distorTran = distributor.firstChildElement( QStringLiteral( 
"distorTran" ) );
 
  366   while ( !distorTran.isNull() )
 
  368     const QDomElement onLineSrc = distorTran.firstChildElement( QStringLiteral( 
"onLineSrc" ) );
 
  369     if ( !onLineSrc.isNull() )
 
  372       link.
url = onLineSrc.firstChildElement( QStringLiteral( 
"linkage" ) ).text();
 
  374       const QDomElement distorFormat = distributor.firstChildElement( QStringLiteral( 
"distorFormat" ) );
 
  375       link.
name = distorFormat.firstChildElement( QStringLiteral( 
"formatName" ) ).text();
 
  376       link.
type = distorFormat.firstChildElement( QStringLiteral( 
"formatSpec" ) ).text();
 
  378       if ( link.
type.isEmpty() )
 
  381         link.
type = onLineSrc.firstChildElement( QStringLiteral( 
"protocol" ) ).text();
 
  386     distorTran = distorTran.nextSiblingElement( QStringLiteral( 
"distorTran" ) );
 
  390   const QDomElement dqInfo = metadataElem.firstChildElement( QStringLiteral( 
"dqInfo" ) );
 
  391   const QDomElement dataLineage = dqInfo.firstChildElement( QStringLiteral( 
"dataLineage" ) );
 
  392   const QString statement = QTextDocumentFragment::fromHtml( dataLineage.firstChildElement( QStringLiteral( 
"statement" ) ).text() ).toPlainText();
 
  393   if ( !statement.isEmpty() )
 
  396   QDomElement dataSource = dataLineage.firstChildElement( QStringLiteral( 
"dataSource" ) );
 
  397   while ( !dataSource.isNull() )
 
  399     metadata.
addHistoryItem( QObject::tr( 
"Data source: %1" ).arg( QTextDocumentFragment::fromHtml( dataSource.firstChildElement( QStringLiteral( 
"srcDesc" ) ).text() ).toPlainText() ) );
 
  400     dataSource = dataSource.nextSiblingElement( QStringLiteral( 
"dataSource" ) );
 
  404   const QDomElement mdContact = metadataElem.firstChildElement( QStringLiteral( 
"mdContact" ) );
 
  405   if ( !mdContact.isNull() )
 
  408     contact.
name = mdContact.firstChildElement( QStringLiteral( 
"rpIndName" ) ).text();
 
  409     contact.
organization = mdContact.firstChildElement( QStringLiteral( 
"rpOrgName" ) ).text();
 
  410     contact.
position = mdContact.firstChildElement( QStringLiteral( 
"rpPosName" ) ).text();
 
  412     const QString role = mdContact.firstChildElement( QStringLiteral( 
"role" ) ).firstChildElement( QStringLiteral( 
"RoleCd" ) ).attribute( QStringLiteral( 
"value" ) );
 
  413     if ( role == QLatin1String( 
"007" ) )
 
  414       contact.
role = QObject::tr( 
"Point of contact" );
 
  416     const QDomElement rpCntInfo = mdContact.firstChildElement( QStringLiteral( 
"rpCntInfo" ) );
 
  417     contact.
email = rpCntInfo.firstChildElement( QStringLiteral( 
"cntAddress" ) ).firstChildElement( QStringLiteral( 
"eMailAdd" ) ).text();
 
  418     contact.
voice = rpCntInfo.firstChildElement( QStringLiteral( 
"cntPhone" ) ).firstChildElement( QStringLiteral( 
"voiceNum" ) ).text();
 
  420     QDomElement cntAddress = rpCntInfo.firstChildElement( QStringLiteral( 
"cntAddress" ) );
 
  421     while ( !cntAddress.isNull() )
 
  425       address.
type = cntAddress.attribute( QStringLiteral( 
"addressType" ) );
 
  426       address.
address = cntAddress.firstChildElement( QStringLiteral( 
"delPoint" ) ).text();
 
  427       address.
city = cntAddress.firstChildElement( QStringLiteral( 
"city" ) ).text();
 
  428       address.
administrativeArea = cntAddress.firstChildElement( QStringLiteral( 
"adminArea" ) ).text();
 
  429       address.
postalCode = cntAddress.firstChildElement( QStringLiteral( 
"postCode" ) ).text();
 
  430       address.
country = cntAddress.firstChildElement( QStringLiteral( 
"country" ) ).text();
 
  434       cntAddress = cntAddress.nextSiblingElement( QStringLiteral( 
"cntAddress" ) );
 
  442   const QDomElement ptcontac = idInfo.firstChildElement( QStringLiteral( 
"ptcontac" ) );
 
  443   const QDomElement cntinfo = ptcontac.firstChildElement( QStringLiteral( 
"cntinfo" ) );
 
  444   if ( !cntinfo.isNull() )
 
  447     const QDomElement cntorgp = cntinfo.firstChildElement( QStringLiteral( 
"cntorgp" ) );
 
  448     const QString org = cntorgp.firstChildElement( QStringLiteral( 
"cntorg" ) ).text();
 
  452     contact.
role = QObject::tr( 
"Point of contact" );
 
  454     const QDomElement rpCntInfo = mdContact.firstChildElement( QStringLiteral( 
"rpCntInfo" ) );
 
  455     contact.
email = cntinfo.firstChildElement( QStringLiteral( 
"cntemail" ) ).text();
 
  456     contact.
fax = cntinfo.firstChildElement( QStringLiteral( 
"cntfax" ) ).text();
 
  457     contact.
voice = cntinfo.firstChildElement( QStringLiteral( 
"cntvoice" ) ).text();
 
  459     QDomElement cntaddr = cntinfo.firstChildElement( QStringLiteral( 
"cntaddr" ) );
 
  460     while ( !cntaddr.isNull() )
 
  464       QDomElement addressElem = cntaddr.firstChildElement( QStringLiteral( 
"address" ) );
 
  465       while ( !addressElem.isNull() )
 
  467         const QString addressPart = addressElem.text();
 
  469         addressElem = addressElem.nextSiblingElement( QStringLiteral( 
"address" ) );
 
  471       address.
type = cntaddr.firstChildElement( QStringLiteral( 
"addrtype" ) ).text();
 
  472       address.
city = cntaddr.firstChildElement( QStringLiteral( 
"city" ) ).text();
 
  473       address.
administrativeArea = cntaddr.firstChildElement( QStringLiteral( 
"state" ) ).text();
 
  474       address.
postalCode = cntaddr.firstChildElement( QStringLiteral( 
"postal" ) ).text();
 
  475       address.
country = cntaddr.firstChildElement( QStringLiteral( 
"country" ) ).text();
 
  479       cntaddr = cntaddr.nextSiblingElement( QStringLiteral( 
"cntaddr" ) );
 
A 3-dimensional box composed of x, y, z coordinates.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
const QgsCoordinateReferenceSystem & crs