westdc-zf1/application/models/ISO19115.php

413 lines
16 KiB
PHP
Raw Normal View History

2009-03-06 03:20:46 +00:00
<?php
class MD_Resolution
{
public $equScale;
public $scaleDist;
}
class MD_Keywords
{
public $keyword;
public $keyTyp;
public $thesaName;
}
class MD_BrowseGraphic
{
public $bgFileName;
public $bgFileDesc;
public $bgFileType;
}
class MD_Identification
{
public $idCitation;
public $idAbs;
public $idPurp;
public $idCredit;
public $idStatus;
public $idPoc;
public $resMaint;
public $graphOver;
public $dsFormat;
public $descKeys;
public $idSpecUse;
public $resConst;
public $aggrInfo;
public $spatRpType;
public $dataScale;
public $dataLang;
public $dataChar;
public $tpCat;
public $envirDesc;
public $dataExt;
public $suppInfo;
public $SerIdent;
}
class MD_Metadata
{
public $mdFileID;//string
public $mdLang;//conditional, string
public $mdChar; //conditional, class
public $mdParentID;//string
public $mdHrLv;//class array
public $mdHrLvName;//string array
public $mdContact;//class array
public $mdDateSt;//class,数据创建时间
public $mdStanName;//string
public $mdStanVer;//string
public $dataSetUri;//string
public $spatRepInfo;//array association
public $refSysInfo;//array..
public $mdExtInfo;//array..
public $dtaIdInfo;//array...MD_Identification
public $contInfo; //array ..
public $distInfo;//association
public $dqInfo;//array ..
public $porCatInfo;//array..
public $mdConst;//array..
public $appSchInfo;//array..
public $mdMaint;//association
}
/**
* 采用DOM实现需要PHP5
**/
class ISO19115
{
public $mdFileID;
public $mdLang;
public $mdChar;
public $mdDateSt;
public $mdStanName='ISO 19115';
public $mdStanVer='19115:2003';
public $mdContact;
public $uuid;
/**
* 数据集标题
* 字符串
**/
public $resTitle;
public $resAltTitle;
/**
* 数据集简介
**/
public $idAbs;
public $dataSetURI;
public $bgFileName;
/**
* 数据集序列信息
* 数组
**/
public $datasetSeries;//array
/**
* 类别代码,数组
* 注意在geonetwork中的不是代码而是直接的类别值
**/
public $tpCat;
/**
* 时间信息start & end
* 注意geonetwork中和国家元数据标准的代码不同
* ISO 19115中好像没有看到相关信息
**/
public $timebegin;
public $timeend;
/**
* 空间信息
* 数组形式['w'],s,e,n
**/
public $geoBox;
public $thumbnail;
public $graph;
public $keyword;
private $dom;
public $keytypecode=array(1=>'discipline','place','stratum','temporal','theme');
public $author;
2009-03-06 03:20:46 +00:00
function __construct()
{
$this->dom = new DOMDocument();
}
/**
* 从文件中读取元数据
**/
function load($file)
{
$this->dom->load($file);
$this->parse();
}
/**
* 从字符串中读取元数据
*/
function loadXML($str)
{
$this->dom->loadXML($str);
$this->parse();
}
/**
* 保存元数据到文件file中
*/
function save($file)
{
return $this->dom->save($file);
}
/**
* 根据xml中的node保存为xml
**/
function saveXML($node="")
{
return $this->dom->saveXML($node);
}
/**
* 根据UUID从数据库中提取元数据信息不需要进行parse()操作
**/
function loadUUID($uuid)
{
}
function saveDB()
{
}
function parse()
{
$this->resTitle=$this->dom->getElementsByTagName('resTitle')->item(0)->nodeValue;
$this->idAbs=$this->dom->getElementsByTagName('idAbs')->item(0)->nodeValue;
$this->mdFileID=$this->dom->getElementsByTagName('mdFileID')->item(0)->nodeValue;
$this->mdDateSt=$this->dom->getElementsByTagName('mdDateSt')->item(0)->nodeValue;
@$this->dataSetURI=$this->dom->getElementsByTagName('dataSetURI')->item(0)->nodeValue;
//引用说明
@$this->citation=$this->dom->getElementsByTagName('otherCitDet')->item(0)->nodeValue;
//数据大小以MB为单位
@$this->filesize=$this->dom->getElementsByTagName('transSize')->item(0)->nodeValue;
//数据格式,可以多个,但此处只用一个?
@$this->fileformat=$this->dom->getElementsByTagName('formatName')->item(0)->nodeValue;
//投影类型,可以多个,但只选一个
@$this->projection=$this->dom->getElementsByTagName('identCode')->item(0)->nodeValue;
//数据作者
$authors=$this->dom->getElementsByTagName('citRespParty');
$cnt=count($authors);
foreach($authors as $k=>$author)
{
$this->author[$k]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
$this->author[$k]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
$this->author[$k]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
$this->author[$k]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
$this->author[$k]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
$this->author[$k]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
$this->author[$k]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
$this->author[$k]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
$this->author[$k]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
$this->author[$k]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
$this->author[$k]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
}
$authors=$this->dom->getElementsByTagName('mdContact');
$cnt+=count($authors);
foreach($authors as $j=>$author)
{
$this->author[$cnt+$j+1]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
$this->author[$cnt+$j+1]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
}
$authors=$this->dom->getElementsByTagName('distorCont');
$cnt+=count($authors);
foreach($authors as $m=>$author)
{
$this->author[$cnt+$m+2]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
$this->author[$cnt+$m+2]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
}
/*
2009-03-06 03:20:46 +00:00
foreach($authors as $author)
{
if($author->getElementsByTagName('rpIndName')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0)->hasAttributes() &&
$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue=="author")
{
$this->author=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
break;
}elseif ($author->getElementsByTagName('rpIndName')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0)->hasAttributes() &&
$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue=="originator" )
{
$this->author=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
break;
}elseif ($author->getElementsByTagName('rpIndName')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0)->hasAttributes() &&
$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue=="owner" )
{
$this->author=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
break;
}elseif ($author->getElementsByTagName('rpIndName')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0)->hasAttributes() &&
$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue=="processor" )
{
$this->author=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
break;
}elseif ($author->getElementsByTagName('rpIndName')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0)->hasAttributes() &&
$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue=="publisher" )
{
$this->author=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
break;
}elseif ($author->getElementsByTagName('rpIndName')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0) &&
$author->getElementsByTagName('RoleCd')->item(0)->hasAttributes() &&
$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue=="resourceProvider" )
{
$this->author=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
break;
}
}
*/
2009-03-06 03:20:46 +00:00
//数据类型,在线或离线
$this->datatype=0;
$onlinesrc=$this->dom->getElementsByTagName('onLineSrc');
foreach($onlinesrc as $k=>$src)
{
if ($src->getElementsByTagName('OnFunctCd')->item(0)
&& $src->getElementsByTagName('OnFunctCd')->item(0)->hasAttributes()
&& $src->getElementsByTagName('OnFunctCd')->item(0)->attributes->getNamedItem('value')->nodeValue=="offlineAccess")
$this->datatype=1;
else {
//在线资源
$this->onlineresource[$k]['linkage']=$src->getElementsByTagName('linkage')->item(0)->nodeValue;
if ($src->getElementsByTagName('protocol')->item(0)) $this->onlineresource[$k]['protocol']=$src->getElementsByTagName('protocol')->item(0)->nodeValue;
if ($src->getElementsByTagName('orName')->item(0)) $this->onlineresource[$k]['name']=$src->getElementsByTagName('orName')->item(0)->nodeValue;
$this->onlineresource[$k]['description']=$src->getElementsByTagName('orDesc')->item(0)->nodeValue;
}
}
$cats=$this->dom->getElementsByTagName('tpCat');
foreach($cats as $cat)
{
if ($cat->getElementsByTagName('TopicCatCd')->item(0)->hasAttributes())
$this->tpCat[]=$cat->getElementsByTagName('TopicCatCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
}
@$this->bgFileName=$this->dom->getElementsByTagName('bgFileName')->item(0)->nodeValue;
$keywords=$this->dom->getElementsByTagName('descKeys');//Keywords? which one?
foreach($keywords as $keys)
{
if ($keys->getElementsByTagName('KeyTypCd')->item(0) && $keys->getElementsByTagName('KeyTypCd')->item(0)->hasAttributes())
$k=$keys->getElementsByTagName('KeyTypCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
if (is_numeric($k))
$kt=$this->keytypecode[(int)$k];
else
$kt=$k;
//如果没有找到类别,则默认为主题关键词
if (!$kt) $kt=$this->keytypecode[5];
$ks=$keys->getElementsByTagName('keyword');
foreach($ks as $key)
{
//处理特殊情况:多关键词输入在一起,用一些符号来分割,如分号等。
$pos=strpos($key->nodeValue,';');
if ($pos===false)
$this->keyword[$kt][]=$key->nodeValue;
else {
$str=explode(';',$key->nodeValue);
foreach($str as $s){
$this->keyword[$kt][]=$s;
}
}
}
}
//in ISO 19115 draft.
2009-12-17 14:08:14 +00:00
$ds=$this->dom->getElementsByTagName('datasetSeries');
2009-03-06 03:20:46 +00:00
foreach($ds as $k=>$dataset)
{
$this->datasetSeries[$k]['seriesName']=$dataset->getElementsByTagName('seriesName')->item(0)->nodeValue;
$this->datasetSeries[$k]['issId']=$dataset->getElementsByTagName('issId')->item(0)->nodeValue;
$this->datasetSeries[$k]['artPage']=$dataset->getElementsByTagName('artPage')->item(0)->nodeValue;
}
//unsure which one.
$ds=$this->dom->getElementsByTagName('Series');
foreach($ds as $k=>$dataset)
{
$this->datasetSeries[$k]['seriesName']=$dataset->getElementsByTagName('Name')->item(0)->nodeValue;
$this->datasetSeries[$k]['issId']=$dataset->getElementsByTagName('issId')->item(0)->nodeValue;
$this->datasetSeries[$k]['artPage']=$dataset->getElementsByTagName('artPage')->item(0)->nodeValue;
}
//可能只适用于ESRI ARCCATELOG产生的元数据
$extent=$this->dom->getElementsByTagName('geoBox');
foreach($extent as $geo)
{
$this->geoBox['w']=$geo->getElementsByTagName('westBL')->item(0)->nodeValue;
$this->geoBox['s']=$geo->getElementsByTagName('southBL')->item(0)->nodeValue;
$this->geoBox['e']=$geo->getElementsByTagName('eastBL')->item(0)->nodeValue;
$this->geoBox['n']=$geo->getElementsByTagName('northBL')->item(0)->nodeValue;
}
//提取ESRI格式中的UUID
if (empty($this->uuid))
{
@$this->uuid=$this->dom->getElementsByTagName('MetaID')->item(0)->nodeValue;
//剔除前后大括号
$this->uuid=trim($this->uuid,'{');
$this->uuid=trim($this->uuid,'}');
}
//根据mdFileID来判断uuid
//如果mdFileID为uuid的组织形式则进行提取
if (strlen($this->mdFileID)==36 && empty($this->uuid))
$this->uuid=$this->mdFileID;
//仍然没有UUID信息则创建一个
if (empty($this->uuid))
{
$this->uuid=new uuid();
$this->uuid=$this->uuid->toString();
//反馈回XML文件
$mdfile=$this->dom->getElementsByTagName('mdFileID');
if ($mdfile->length>0) {
$this->dom->getElementsByTagName('mdFileID')->item(0)->nodeValue=$this->uuid;
} else {
$mdfile=$this->dom->createElement('mdFileID', $this->uuid);
$this->dom->getElementsByTagName('Metadata')->item(0)->appendChild($mdfile);
}
}
//提取时间信息
$tm_period=$this->dom->getElementsByTagName('TM_Period');
foreach($tm_period as $period)
{
$this->timebegin=$period->getElementsByTagName('begin')->item(0)->nodeValue;
$this->timeend=$period->getElementsByTagName('end')->item(0)->nodeValue;
}
//Todo:处理缩略图,限制为一个。
//$thumb=$this->dom->getElementsByTagName('Thumbnail');
$xpath = new DOMXPath($this->dom);
$query = '//metadata/Binary/Thumbnail/Data';//should be Metadata
$entries = $xpath->query($query);
if ($entries->length>0)
$this->thumbnail=$entries->item(0)->nodeValue;
else {
$query='//Metadata/Binary/Thumbnail/Data';
$entries=$xpath->query($query);
@$this->thumbnail=$entries->item(0)->nodeValue;
}
//如果是从GEONETWORK获取判断是否已有缩略图获取最小的缩略图
$graphs=$this->dom->getElementsByTagName('graphOver');
foreach ($graphs as $g)
{
if ($g->getElementsByTagName('bgFileDesc')->item(0)->nodeValue=='thumbnail') {
$this->graph['filename']=$g->getElementsByTagName('bgFileName')->item(0)->nodeValue;
$this->graph['filedesc']='thumbnail';
$this->graph['filetype']=$g->getElementsByTagName('bgFileType')->item(0)->nodeValue;
}
}
}
}
?>