Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Add an extended Capabilites section into a 1.3.0 WMS GetCapabilites response to fulfil INSPIRE requirements
- This script was tested using MapServer 5.6.6. It should also work with the upcoming 6.0 release.
- */
- /*load map*/
- /* Substitute the full path to your map file BELOW */
- $oMap = ms_newMapobj(".../BGS_Bedrock_and_Surface_Geology/onegeology.map");
- /*initialise request object and parse request*/
- $request = ms_newowsrequestobj();
- $request->loadparams();
- ms_ioinstallstdouttobuffer();
- /*get response from mapserver*/
- $oMap->owsdispatch($request);
- $contenttype = ms_iostripstdoutbuffercontenttype();
- header('Content-type:' . $contenttype);
- $operation = $request->getValueByName('Request');
- $version = $request->getValueByName('VERSION');
- /*insert inspire pieces only for version 1.30*/
- if ((strcasecmp($version,'1.3.0') ==0 || $version == "") && strcasecmp($operation,'GetCapabilities') == 0)
- {
- $content = ms_iogetstdoutbufferstring();
- $content = altercapabilities($content);
- echo $content;
- }
- else
- ms_iogetStdoutBufferBytes();
- ms_ioresethandlers();
- /************************************************************************/
- /* altercapabilities */
- /* */
- /* Utility function to add the minimum requirement parts into */
- /* a capabilities document. */
- /************************************************************************/
- function altercapabilities($capabilities_xml)
- {
- $doc = new DOMDocument();
- $doc->loadXML($capabilities_xml);
- $root = $doc->documentElement;
- /* ==================================================================== */
- /* add inspire name space and schema locations */
- /* ==================================================================== */
- $doc->createAttributeNS('http://inspire.ec.europa.eu/schemas/common/1.0' ,'inspire_common:inspire_common');
- $doc->createAttributeNS('http://inspire.ec.europa.eu/schemas/inspire_vs/1.0' ,'inspire_vs:inspire_vs');
- $root = $doc->documentElement;
- $attrs = $root->attributes;
- /*use array of attributes. getAttributeNS does not seem to return the value*/
- //$schema_value = $root->getAttribute('schemaLocation');
- foreach ($attrs as $i => $attr)
- {
- if (strstr($attr->name, 'schemaLocation'))
- {
- $new_value = $attr->value . " http://inspire.ec.europa.eu/schemas/inspire_vs/1.0 http://inspire.ec.europa.eu/schemas/inspire_vs/1.0/inspire_vs.xsd";
- $root->setAttribute('xsi:schemaLocation', $new_value);
- break;
- }
- }
- /* ==================================================================== */
- /* add the extend capabilities before the Layer element. */
- /* ==================================================================== */
- $capability_node = $doc->getElementsByTagName('Capability')->item(0);
- $layer_node = $capability_node->getElementsByTagName('Layer')->item(0);
- /*
- //minimum requirement
- //a 'scenario 1' response for a service that supports only one language.
- //ref: Technical Guidance for the implementation of INSPIRE View Services v3.0
- <inspire_vs:ExtendedCapabilities>
- <inspire_common:MetadataUrl xsi:type="inspire_common:resourceLocatorType"> <inspire_common:URL>http://ogcdev.bgs.ac.uk/geonetwork/srv/en/csw?SERVICE=CSW&REQUEST=GetRecordById&ID=7822e848-822d-45a5-8584-56d352fd2170&elementSetName=full&OutputSchema=http://www.isotc211.org/2005/gmd&</inspire_common:URL>
- <inspire_common:MediaType>application/vnd.iso.19139+xml</inspire_common:MediaType>
- </inspire_common:MetadataUrl>
- <inspire_common:SupportedLanguages>
- <inspire_common:DefaultLanguage>
- <inspire_common:Language>eng</inspire_common:Language>
- </inspire_common:DefaultLanguage>
- </inspire_common:SupportedLanguages>
- <inspire_com:ResponseLanguage>
- <inspire_com:Language>eng</inspire_com:Language>
- </inspire_com:ResponseLanguage>
- </inspire_vs:ExtendedCapabilities>
- */
- $element = $doc->createElement('inspire_vs:ExtendedCapabilities');
- $extend_root =$capability_node->insertBefore($element, $layer_node);
- $metadata_url = $doc->createElement('inspire_common:MetadataUrl');
- $node_added = $extend_root->appendChild($metadata_url);
- $md_attribute = $doc->createAttribute('xsi:type');
- $metadata_url->appendChild($md_attribute);
- $md_att_text = $doc->createTextNode('inspire_common:resourceLocatorType');
- $md_attribute->appendChild($md_att_text);
- $new_node = $doc->createElement('inspire_common:URL');
- $node_tmp = $node_added->appendChild($new_node);
- $node_tmp->appendChild($doc->createTextNode('http://ogcdev.bgs.ac.uk/geonetwork/srv/en/csw?SERVICE=CSW&REQUEST=GetRecordById&ID=a0a82d76-657c-2a78-e044-0003ba9b0d98&elementSetName=full&OutputSchema=http://www.isotc211.org/2005/gmd&'));
- $new_node = $doc->createElement('inspire_common:MediaType');
- $node_tmp = $node_added->appendChild($new_node);
- $node_tmp->appendChild($doc->createTextNode('application/vnd.iso.19139+xml'));
- $supp_lan = $doc->createElement('inspire_common:SupportedLanguages');
- $node_added = $extend_root->appendChild( $supp_lan);
- $def_lan = $doc->createElement('inspire_common:DefaultLanguage');
- $node_tmp = $node_added->appendChild($def_lan);
- $new_node = $doc->createElement('inspire_common:Language');
- $node_tmp = $def_lan->appendChild($new_node);
- $node_tmp->appendChild($doc->createTextNode('eng'));
- $response_lan = $doc->createElement('inspire_common:ResponseLanguage');
- $node_added = $extend_root->appendChild( $response_lan);
- $new_node = $doc->createElement('inspire_common:Language');
- $node_tmp = $node_added->appendChild($new_node);
- $node_tmp->appendChild($doc->createTextNode('eng'));
- return $doc->saveXML();
- }
- ?>
Add Comment
Please, Sign In to add comment