Child pages
  • WPS Primer (using Matlab)*
Skip to end of metadata
Go to start of metadata
Extracting data from the WPS server is a three step process
  1. Get information about available processes (GetCapabilities)
  2. Get information about a specific process (DescribeProcess)
  3. Execute the process (Execute)

GetCapabilities

The first step is to ask the server which processes are being offered. To get this information we do a GetCapabilities request. The request returns an xml response that contains a list of processes that are provided by the server.

% Server URL
url = 'http://dtvirt5.deltares.nl/wps';

% Pass the required paramters
xml = urlread(url,'get',{'request','GetCapabilities','service','wps','version','1.0.0'});

% Now we have to save the XML file otherwise we can't use xmlread
fid = fopen('file.xml','w');
fwrite(fid, xml);
fclose(fid);

% Read the XML file we just saved
xmldoc = xmlread('file.xml');

% Look up the intersting elements (Processes)
offerings = xmldoc.getElementsByTagName('wps:Process');

% Look up all process Identifiers
for i = 0:offerings.getLength-1
    process = offerings.item(i);
    identifier = process.getElementsByTagName('ows:Identifier').item(0).getFirstChild.getData
end

DescribeProcess

After inspecting the GetCapabilities document and choosing the process you like, you need to find out how to execute the process. For execution you need at least all all requested input parameters. This is done by means of the 'DescribeProcess' request. This request returns an xml containing all in- and outputs.

% Pass the required parameters to read the process' meta data
xml = urlread(url,'get',{'request','DescribeProcess','service','wps','version','1.0.0','identifier',identifier});

% Now we have to save the XML file otherwise we can't use xmlread
fid = fopen('file.xml','w');
fwrite(fid, xml);
fclose(fid);

% Read the XML file we just saved
xmldoc = xmlread('file.xml');

% Look up the intersting elements (Processes)
inputs = xmldoc.getElementsByTagName('Input')

% Look up all input identifiers
for i = 0:inputs.getLength-1
    input = inputs.item(i);
    identifier = input.getElementsByTagName('ows:Identifier').item(0).getFirstChild.getData
end

Execute

Once you've found and specified all input parameters you are ready to execute the process by means of the 'Execute' request. The service returns an xml containing all process outputs. These outputs can be read by Matlab and can also be plotted or used for other operations.

% Specify the process with the process identifier
identifier = 'tidal_predict'

% Specify process inputs
inputs = 'location=POINT(3 52);startdate=2013-08-21 00:00;frequency=HOURLY;enddate=2013-08-29 23:00'

% Pass the required parameters to read the process' meta data
xml = urlread([url '?request=Execute&service=wps&version=1.0.0&identifier=' identifier '&DataInputs=' inputs]);

% Now we have to save the XML file otherwise we can't use xmlread
fid = fopen('file.xml','w');
fwrite(fid, xml);
fclose(fid);

% Read the XML file we just saved
xmldoc = xmlread('file.xml');

% Look up the intersting elements (Processes)
outputs = xmldoc.getElementsByTagName('wps:Output');
output = outputs.item(0);
identifier = output.getElementsByTagName('ows:Identifier').item(0).getFirstChild.getData;

% Look up the output data from the XML
outputdata = output.getElementsByTagName('wps:ComplexData').item(0).getFirstChild.getData;
outputdata = char(outputdata);

% Write output data to table
table = textscan(outputdata(2:end),'%s%f%f%f', 'Delimiter', ',','HeaderLines',1);
dates = table{1};
h = table{2};

% Plot output
plot(datenum(dates),h)
datetick;

  • No labels