Server.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /*
  3. * GetCapabilities
  4. * DescribeProcess
  5. * Execute
  6. */
  7. Lib::loadClass('Api_WpsV1_ServerBase');
  8. Lib::loadClass('Api_WfsException');
  9. Lib::loadClass('Api_WfsGeomTypeConverter');
  10. Lib::loadClass('Api_WfsNs');
  11. Lib::loadClass('Core_XmlWriter');
  12. Lib::loadClass('DBG');
  13. Lib::loadClass('Api_WpsV1_GetCapabilities');
  14. Lib::loadClass('Api_WpsV1_DescribeProcess');
  15. Lib::loadClass('Core_AclBase');
  16. Lib::loadClass('Type_ApiRequest');
  17. Lib::loadClass('Type_WpsProcess');
  18. Lib::loadClass('Api_WpsHelper');
  19. class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
  20. public function run(Type_ApiRequest $request) {
  21. $document = '';
  22. $req = V::geti('request', '', $request->query);
  23. if (!empty($req)) {
  24. if ('WPS' != V::geti('service', '', $request->query)) {
  25. throw new Api_WfsException("Only WPS Service is allowed");
  26. }
  27. $methodName = "{$req}Action";
  28. if (!method_exists($this, $methodName)) {
  29. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  30. }
  31. $this->DBG("WpsServer->{$methodName}() ...", __LINE__);
  32. $document = $this->$methodName($urlQuery);
  33. }
  34. else {
  35. $this->DBG("WpsServer->parseXMLRequest() ...", __LINE__);
  36. $document = $this->parseXMLRequest();
  37. header('Content-type: application/xml');
  38. echo '<?xml version="1.0" encoding="UTF-8"?>';
  39. echo $document; exit;// TODO: return $document;
  40. }
  41. 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>';}
  42. if ('raw' == V::get('outputFormat', '', $request->query)) {
  43. header('Content-type: text/plain; charset=utf-8');
  44. echo $document;
  45. } else {
  46. header('Content-type: application/xml');
  47. echo $document;
  48. }
  49. }
  50. function parseXMLRequest() {
  51. $data = array();
  52. $tags = [];
  53. $reqContent = Request::getRequestBody();
  54. if (empty($reqContent)) throw new Exception("Empty request");
  55. Lib::loadClass('XML');
  56. $xml = XML::xmlToArray($reqContent);
  57. if (empty($xml)) throw new Exception("Error structure from request");
  58. $rootTagName = $xml[0];
  59. switch ($rootTagName) {
  60. case 'wps:Execute': return $this->_runExecute($xml);
  61. default: throw new Api_WfsException("Not implemented WPS xml request '{$rootTagName}'" . __LINE__, 501);
  62. }
  63. }
  64. function _runExecute($xml) {
  65. $funInfo = self::_parseExecuteXmlArray($xml);
  66. $identifier = V::get('identifier', '', $funInfo);
  67. $args = V::get('args', [], $funInfo, 'array');
  68. if (empty($identifier)) throw new Exception("Parse xml request error - missing identifier");
  69. Lib::loadClass('Api_WpsHelper');
  70. $wpsProcess = Api_WpsHelper::getUserWpsProcess($identifier);
  71. Api_WpsHelper::validateProcessArgs($wpsProcess, $args);
  72. Api_WpsHelper::executeProcess($wpsProcess, $args);
  73. exit;
  74. }
  75. function describeProcessAction() {
  76. $identifier = V::geti('identifier', '', $_REQUEST);
  77. if (empty($identifier)) throw new HttpException("Missing identifier", 400);
  78. if ('JTS:Aarea' === $identifier) return self::exampleDescribeProcess_JTS_Area();
  79. if ('vec:Feature' === $identifier) return self::exampleDescribeProcess_vec_Feature();
  80. $wpsServerUrl = $this->getBaseUri();
  81. $wpsProcess = Api_WpsHelper::getUserWpsProcess($identifier);
  82. if (!$wpsProcess) throw new Api_WfsException("Forbidden", 403);
  83. Api_WpsV1_DescribeProcess::sendDescribeProcessXml($wpsServerUrl, $wpsProcess);
  84. }
  85. static function exampleDescribeProcess_JTS_Area() {
  86. header('Content-type: application/xml; charset=utf-8');
  87. 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>';
  88. exit;
  89. }
  90. static function exampleDescribeProcess_vec_Feature() {
  91. header('Content-type: application/xml; charset=utf-8');
  92. 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>';
  93. exit;
  94. }
  95. public function getCapabilitiesAction() {
  96. $wpsServerUrl = $this->getBaseUri();
  97. $serviceTitle = "Web Processing Service";
  98. $serviceDescription = "Web Processing Service";
  99. $idDefaultDB = DB::getPDO()->getZasobId();
  100. $wpsProcessList = Api_WpsHelper::getUserWpsProcessList();
  101. switch (V::get('outputFormat', 'xml', $_GET)) {
  102. case 'csv': {
  103. Api_WpsV1_GetCapabilities::sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList);
  104. } break;
  105. case 'xml': {
  106. Api_WpsV1_GetCapabilities::sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList);
  107. } break;
  108. default: throw new Api_WfsException("Not Implemented outputFormat", 501); // , null, 'NotImplemented', 'request');
  109. }
  110. exit;
  111. }
  112. }