| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- /*
- * GetCapabilities
- * DescribeProcess
- * Execute
- */
- Lib::loadClass('Api_WpsV1_ServerBase');
- Lib::loadClass('Api_WfsException');
- Lib::loadClass('Api_WfsGeomTypeConverter');
- Lib::loadClass('Api_WfsNs');
- Lib::loadClass('Core_XmlWriter');
- Lib::loadClass('DBG');
- Lib::loadClass('Api_WpsV1_GetCapabilities');
- Lib::loadClass('Api_WpsV1_DescribeProcess');
- Lib::loadClass('Core_AclBase');
- Lib::loadClass('Type_ApiRequest');
- Lib::loadClass('Type_WpsProcess');
- Lib::loadClass('Api_WpsHelper');
- class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
- public function run(Type_ApiRequest $request) {
- $document = '';
- $req = V::geti('request', '', $request->query);
- if (!empty($req)) {
- if ('WPS' != V::geti('service', '', $request->query)) {
- throw new Api_WfsException("Only WPS Service is allowed");
- }
- $methodName = "{$req}Action";
- if (!method_exists($this, $methodName)) {
- throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
- }
- $this->DBG("WpsServer->{$methodName}() ...", __LINE__);
- $document = $this->$methodName($urlQuery);
- }
- else {
- $this->DBG("WpsServer->parseXMLRequest() ...", __LINE__);
- $document = $this->parseXMLRequest();
- header('Content-type: application/xml');
- echo '<?xml version="1.0" encoding="UTF-8"?>';
- echo $document; exit;// TODO: return $document;
- }
- IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$document (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($document);echo'</pre>';}
- if ('raw' == V::get('outputFormat', '', $request->query)) {
- header('Content-type: text/plain; charset=utf-8');
- echo $document;
- } else {
- header('Content-type: application/xml');
- echo $document;
- }
- }
- function parseXMLRequest() {
- $data = array();
- $tags = [];
- $reqContent = Request::getRequestBody();
- if (empty($reqContent)) throw new Exception("Empty request");
- Lib::loadClass('XML');
- $xml = XML::xmlToArray($reqContent);
- if (empty($xml)) throw new Exception("Error structure from request");
- $rootTagName = $xml[0];
- switch ($rootTagName) {
- case 'wps:Execute': return $this->_runExecute($xml);
- default: throw new Api_WfsException("Not implemented WPS xml request '{$rootTagName}'" . __LINE__, 501);
- }
- }
- function _runExecute($xml) {
- $funInfo = self::_parseExecuteXmlArray($xml);
- $identifier = V::get('identifier', '', $funInfo);
- $args = V::get('args', [], $funInfo, 'array');
- if (empty($identifier)) throw new Exception("Parse xml request error - missing identifier");
- Lib::loadClass('Api_WpsHelper');
- $wpsProcess = Api_WpsHelper::getUserWpsProcess($identifier);
- Api_WpsHelper::validateProcessArgs($wpsProcess, $args);
- Api_WpsHelper::executeProcess($wpsProcess, $args);
- exit;
- }
- function describeProcessAction() {
- $identifier = V::geti('identifier', '', $_REQUEST);
- if (empty($identifier)) throw new HttpException("Missing identifier", 400);
- if ('JTS:Aarea' === $identifier) return self::exampleDescribeProcess_JTS_Area();
- if ('vec:Feature' === $identifier) return self::exampleDescribeProcess_vec_Feature();
- $wpsServerUrl = $this->getBaseUri();
- $wpsProcess = Api_WpsHelper::getUserWpsProcess($identifier);
- if (!$wpsProcess) throw new Api_WfsException("Forbidden", 403);
- Api_WpsV1_DescribeProcess::sendDescribeProcessXml($wpsServerUrl, $wpsProcess);
- }
- static function exampleDescribeProcess_JTS_Area() {
- header('Content-type: application/xml; charset=utf-8');
- echo '<?xml version="1.0" encoding="UTF-8"?><wps:ProcessDescriptions xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd"><ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true"><ows:Identifier>JTS:area</ows:Identifier><ows:Title>Area</ows:Title><ows:Abstract>Returns the area of a geometry, in the units of the geometry. Assumes a Cartesian plane, so this process is only recommended for non-geographic CRSes.</ows:Abstract><DataInputs><Input maxOccurs="1" minOccurs="1"><ows:Identifier>geom</ows:Identifier><ows:Title>geom</ows:Title><ows:Abstract>Input geometry</ows:Abstract><ComplexData><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/json</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexData></Input></DataInputs><ProcessOutputs><Output><ows:Identifier>result</ows:Identifier><ows:Title>result</ows:Title><LiteralOutput><ows:DataType>double</ows:DataType></LiteralOutput></Output></ProcessOutputs></ProcessDescription></wps:ProcessDescriptions>';
- exit;
- }
- static function exampleDescribeProcess_vec_Feature() {
- header('Content-type: application/xml; charset=utf-8');
- echo '<?xml version="1.0" encoding="UTF-8"?><wps:ProcessDescriptions xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd"><ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true"><ows:Identifier>vec:Feature</ows:Identifier><ows:Title>Feature from Geometry</ows:Title><ows:Abstract>Converts a geometry into a feature collection.</ows:Abstract><DataInputs><Input maxOccurs="1" minOccurs="1"><ows:Identifier>geometry</ows:Identifier><ows:Title>geometry</ows:Title><ows:Abstract>Input geometry</ows:Abstract><ComplexData><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/json</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexData></Input><Input maxOccurs="1" minOccurs="1"><ows:Identifier>crs</ows:Identifier><ows:Title>crs</ows:Title><ows:Abstract>Coordinate reference system of the input geometry (if not provided in the geometry)</ows:Abstract><LiteralData><ows:AnyValue/></LiteralData></Input><Input maxOccurs="1" minOccurs="1"><ows:Identifier>typeName</ows:Identifier><ows:Title>typeName</ows:Title><ows:Abstract>Feauturetype name for the feature collection</ows:Abstract><LiteralData><ows:AnyValue/></LiteralData></Input></DataInputs><ProcessOutputs><Output><ows:Identifier>result</ows:Identifier><ows:Title>result</ows:Title><ComplexOutput><Default><Format><MimeType>text/xml; subtype=wfs-collection/1.0</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=wfs-collection/1.0</MimeType></Format><Format><MimeType>text/xml; subtype=wfs-collection/1.1</MimeType></Format><Format><MimeType>application/json</MimeType></Format><Format><MimeType>application/wfs-collection-1.0</MimeType></Format><Format><MimeType>application/wfs-collection-1.1</MimeType></Format><Format><MimeType>application/zip</MimeType></Format></Supported></ComplexOutput></Output></ProcessOutputs></ProcessDescription></wps:ProcessDescriptions>';
- exit;
- }
- public function getCapabilitiesAction() {
- $wpsServerUrl = $this->getBaseUri();
- $serviceTitle = "Web Processing Service";
- $serviceDescription = "Web Processing Service";
- $idDefaultDB = DB::getPDO()->getZasobId();
- $wpsProcessList = Api_WpsHelper::getUserWpsProcessList();
- switch (V::get('outputFormat', 'xml', $_GET)) {
- case 'csv': {
- Api_WpsV1_GetCapabilities::sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList);
- } break;
- case 'xml': {
- Api_WpsV1_GetCapabilities::sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList);
- } break;
- default: throw new Api_WfsException("Not Implemented outputFormat", 501); // , null, 'NotImplemented', 'request');
- }
- exit;
- }
- }
|