nmtoken

INSPIRE scenario 1 extended capabilities with PHP MapScript

Apr 14th, 2011
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.15 KB | None | 0 0
  1. <?php
  2.   /*
  3.     Add an extended Capabilites section into a 1.3.0 WMS GetCapabilites response to fulfil INSPIRE requirements
  4.     This script was tested using MapServer 5.6.6. It should also work with the upcoming 6.0 release.
  5.    */
  6.  
  7. /*load map*/
  8. /* Substitute the full path to your map file BELOW */
  9. $oMap = ms_newMapobj(".../BGS_Bedrock_and_Surface_Geology/onegeology.map");
  10.  
  11. /*initialise request object and parse request*/
  12. $request = ms_newowsrequestobj();
  13. $request->loadparams();
  14. ms_ioinstallstdouttobuffer();
  15.  
  16. /*get response from mapserver*/
  17. $oMap->owsdispatch($request);
  18. $contenttype = ms_iostripstdoutbuffercontenttype();
  19.  
  20. header('Content-type:' . $contenttype);
  21.  
  22. $operation = $request->getValueByName('Request');
  23. $version = $request->getValueByName('VERSION');
  24.  
  25. /*insert inspire pieces only for version 1.30*/
  26. if ((strcasecmp($version,'1.3.0') ==0 || $version == "") && strcasecmp($operation,'GetCapabilities') == 0)
  27. {
  28.     $content = ms_iogetstdoutbufferstring();
  29.     $content = altercapabilities($content);
  30.     echo $content;
  31. }
  32. else
  33.   ms_iogetStdoutBufferBytes();
  34.  
  35. ms_ioresethandlers();
  36.  
  37. /************************************************************************/
  38. /*                            altercapabilities                         */
  39. /*                                                                      */
  40. /*      Utility function to add the minimum requirement parts into      */
  41. /*      a capabilities document.                                        */
  42. /************************************************************************/
  43. function altercapabilities($capabilities_xml)
  44. {
  45.     $doc = new DOMDocument();
  46.     $doc->loadXML($capabilities_xml);
  47.     $root = $doc->documentElement;
  48.  
  49. /* ==================================================================== */
  50. /*      add inspire name space and schema locations                     */
  51. /* ==================================================================== */
  52.     $doc->createAttributeNS('http://inspire.ec.europa.eu/schemas/common/1.0' ,'inspire_common:inspire_common');
  53.     $doc->createAttributeNS('http://inspire.ec.europa.eu/schemas/inspire_vs/1.0' ,'inspire_vs:inspire_vs');
  54.     $root = $doc->documentElement;
  55.     $attrs = $root->attributes;
  56.  
  57.     /*use array of attributes. getAttributeNS does not seem to return the value*/
  58.     //$schema_value = $root->getAttribute('schemaLocation');
  59.     foreach ($attrs as $i => $attr)
  60.     {
  61.         if (strstr($attr->name, 'schemaLocation'))
  62.         {      
  63.             $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";
  64.             $root->setAttribute('xsi:schemaLocation',  $new_value);
  65.             break;
  66.         }
  67.     }
  68. /* ==================================================================== */
  69. /*      add the extend capabilities before the Layer element.           */
  70. /* ==================================================================== */
  71.     $capability_node = $doc->getElementsByTagName('Capability')->item(0);
  72.     $layer_node = $capability_node->getElementsByTagName('Layer')->item(0);
  73.     /*
  74.     //minimum requirement
  75.     //a 'scenario 1' response for a service that supports only one language.
  76.     //ref: Technical Guidance for the implementation of INSPIRE View Services v3.0
  77.         <inspire_vs:ExtendedCapabilities>
  78.             <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>
  79.                 <inspire_common:MediaType>application/vnd.iso.19139+xml</inspire_common:MediaType>
  80.             </inspire_common:MetadataUrl>
  81.             <inspire_common:SupportedLanguages>
  82.                 <inspire_common:DefaultLanguage>
  83.                     <inspire_common:Language>eng</inspire_common:Language>
  84.                 </inspire_common:DefaultLanguage>
  85.             </inspire_common:SupportedLanguages>
  86.             <inspire_com:ResponseLanguage>
  87.                 <inspire_com:Language>eng</inspire_com:Language>
  88.             </inspire_com:ResponseLanguage>
  89.         </inspire_vs:ExtendedCapabilities>
  90.      */
  91.  
  92.     $element = $doc->createElement('inspire_vs:ExtendedCapabilities');
  93.     $extend_root =$capability_node->insertBefore($element,  $layer_node);
  94.    
  95.     $metadata_url = $doc->createElement('inspire_common:MetadataUrl');
  96.     $node_added = $extend_root->appendChild($metadata_url);
  97.    
  98.     $md_attribute = $doc->createAttribute('xsi:type');
  99.     $metadata_url->appendChild($md_attribute);
  100.     $md_att_text = $doc->createTextNode('inspire_common:resourceLocatorType');
  101.     $md_attribute->appendChild($md_att_text);
  102.    
  103.     $new_node = $doc->createElement('inspire_common:URL');
  104.     $node_tmp = $node_added->appendChild($new_node);
  105.     $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&'));
  106.     $new_node = $doc->createElement('inspire_common:MediaType');
  107.     $node_tmp = $node_added->appendChild($new_node);
  108.     $node_tmp->appendChild($doc->createTextNode('application/vnd.iso.19139+xml'));
  109.  
  110.     $supp_lan = $doc->createElement('inspire_common:SupportedLanguages');
  111.     $node_added = $extend_root->appendChild( $supp_lan);
  112.     $def_lan = $doc->createElement('inspire_common:DefaultLanguage');
  113.     $node_tmp = $node_added->appendChild($def_lan);
  114.     $new_node = $doc->createElement('inspire_common:Language');
  115.     $node_tmp = $def_lan->appendChild($new_node);    
  116.     $node_tmp->appendChild($doc->createTextNode('eng'));
  117.  
  118.     $response_lan = $doc->createElement('inspire_common:ResponseLanguage');
  119.     $node_added = $extend_root->appendChild( $response_lan);
  120.     $new_node = $doc->createElement('inspire_common:Language');
  121.     $node_tmp = $node_added->appendChild($new_node);
  122.     $node_tmp->appendChild($doc->createTextNode('eng'));  
  123.  
  124.     return $doc->saveXML();
  125. }                                          
  126. ?>
Add Comment
Please, Sign In to add comment