3

I want to create a wrapper for my server. (I use mapserver and apache on windows server)

In this document ( http://mapserver.org/cgi/wrapper.html ) refer to suggestions:

1st :

#!/bin/sh
MAPSERV="/path/to/my/mapserv"
MS_MAPFILE="/path/to/my/mapfile.map" exec ${MAPSERV}

2nd :

#!/bin/sh
MAPSERV="/path/to/my/mapserv"
MAPFILE="/path/to/my/mapfile.map"
if [ "${REQUEST_METHOD}" = "GET" ]; then
  if [ -z "${QUERY_STRING}" ]; then
    QUERY_STRING="map=${MAPFILE}"
  else
    QUERY_STRING="map=${MAPFILE}&${QUERY_STRING}"
  fi
  exec ${MAPSERV}
else
  echo "Sorry, I only understand GET requests."
fi
exit 1
# End of Script

1. Are that run on windows server?

2. in that document say : "Put the script in your web server’s cgi-bin directory, and make it executable". what is the name and extension of saved script ?

also in MapServer WMS Document in url "http://mapserver.org/ogc/wfs_server.html" refer to some suggestions :

  • Apache ReWrite rules (using Apache mod_rewrite)
  • Apache environment variables - MS_MAPFILE
  • Apache SetEnvIf
  • ASP script (IIS - Microsoft Windows)
  • Mapscript wrapper
  • Wrapper script (Unix)

3. Which is best suggestion? why? What are the advantages of each?

4. "1st suggestion" and "Apache mod_rewrite" are seems easy and good Enough. Is not it?

1
  • I would love to get a reply for this. Can we make an auto ip changer out of this? Thanks.
    – user30018
    Nov 7, 2014 at 13:18

1 Answer 1

1

I wrote some php mapscript a while ago to inject a some custom information into my WMS GetCapabilities response ~ adding an extended capabilities section to make an INSPIRE compliant service, prior to that functionality becoming available natively in MapServer 6.2.

The starting point was a MapServer for Windows (MS4W) installation with an endpoint of for example:

http://your-server-name/cgi-bin/BGS_Bedrock_and_Superficial_Geology/wms?

and an unadulterated GetCapabilities response like:

http://your-server-name/cgi-bin/BGS_Bedrock_and_Superficial_Geology/wms?service=WMS&request=GetCapabilities&

Take a look at the OneGeology cookbook if you want to see how to set up such a service Step-by-step configuration for MS4W.

Now with my service working (so knowing my map file had no errors) I take my php file (let's call it wms.php) like below and put it in a file location that allows php to run.

<?php

/*load map*/
$oMap = ms_newMapobj("D:/path/to/the/map-file/onegeology.map");s/

/*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.3.0*/
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://metadata.bgs.ac.uk/geonetwork/srv/en/csw?SERVICE=CSW&REQUEST=GetRecordById&ID=7822e848-822d-45a5-8584-56d352fd2170&elementSetName=full&OutputSchema=csw:IsoRecord&</inspire_common:URL>
                <inspire_common:MediaType>application/xml;charset=UTF-8</inspire_common:MediaType>
                //<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://metadata.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/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();
}                                           
?>

Now we can call the service using this php file like:

http://your-server-name/BGS_Bedrock_and_Superficial_Geology/wms.php?service=WMS&request=GetCapabilities&

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.