DescribeProcess.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. Lib::loadClass('Type_WpsProcess');
  8. class Api_WpsV1_DescribeProcess {
  9. static function sendDescribeProcessXml($wpsServerUrl, Type_WpsProcess $wpsProcess) {
  10. header('Content-type: application/xml; charset=utf-8');
  11. $xmlWriter = new Core_XmlWriter();
  12. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  13. $xmlWriter->openUri('php://output');
  14. $xmlWriter->setIndent(true);
  15. $xmlWriter->startDocument('1.0','UTF-8');
  16. $xmlWriter->startElement('wps:ProcessDescriptions');
  17. $xmlWriter->writeAttribute('service', "WPS");
  18. $xmlWriter->writeAttribute('version', "1.0.0");
  19. // $xmlWriter->writeAttribute('xml:lang', "en");
  20. $xmlWriter->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
  21. $xmlWriter->writeAttribute('xmlns:ows', "http://www.opengis.net/ows/1.1");
  22. $xmlWriter->writeAttribute('xmlns:wps', "http://www.opengis.net/wps/1.0.0");
  23. $xmlWriter->writeAttribute('xmlns:xlink', "http://www.w3.org/1999/xlink");
  24. $xmlWriter->writeAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
  25. // $xmlWriter->writeAttribute('xsi:schemaLocation', "http://www.opengis.net/wps/1.0.0 ../wpsGetCapabilities_response.xsd");
  26. // foreach (Api_WfsNs::getNsList() as $uri => $prefix) {
  27. // $xmlWriter->writeAttribute("xmlns:{$prefix}", $uri);
  28. // }
  29. // $schemaLocations = [];
  30. //$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
  31. // if (!empty($schemaLocations)) $xmlWriter->writeAttribute('xsi:schemaLocation', implode(' ', $schemaLocations));
  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:Identifier', $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', self::convertOutputToWpsFormatXml($wpsProcess->defaultOutput) ],
  63. ] ],
  64. [ 'Supported', array_map(function ($output) {
  65. return [ 'Format', self::convertOutputToWpsFormatXml($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 convertOutputToWpsFormatXml($output) {
  84. // 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
  85. // return <MimeType>text/xml</MimeType><Encoding>base64</Encoding><Schema>http://foo.bar/gml/3.1.0/polygon.xsd</Schema>
  86. return array_merge(
  87. (!empty($output['MimeType'])) ? [ [ 'MimeType', $output['MimeType'] ] ] : [],
  88. (!empty($output['Encoding'])) ? [ [ 'Encoding', $output['Encoding'] ] ] : [],
  89. (!empty($output['Schema'])) ? [ [ 'Schema', $output['Schema'] ] ] : []
  90. );
  91. }
  92. }