DescribeProcess.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. Lib::loadClass('Api_WfsException');
  3. Lib::loadClass('Api_WfsNs');
  4. Lib::loadClass('Request');
  5. Lib::loadClass('Core_AclHelper');
  6. Lib::loadClass('Core_XmlWriter');
  7. class Api_WpsV1_DescribeProcess {
  8. static function sendDescribeProcessXml($wpsServerUrl, $identifier) {
  9. header('Content-type: application/xml; charset=utf-8');
  10. $xmlWriter = new Core_XmlWriter();
  11. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  12. $xmlWriter->openUri('php://output');
  13. $xmlWriter->setIndent(true);
  14. $xmlWriter->startDocument('1.0','UTF-8');
  15. $xmlWriter->startElement('wps:ProcessDescriptions');
  16. $xmlWriter->writeAttribute('service', "WPS");
  17. $xmlWriter->writeAttribute('version', "1.0.0");
  18. // $xmlWriter->writeAttribute('xml:lang', "en");
  19. $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
  20. $xmlWriter->writeAttribute('xmlns:ows', "http://www.opengis.net/ows/1.1");
  21. $xmlWriter->writeAttribute('xmlns:wps', "http://www.opengis.net/wps/1.0.0");
  22. $xmlWriter->writeAttribute('xmlns:xlink', "http://www.w3.org/1999/xlink");
  23. $xmlWriter->writeAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
  24. // $xmlWriter->writeAttribute('xsi:schemaLocation', "http://www.opengis.net/wps/1.0.0 ../wpsGetCapabilities_response.xsd");
  25. // foreach (Api_WfsNs::getNsList() as $uri => $prefix) {
  26. // $xmlWriter->writeAttribute("xmlns:{$prefix}", $uri);
  27. // }
  28. // $schemaLocations = [];
  29. //$schemaLocations[] = 'http://www.opengis.net/wfs http://webgis.regione.sardegna.it:80/geoserver/schemas/wfs/1.0.0/WFS-capabilities.xsd';// @from http://webgis.regione.sardegna.it/geoserver/ows?service=WFS&request=GetCapabilities
  30. // if (!empty($schemaLocations)) $xmlWriter->writeAttribute('xsi:schemaLocation', implode(' ', $schemaLocations));
  31. $wpsProcess = self::getWpsProcess($identifier);
  32. $xmlWriter->h('ProcessDescription', [
  33. [ 'ows:Identifier', $wpsProcess->identifier ],
  34. [ 'ows:Title', $wpsProcess->title ],
  35. [ 'ows:Abstract', $wpsProcess->description ],
  36. [ 'DataInputs', array_map(function ($dataInput) {
  37. return [ 'Input', [ 'maxOccurs' => $dataInput->maxOccurs, 'minOccurs' => $dataInput->minOccurs ], [
  38. [ 'ows:Identiier', $dataInput->identifier ],
  39. [ 'ows:Title', $dataInput->title ],
  40. [ 'ows:Abstract', $dataInput->description ],
  41. ('xml' === $dataInput->type)
  42. ? [ 'ComplexData', [
  43. [ 'Default', [
  44. [ 'Format', [
  45. [ 'MimeType', "text/xml; subtype=gml/3.1.1" ],
  46. ] ],
  47. ] ],
  48. ] ]
  49. : [
  50. [ 'LiteralData', [
  51. [ 'ows:AnyValue' ],
  52. ] ],
  53. ],
  54. ] ];
  55. }, $wpsProcess->dataInputs) ],
  56. [ 'ProcessOutputs', [
  57. [ 'Output', [
  58. [ 'ows:Identifier', "result" ],
  59. [ 'ows:Title', "result" ],
  60. [ 'ComplexOutput', [
  61. [ 'Default', [
  62. [ 'Format', [ [ 'MimeType', $wpsProcess->defaultOutput ] ] ],
  63. ] ],
  64. [ 'Supported', array_map(function ($output) {
  65. return [ 'Format', [ [ 'MimeType', $output ] ] ];
  66. }, $wpsProcess->supportedOutput) ],
  67. // [ 'Supported', [
  68. // [ 'Format', [ [ 'MimeType', "text/xml; subtype=wfs-collection/1.0" ] ] ],
  69. // [ 'Format', [ [ 'MimeType', "text/xml; subtype=wfs-collection/1.1" ] ] ],
  70. // [ 'Format', [ [ 'MimeType', "application/json" ] ] ],
  71. // [ 'Format', [ [ 'MimeType', "application/wfs-collection-1.0" ] ] ],
  72. // [ 'Format', [ [ 'MimeType', "application/wfs-collection-1.1" ] ] ],
  73. // [ 'Format', [ [ 'MimeType', "application/zip" ] ] ],
  74. // ] ],
  75. ] ],
  76. ] ],
  77. ] ],
  78. ]);
  79. $xmlWriter->endElement();// wps:ProcessDescriptions
  80. $xmlWriter->endDocument();
  81. exit;
  82. }
  83. static function getWpsProcess($identifier) { // TODO: get from WPS Process Factory // @return Type_WpsProcess
  84. $wpsProcess = (object)[
  85. 'identifier' => $identifier,
  86. 'title' => "Title({$identifier})",
  87. 'description' => "Desc($identifier)",
  88. 'maxOccurs' => "1",
  89. 'minOccurs' => "1",
  90. 'dataInputs' => [
  91. (object)[
  92. 'identifier' => $identifier,
  93. 'title' => $title,
  94. 'description' => $description,
  95. 'type' => 'literal',
  96. ],
  97. ],
  98. // 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
  99. 'defaultOutput' => [ 'MimeType' => "text/xml; subtype=wfs-collection/1.0" ],
  100. 'supportedOutput' => [
  101. [ 'MimeType' => "text/xml; subtype=wfs-collection/1.0" ],
  102. [ 'MimeType' => "text/xml; subtype=wfs-collection/1.1" ],
  103. [ 'MimeType' => "application/json" ],
  104. [ 'MimeType' => "application/wfs-collection-1.0" ],
  105. [ 'MimeType' => "application/wfs-collection-1.1" ],
  106. [ 'MimeType' => "application/zip" ],
  107. ]
  108. ];
  109. return $wpsProcess;
  110. }
  111. }