28 const QDomElement metadataElem = document.firstChildElement( QStringLiteral(
"metadata" ) );
30 const QDomElement esri = metadataElem.firstChildElement( QStringLiteral(
"Esri" ) );
31 const QDomElement dataProperties = esri.firstChildElement( QStringLiteral(
"DataProperties" ) );
32 const QDomElement itemProps = dataProperties.firstChildElement( QStringLiteral(
"itemProps" ) );
33 metadata.
setIdentifier( itemProps.firstChildElement( QStringLiteral(
"itemName" ) ).text() );
35 const QDomElement dataIdInfo = metadataElem.firstChildElement( QStringLiteral(
"dataIdInfo" ) );
36 const QDomElement idInfo = metadataElem.firstChildElement( QStringLiteral(
"idinfo" ) );
39 const QDomElement idCitation = dataIdInfo.firstChildElement( QStringLiteral(
"idCitation" ) );
40 const QString title = idCitation.firstChildElement( QStringLiteral(
"resTitle" ) ).text();
44 if ( metadata.
identifier().isEmpty() && !title.isEmpty() )
47 const QDomElement citationDatesElement = idCitation.firstChildElement( QStringLiteral(
"date" ) ).toElement();
48 if ( !citationDatesElement.isNull() )
51 const QDomElement createDateElement = citationDatesElement.firstChildElement( QStringLiteral(
"createDate" ) ).toElement();
52 if ( !createDateElement.isNull() )
58 const QDomElement pubDateElement = citationDatesElement.firstChildElement( QStringLiteral(
"pubDate" ) ).toElement();
59 if ( !pubDateElement.isNull() )
65 const QDomElement reviseDateElement = citationDatesElement.firstChildElement( QStringLiteral(
"reviseDate" ) ).toElement();
66 if ( !reviseDateElement.isNull() )
72 const QDomElement supersededDateElement = citationDatesElement.firstChildElement( QStringLiteral(
"supersDate" ) ).toElement();
73 if ( !supersededDateElement.isNull() )
81 const QDomElement idAbs = dataIdInfo.firstChildElement( QStringLiteral(
"idAbs" ) );
82 const QString abstractPlainText = QTextDocumentFragment::fromHtml( idAbs.text() ).toPlainText();
86 const QDomElement idPurp = dataIdInfo.firstChildElement( QStringLiteral(
"idPurp" ) );
87 const QString purposePlainText = QTextDocumentFragment::fromHtml( idPurp.text() ).toPlainText();
88 if ( !metadata.
abstract().isEmpty() )
94 const QDomElement descript = idInfo.firstChildElement( QStringLiteral(
"descript" ) );
95 if ( !descript.isNull() )
97 const QDomElement abstract = descript.firstChildElement( QStringLiteral(
"abstract" ) );
98 const QString abstractPlainText = QTextDocumentFragment::fromHtml( abstract.text() ).toPlainText();
99 if ( !abstractPlainText.isEmpty() )
101 if ( !metadata.
abstract().isEmpty() )
102 metadata.
setAbstract( metadata.
abstract() + QStringLiteral(
"\n\n" ) + abstractPlainText );
107 const QDomElement purpose = descript.firstChildElement( QStringLiteral(
"purpose" ) );
108 const QString purposePlainText = QTextDocumentFragment::fromHtml( purpose.text() ).toPlainText();
109 if ( !purposePlainText.isEmpty() )
111 if ( !metadata.
abstract().isEmpty() )
117 const QDomElement supplinf = descript.firstChildElement( QStringLiteral(
"supplinf" ) );
118 const QString supplinfPlainText = QTextDocumentFragment::fromHtml( supplinf.text() ).toPlainText();
119 if ( !supplinfPlainText.isEmpty() )
121 if ( !metadata.
abstract().isEmpty() )
122 metadata.
setAbstract( metadata.
abstract() + QStringLiteral(
"\n\n" ) + supplinfPlainText );
129 const QDomElement suppInfo = dataIdInfo.firstChildElement( QStringLiteral(
"suppInfo" ) );
130 const QString suppInfoPlainText = QTextDocumentFragment::fromHtml( suppInfo.text() ).toPlainText();
131 if ( !suppInfoPlainText.isEmpty() )
133 if ( !metadata.
abstract().isEmpty() )
134 metadata.
setAbstract( metadata.
abstract() + QStringLiteral(
"\n\n" ) + suppInfoPlainText );
140 const QDomElement dataLang = dataIdInfo.firstChildElement( QStringLiteral(
"dataLang" ) );
141 const QDomElement languageCode = dataLang.firstChildElement( QStringLiteral(
"languageCode" ) );
142 const QString language = languageCode.attribute( QStringLiteral(
"value" ) ).toUpper();
146 QDomElement searchKeys = dataIdInfo.firstChildElement( QStringLiteral(
"searchKeys" ) );
147 QStringList keywords;
148 while ( !searchKeys.isNull() )
150 QDomElement keyword = searchKeys.firstChildElement( QStringLiteral(
"keyword" ) );
151 while ( !keyword.isNull() )
153 keywords << keyword.text();
154 keyword = keyword.nextSiblingElement( QStringLiteral(
"keyword" ) );
157 searchKeys = searchKeys.nextSiblingElement( QStringLiteral(
"searchKeys" ) );
161 QDomElement themeKeys = dataIdInfo.firstChildElement( QStringLiteral(
"themeKeys" ) );
162 QStringList categories;
163 while ( !themeKeys.isNull() )
165 const QDomElement thesaName = themeKeys.firstChildElement( QStringLiteral(
"thesaName" ) );
166 const QString thesaTitle = thesaName.firstChildElement( QStringLiteral(
"resTitle" ) ).text();
168 const bool isSearchKeyWord = thesaTitle.compare( QLatin1String(
"Common Search Terms" ), Qt::CaseInsensitive ) == 0;
170 QDomElement themeKeyword = themeKeys.firstChildElement( QStringLiteral(
"keyword" ) );
171 while ( !themeKeyword.isNull() )
173 if ( isSearchKeyWord )
175 keywords.append( themeKeyword.text().split(
',' ) );
179 categories << themeKeyword.text();
181 themeKeyword = themeKeyword.nextSiblingElement( QStringLiteral(
"keyword" ) );
183 themeKeys = themeKeys.nextSiblingElement( QStringLiteral(
"themeKeys" ) );
187 QDomElement keywordsElem = idInfo.firstChildElement( QStringLiteral(
"keywords" ) );
188 while ( !keywordsElem.isNull() )
190 QDomElement theme = keywordsElem.firstChildElement( QStringLiteral(
"theme" ) );
191 while ( !theme.isNull() )
193 categories << theme.firstChildElement( QStringLiteral(
"themekey" ) ).text();
194 theme = theme.nextSiblingElement( QStringLiteral(
"theme" ) );
197 keywordsElem = keywordsElem.nextSiblingElement( QStringLiteral(
"keywords" ) );
200 if ( !categories.isEmpty() )
203 if ( !keywords.empty() )
204 metadata.
addKeywords( QObject::tr(
"Search keys" ), keywords );
209 const QDomElement date = idCitation.firstChildElement( QStringLiteral(
"date" ) );
210 const QString pubDate = date.firstChildElement( QStringLiteral(
"pubDate" ) ).text();
211 const QDateTime publicationDate = QDateTime::fromString( pubDate, Qt::ISODate );
212 if ( publicationDate.isValid() )
219 QDomElement timeperd = idInfo.firstChildElement( QStringLiteral(
"timeperd" ) );
220 while ( !timeperd.isNull() )
222 if ( timeperd.firstChildElement( QStringLiteral(
"current" ) ).text().compare( QLatin1String(
"publication date" ) ) == 0 )
224 const QDomElement timeinfo = timeperd.firstChildElement( QStringLiteral(
"timeinfo" ) );
225 const QDomElement sngdate = timeinfo.firstChildElement( QStringLiteral(
"sngdate" ) );
226 if ( !sngdate.isNull() )
228 const QDomElement caldate = sngdate.firstChildElement( QStringLiteral(
"caldate" ) );
229 const QString caldateString = caldate.text();
230 const QDateTime publicationDate = QDateTime::fromString( caldateString, QStringLiteral(
"MMMM yyyy" ) );
231 if ( publicationDate.isValid() )
237 const QDomElement rngdates = timeinfo.firstChildElement( QStringLiteral(
"rngdates" ) );
238 if ( !rngdates.isNull() )
240 const QDomElement begdate = rngdates.firstChildElement( QStringLiteral(
"begdate" ) );
241 const QDomElement enddate = rngdates.firstChildElement( QStringLiteral(
"enddate" ) );
242 const QString begdateString = begdate.text();
243 const QString enddateString = enddate.text();
246 for (
const QString format : {
"yyyy-MM-dd",
"dd/MM/yyyy" } )
248 if ( !begin.isValid() )
249 begin = QDateTime::fromString( begdateString, format );
250 if ( !end.isValid() )
251 end = QDateTime::fromString( enddateString, format );
254 if ( begin.isValid() || end.isValid() )
262 timeperd = timeperd.nextSiblingElement( QStringLiteral(
"timeperd" ) );
268 QDomElement refSysInfo = metadataElem.firstChildElement( QStringLiteral(
"refSysInfo" ) );
269 while ( !refSysInfo.isNull() )
271 const QDomElement refSystem = refSysInfo.firstChildElement( QStringLiteral(
"RefSystem" ) );
272 const QDomElement refSysID = refSystem.firstChildElement( QStringLiteral(
"refSysID" ) );
273 const QDomElement identAuth = refSysID.firstChildElement( QStringLiteral(
"identAuth" ) );
274 if ( !identAuth.isNull() )
276 if ( identAuth.firstChildElement( QStringLiteral(
"resTitle" ) ).text().compare( QLatin1String(
"EPSG Geodetic Parameter Dataset" ) ) == 0 )
278 const QString code = refSysID.firstChildElement( QStringLiteral(
"identCode" ) ).attribute( QStringLiteral(
"code" ) );
284 const QString code = refSysID.firstChildElement( QStringLiteral(
"identCode" ) ).attribute( QStringLiteral(
"code" ) );
285 const QString auth = refSysID.firstChildElement( QStringLiteral(
"idCodeSpace" ) ).text();
294 refSysInfo = refSysInfo.nextSiblingElement( QStringLiteral(
"refSysInfo" ) );
298 QDomElement dataExt = dataIdInfo.firstChildElement( QStringLiteral(
"dataExt" ) );
299 while ( !dataExt.isNull() )
301 const QDomElement geoEle = dataExt.firstChildElement( QStringLiteral(
"geoEle" ) );
302 if ( !geoEle.isNull() )
304 const QDomElement geoBndBox = geoEle.firstChildElement( QStringLiteral(
"GeoBndBox" ) );
305 const double west = geoBndBox.firstChildElement( QStringLiteral(
"westBL" ) ).text().toDouble();
306 const double east = geoBndBox.firstChildElement( QStringLiteral(
"eastBL" ) ).text().toDouble();
307 const double south = geoBndBox.firstChildElement( QStringLiteral(
"northBL" ) ).text().toDouble();
308 const double north = geoBndBox.firstChildElement( QStringLiteral(
"southBL" ) ).text().toDouble();
312 spatialExtent.
bounds =
QgsBox3D( west, south, 0, east, north, 0 );
317 dataExt = dataExt.nextSiblingElement( QStringLiteral(
"dataExt" ) );
323 QStringList licenses;
326 QDomElement resConst = dataIdInfo.firstChildElement( QStringLiteral(
"resConst" ) );
327 while ( !resConst.isNull() )
329 QDomElement legConsts = resConst.firstChildElement( QStringLiteral(
"LegConsts" ) );
330 while ( !legConsts.isNull() )
332 const QString restrictCd = legConsts.firstChildElement( QStringLiteral(
"useConsts" ) ).firstChildElement( QStringLiteral(
"RestrictCd" ) ).attribute( QStringLiteral(
"value" ) );
334 if ( restrictCd.compare( QLatin1String(
"005" ) ) == 0 )
336 licenses << QTextDocumentFragment::fromHtml( legConsts.firstChildElement( QStringLiteral(
"useLimit" ) ).text() ).toPlainText();
338 else if ( restrictCd.compare( QLatin1String(
"006" ) ) == 0 )
340 rights << QTextDocumentFragment::fromHtml( legConsts.firstChildElement( QStringLiteral(
"useLimit" ) ).text() ).toPlainText();
342 legConsts = legConsts.nextSiblingElement( QStringLiteral(
"LegConsts" ) );
345 QDomElement secConsts = resConst.firstChildElement( QStringLiteral(
"SecConsts" ) );
346 while ( !secConsts.isNull() )
349 constraint.
type = QObject::tr(
"Security constraints" );
350 constraint.
constraint = QTextDocumentFragment::fromHtml( secConsts.firstChildElement( QStringLiteral(
"userNote" ) ).text() ).toPlainText();
351 constraints << constraint;
352 secConsts = secConsts.nextSiblingElement( QStringLiteral(
"SecConsts" ) );
355 QDomElement consts = resConst.firstChildElement( QStringLiteral(
"Consts" ) );
356 while ( !consts.isNull() )
359 constraint.
type = QObject::tr(
"Limitations of use" );
360 constraint.
constraint = QTextDocumentFragment::fromHtml( consts.firstChildElement( QStringLiteral(
"useLimit" ) ).text() ).toPlainText();
361 constraints << constraint;
362 consts = consts.nextSiblingElement( QStringLiteral(
"Consts" ) );
365 resConst = resConst.nextSiblingElement( QStringLiteral(
"resConst" ) );
368 const QDomElement idCredit = dataIdInfo.firstChildElement( QStringLiteral(
"idCredit" ) );
369 const QString credit = idCredit.text();
370 if ( !credit.isEmpty() )
374 QDomElement accconst = idInfo.firstChildElement( QStringLiteral(
"accconst" ) );
375 while ( !accconst.isNull() )
378 constraint.
type = QObject::tr(
"Access" );
379 constraint.
constraint = QTextDocumentFragment::fromHtml( accconst.text() ).toPlainText();
380 constraints << constraint;
382 accconst = accconst.nextSiblingElement( QStringLiteral(
"accconst" ) );
384 QDomElement useconst = idInfo.firstChildElement( QStringLiteral(
"useconst" ) );
385 while ( !useconst.isNull() )
387 rights << QTextDocumentFragment::fromHtml( useconst.text() ).toPlainText();
388 useconst = useconst.nextSiblingElement( QStringLiteral(
"useconst" ) );
396 const QDomElement distInfo = metadataElem.firstChildElement( QStringLiteral(
"distInfo" ) );
397 const QDomElement distributor = distInfo.firstChildElement( QStringLiteral(
"distributor" ) );
399 QDomElement distorTran = distributor.firstChildElement( QStringLiteral(
"distorTran" ) );
400 while ( !distorTran.isNull() )
402 const QDomElement onLineSrc = distorTran.firstChildElement( QStringLiteral(
"onLineSrc" ) );
403 if ( !onLineSrc.isNull() )
406 link.
url = onLineSrc.firstChildElement( QStringLiteral(
"linkage" ) ).text();
408 const QDomElement distorFormat = distributor.firstChildElement( QStringLiteral(
"distorFormat" ) );
409 link.
name = distorFormat.firstChildElement( QStringLiteral(
"formatName" ) ).text();
410 link.
type = distorFormat.firstChildElement( QStringLiteral(
"formatSpec" ) ).text();
412 if ( link.
type.isEmpty() )
415 link.
type = onLineSrc.firstChildElement( QStringLiteral(
"protocol" ) ).text();
420 distorTran = distorTran.nextSiblingElement( QStringLiteral(
"distorTran" ) );
424 const QDomElement dqInfo = metadataElem.firstChildElement( QStringLiteral(
"dqInfo" ) );
425 const QDomElement dataLineage = dqInfo.firstChildElement( QStringLiteral(
"dataLineage" ) );
426 const QString statement = QTextDocumentFragment::fromHtml( dataLineage.firstChildElement( QStringLiteral(
"statement" ) ).text() ).toPlainText();
427 if ( !statement.isEmpty() )
430 QDomElement dataSource = dataLineage.firstChildElement( QStringLiteral(
"dataSource" ) );
431 while ( !dataSource.isNull() )
433 metadata.
addHistoryItem( QObject::tr(
"Data source: %1" ).arg( QTextDocumentFragment::fromHtml( dataSource.firstChildElement( QStringLiteral(
"srcDesc" ) ).text() ).toPlainText() ) );
434 dataSource = dataSource.nextSiblingElement( QStringLiteral(
"dataSource" ) );
438 const QDomElement mdContact = metadataElem.firstChildElement( QStringLiteral(
"mdContact" ) );
439 if ( !mdContact.isNull() )
442 contact.
name = mdContact.firstChildElement( QStringLiteral(
"rpIndName" ) ).text();
443 contact.
organization = mdContact.firstChildElement( QStringLiteral(
"rpOrgName" ) ).text();
444 contact.
position = mdContact.firstChildElement( QStringLiteral(
"rpPosName" ) ).text();
446 const QString role = mdContact.firstChildElement( QStringLiteral(
"role" ) ).firstChildElement( QStringLiteral(
"RoleCd" ) ).attribute( QStringLiteral(
"value" ) );
447 if ( role == QLatin1String(
"007" ) )
448 contact.
role = QObject::tr(
"Point of contact" );
450 const QDomElement rpCntInfo = mdContact.firstChildElement( QStringLiteral(
"rpCntInfo" ) );
451 contact.
email = rpCntInfo.firstChildElement( QStringLiteral(
"cntAddress" ) ).firstChildElement( QStringLiteral(
"eMailAdd" ) ).text();
452 contact.
voice = rpCntInfo.firstChildElement( QStringLiteral(
"cntPhone" ) ).firstChildElement( QStringLiteral(
"voiceNum" ) ).text();
454 QDomElement cntAddress = rpCntInfo.firstChildElement( QStringLiteral(
"cntAddress" ) );
455 while ( !cntAddress.isNull() )
459 address.
type = cntAddress.attribute( QStringLiteral(
"addressType" ) );
460 address.
address = cntAddress.firstChildElement( QStringLiteral(
"delPoint" ) ).text();
461 address.
city = cntAddress.firstChildElement( QStringLiteral(
"city" ) ).text();
462 address.
administrativeArea = cntAddress.firstChildElement( QStringLiteral(
"adminArea" ) ).text();
463 address.
postalCode = cntAddress.firstChildElement( QStringLiteral(
"postCode" ) ).text();
464 address.
country = cntAddress.firstChildElement( QStringLiteral(
"country" ) ).text();
468 cntAddress = cntAddress.nextSiblingElement( QStringLiteral(
"cntAddress" ) );
476 const QDomElement ptcontac = idInfo.firstChildElement( QStringLiteral(
"ptcontac" ) );
477 const QDomElement cntinfo = ptcontac.firstChildElement( QStringLiteral(
"cntinfo" ) );
478 if ( !cntinfo.isNull() )
481 const QDomElement cntorgp = cntinfo.firstChildElement( QStringLiteral(
"cntorgp" ) );
482 const QString org = cntorgp.firstChildElement( QStringLiteral(
"cntorg" ) ).text();
486 contact.
role = QObject::tr(
"Point of contact" );
488 const QDomElement rpCntInfo = mdContact.firstChildElement( QStringLiteral(
"rpCntInfo" ) );
489 contact.
email = cntinfo.firstChildElement( QStringLiteral(
"cntemail" ) ).text();
490 contact.
fax = cntinfo.firstChildElement( QStringLiteral(
"cntfax" ) ).text();
491 contact.
voice = cntinfo.firstChildElement( QStringLiteral(
"cntvoice" ) ).text();
493 QDomElement cntaddr = cntinfo.firstChildElement( QStringLiteral(
"cntaddr" ) );
494 while ( !cntaddr.isNull() )
498 QDomElement addressElem = cntaddr.firstChildElement( QStringLiteral(
"address" ) );
499 while ( !addressElem.isNull() )
501 const QString addressPart = addressElem.text();
503 addressElem = addressElem.nextSiblingElement( QStringLiteral(
"address" ) );
505 address.
type = cntaddr.firstChildElement( QStringLiteral(
"addrtype" ) ).text();
506 address.
city = cntaddr.firstChildElement( QStringLiteral(
"city" ) ).text();
507 address.
administrativeArea = cntaddr.firstChildElement( QStringLiteral(
"state" ) ).text();
508 address.
postalCode = cntaddr.firstChildElement( QStringLiteral(
"postal" ) ).text();
509 address.
country = cntaddr.firstChildElement( QStringLiteral(
"country" ) ).text();
513 cntaddr = cntaddr.nextSiblingElement( QStringLiteral(
"cntaddr" ) );