DescribeProcess.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. DBG::log($wpsProcess, 'array', "\$wpsProcess");
  33. $xmlWriter->h('ProcessDescription', [
  34. [ 'ows:Identifier', $wpsProcess->identifier ],
  35. [ 'ows:Title', $wpsProcess->title ],
  36. [ 'ows:Abstract', $wpsProcess->description ],
  37. [ 'DataInputs', array_map([ self, 'convertInputToXmlWriter' ], $wpsProcess->dataInputs) ],
  38. [ 'ProcessOutputs', [
  39. [ 'Output', [
  40. [ 'ows:Identifier', "result" ],
  41. [ 'ows:Title', "result" ],
  42. [ 'ComplexOutput', [
  43. [ 'Default', [ self::convertOutputFormatToXmlWriter($wpsProcess->defaultOutput) ] ],
  44. [ 'Supported', array_map([ self, 'convertOutputFormatToXmlWriter' ], $wpsProcess->supportedOutput) ],
  45. // [ 'Supported', [
  46. // [ 'Format', [ [ 'MimeType', "text/xml; subtype=wfs-collection/1.0" ] ] ],
  47. // [ 'Format', [ [ 'MimeType', "text/xml; subtype=wfs-collection/1.1" ] ] ],
  48. // [ 'Format', [ [ 'MimeType', "application/json" ] ] ],
  49. // [ 'Format', [ [ 'MimeType', "application/wfs-collection-1.0" ] ] ],
  50. // [ 'Format', [ [ 'MimeType', "application/wfs-collection-1.1" ] ] ],
  51. // [ 'Format', [ [ 'MimeType', "application/zip" ] ] ],
  52. // ] ],
  53. ] ],
  54. ] ],
  55. ] ],
  56. ]);
  57. $xmlWriter->endElement();// wps:ProcessDescriptions
  58. $xmlWriter->endDocument();
  59. exit;
  60. }
  61. static function convertInputToXmlWriter($input) {
  62. DBG::log($input, 'array', "convertInputToXmlWriter(\$input)");
  63. return [ 'Input', [ 'maxOccurs' => $input->maxOccurs, 'minOccurs' => $input->minOccurs ], array_filter([
  64. [ 'ows:Identifier', $input->identifier ],
  65. [ 'ows:Title', $input->title ],
  66. (!empty($input->description)) ? [ 'ows:Abstract', $input->description ] : null,
  67. self::convertInputFormChoiceToXmlWriter($input),
  68. ], [ 'V', 'filterNotEmpty' ]) ];
  69. // (isset($input->description)) ? [ [ 'ows:Abstract', $input->description ] ] : [],
  70. }
  71. static function convertInputFormChoiceToXmlWriter($input) {
  72. switch ($input->dataType) {
  73. case 'literal': return self::convertInputLiteralDataToXmlWriter($input);
  74. case 'complex': return self::convertInputComplexDataToXmlWriter($input);
  75. case 'boundingBox': return self::convertInputBoundingBoxDataToXmlWriter($input);
  76. }
  77. }
  78. static function convertInputLiteralDataToXmlWriter($input) {
  79. $owsDataTypeAttribs = ( !empty($input->xsdType) ) ? [ 'ows:reference' => $input->xsdType ] : [];
  80. return [ 'LiteralData', [], array_merge(
  81. [ [ 'ows:AnyValue' ] ],
  82. ( !empty($input->xsdType) ) ? [ [ 'ows:DataType', $owsDataTypeAttribs, $input->xsdType ] ] : []
  83. ) ];
  84. }
  85. static function convertInputComplexDataToXmlWriter($input) {
  86. return [ 'ComplexData', [], [
  87. [ 'Default', [
  88. [ 'Format', [
  89. [ 'MimeType', "text/xml" ],
  90. ] ],
  91. ] ],
  92. ] ];
  93. }
  94. static function convertInputBoundingBoxDataToXmlWriter($input) {
  95. return [ 'BoundingBoxData', [], [
  96. ] ];
  97. }
  98. static function convertOutputFormatToXmlWriter($output) {
  99. DBG::log($output, 'array', "convertOutputFormatToXmlWriter(\$output)");
  100. // 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
  101. // return <MimeType>text/xml</MimeType><Encoding>base64</Encoding><Schema>http://foo.bar/gml/3.1.0/polygon.xsd</Schema>
  102. return [ 'Format', array_merge(
  103. (!empty($output['MimeType'])) ? [ [ 'MimeType', $output['MimeType'] ] ] : [],
  104. (!empty($output['Encoding'])) ? [ [ 'Encoding', $output['Encoding'] ] ] : [],
  105. (!empty($output['Schema'])) ? [ [ 'Schema', $output['Schema'] ] ] : []
  106. ) ];
  107. }
  108. }