435 lines
17 KiB
PHP
Executable File
435 lines
17 KiB
PHP
Executable File
<?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;
|
||
|
||
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->resAltTitle=$this->dom->getElementsByTagName('resAltTitle')->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;
|
||
//数据限制信息
|
||
$limits=$this->dom->getElementsByTagName('useLimit');
|
||
foreach($limits as $limit)
|
||
{
|
||
$this->limits[]=$limit->nodeValue;
|
||
}
|
||
//数据作者
|
||
$authors=$this->dom->getElementsByTagName('citRespParty');
|
||
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;
|
||
}
|
||
$cnt=$k+1;
|
||
$authors=$this->dom->getElementsByTagName('mdContact');
|
||
foreach($authors as $j=>$author)
|
||
{
|
||
$this->author[$cnt+$j]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
|
||
$this->author[$cnt+$j]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
|
||
}
|
||
$cnt+=$j+1;
|
||
$authors=$this->dom->getElementsByTagName('distorCont');
|
||
foreach($authors as $m=>$author)
|
||
{
|
||
$this->author[$cnt+$m]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
|
||
}
|
||
$cnt+=$m+1;
|
||
$authors=$this->dom->getElementsByTagName('idPoC');
|
||
foreach($authors as $m=>$author)
|
||
{
|
||
$this->author[$cnt+$m]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
|
||
$this->author[$cnt+$m]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
|
||
}
|
||
/*
|
||
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;
|
||
}
|
||
}
|
||
*/
|
||
//数据类型,在线或离线
|
||
$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.
|
||
$ds=$this->dom->getElementsByTagName('datasetSeries');
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
?>
|