Jesus Loves GRASS

Technical blog about GRASS/GIS,open source geoinformatics and MAPSERVER.

Friday, April 20, 2007

OWS_request

The Legend is static and is drawn at the start up so I couldn't make a link in the download icon making a specific WxS request.

The solution was a javascript function that is called when the icon is pressed. This function will get the service and the name of the layer, later it will request adicional information (getDescription) so that a proper WxC can be performed.

After getting all the information the functions opens a window and calls a PHP file (passing by GET all the information for the WxS). The new pop-up will have all the values hidden inside a form. When the user click on "submit" the final WxS will be performed. The pop-up also containes a table with all the information on the request

function OWS_request (OWS_name, OWS_service) {
//example of request
//ows.php?service=srtm10x&request=getCoverage&COVERAGE=srtm10x+&CRS=epgs:4326&BBOX=41,75,45,50&RESX=0.00833&RESY=0.00833&FORMAT=GEOTIFFINT16';


//Creation of the XTMLHTTP object and request of information coverage
request=new getXMLHTTP()
var URL='ows.php?service=WCS&request=describeCoverage&coverage='+OWS_name;
request.open ('GET',URL,false) ; //wait for response
request.send(null);
var xmldoc=request.responseXML;
//necessary info: CRS,RESX,RESY,FORMAT,BBOX the name is alreay given
//the XML programming was from the AJAX for Dummies
//for example the tag gml:offsetVector has the name offsetVector the GML is nothing
var CRSnode=xmldoc.getElementsByTagName("requestResponseCRSs");
var CRS=CRSnode[0].firstChild.nodeValue;
var RESnode=xmldoc.getElementsByTagName("offsetVector");
var sRESX=RESnode[0].firstChild.nodeValue;
var RESX=sRESX.split(" "); //array with resx in this case the first value is the important one
var sRESY=RESnode[1].firstChild.nodeValue;
var RESY=sRESY.split(" ");
var FORMATnode=xmldoc.getElementsByTagName("formats");
var FORMAT=FORMATnode[0].firstChild.nodeValue;

/*The BBOX comes from the getGeoExtents, were it is defined that
gminx=minx;
gmaxx=maxx;
gmaxy=maxy;
gminy=miny;

These are golbal variables, so no problem to access them, also they are always changed according to the events of kamap

BBOX = lower left (min x, min y) and upper right (max x, max y)
*/
var BBOX = new Array(gminx,gminy,gmaxx,gmaxy);

//creation of the URL that passes the information to the popup.php
//note: RESY fix in the string (it canot be negative)
var url_str='popup.php?service='+OWS_service+'&request=getCoverage&COVERAGE='+OWS_name+'&CRS='+CRS+'&BBOX='+BBOX.join(",")+'&RESX='+RESX[0]+'&RESY='+(-1*parseFloat(RESY[1]))+'&FORMAT='+FORMAT;

//open window
var window_popup=window.open(url_str,null,"height=300,width=375");
};

Labels: , ,

Monday, April 16, 2007

WCS and WFS metadata

I forgot that aside from the information if the map is downloadable or not is is also necessary to know what service, so another metadata tag was added

METADATA
"ows_service" "wcs"
END

it can be "wcs" or "wfs"

The programming is basically the same for the download but simpler since is it only a property and it doesn't need functions like isDownload()

The getMetadata is a bit different because the wcs and wfs are string and need '', otherwise the javascript eval() will not work (this functions runs the init.php reply)

$ows_service = "null";
if ($oLayer->getMetaData ("ows_service") !="") {
if(strcasecmp($oLayer->getMetaData("ows_service"), "wcs") == 0)
$ows_service = "'wcs'";

if(strcasecmp($oLayer->getMetaData("ows_service"), "wfs") == 0)
$ows_service = "'wfs'";

}

Labels: , , ,

Thursday, April 05, 2007

WCS wrapper for Mapserver

WMS,WFS and WCS is how it is possible to connected to a webGIS server and to download data:
WMS == Raster as an image
WFS == Vectorial information
WCS == Raster as a layer (original raster with values)

The request of WxF is normally done by a GET to the Mapserv program (is like a normal CGI-BIN for program execution), well I don't want Apache to run any program, so the solution is a wrapper PHP script, where the script catches the requests and uses them for a valid WCS reply.

The wrapper is very simple and there is a basic example on the mapserver home page, This is a wrapper with small modifications to work with WCS:

<?php
/*ows.php?service=WCS&version=1.0.0&Request=GetCapabilities*/
$request = ms_newowsrequestobj();

//$request->loadparams();

foreach ($_GET as $k=>$v) {
$request->setParameter($k, $v);
}



// forcing to version 1.0.0
$request->setParameter("VeRsIoN","1.0.0");

ms_ioinstallstdouttobuffer();

$oMap = ms_newMapobj("/usr/local/apache2/htdocs/secure/ms/data/calter.map");
$oMap->owsdispatch($request);
$contenttype = ms_iostripstdoutbuffercontenttype();
$buffer = ms_iogetstdoutbufferstring();

header('Content-type: application/xml');
echo $buffer;

ms_ioresethandlers();

?>

For start Mapserver only suports WCS version 1.0.0 so any request for higher versions has to be redirect:
$request->setParameter("VeRsIoN","1.0.0");

There seems to be a bug with $request->loadparams(); this produces an empy file reply from the server with no errors, so the solution it to get the parameters directely from the GET
foreach ($_GET as $k=>$v) {
$request->setParameter($k, $v);
}

if replacing $_GET for $_POST is should be possible to use POST to request the WCS, mapserver only accepts GET.

Labels: , , , , ,