GetCapabilities.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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_GetCapabilities { // TODO: ...
  8. static function sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList) {
  9. throw new Api_WfsException("Not Implemented sendGetCapabilitiesCsv for Wps version 1.0.0", 501);
  10. header('Content-Type: text/csv; charset=utf-8');
  11. $csvLineSepartor = "\n";
  12. $csvValueSepartor = ",";
  13. $csvText = function ($value) {
  14. return '"' . str_replace(['"'], ['\"'], $value) . '"';
  15. };
  16. echo implode(",", [
  17. "Name",
  18. "Title",
  19. "namespace url",
  20. "Keywords",
  21. "Abstract",
  22. "SRS",
  23. "LatLongBoundingBox - minx",
  24. "LatLongBoundingBox - miny",
  25. "LatLongBoundingBox - maxx",
  26. "LatLongBoundingBox - maxy",
  27. ]);
  28. echo $csvLineSepartor;
  29. echo implode($csvLineSepartor, array_map(function ($acl) use ($csvText, $csvValueSepartor) {
  30. $ns = Core_AclHelper::parseNamespaceUrl($acl->getNamespace());
  31. return implode($csvValueSepartor, [
  32. "p5_{$ns['prefix']}:{$ns['name']}", // Name
  33. $csvText($acl->getRawLabel()), // Title
  34. Api_WfsNs::getNsUri($ns['prefix']), // namespace url
  35. $csvText(implode(', ', [ $acl->getID(), $acl->getName(), $acl->getRawLabel() ])), // Keywords
  36. $csvText($acl->getRawOpis()), // Abstract
  37. 'EPSG:4326', // SRS
  38. "8.12328509871721", // LatLongBoundingBox - minx
  39. "38.8575126897477", // LatLongBoundingBox - miny
  40. "9.838674658246807", // LatLongBoundingBox - maxx
  41. "41.31378404137082", // LatLongBoundingBox - maxy
  42. ]);
  43. }, $wpsProcessList));
  44. echo $csvLineSepartor;
  45. echo implode($csvLineSepartor, array_map(function ($typeName) use ($csvText, $csvValueSepartor) {
  46. list($prefix, $name) = explode(':', $typeName);
  47. return implode($csvValueSepartor, [
  48. "p5_{$prefix}:{$name}", // Name
  49. $csvText($name), // Title
  50. Api_WfsNs::getNsUri($prefix), // namespace url
  51. $csvText($name), // Keywords
  52. $csvText($name), // Abstract
  53. 'EPSG:4326', // SRS
  54. "8.12328509871721", // LatLongBoundingBox - minx
  55. "38.8575126897477", // LatLongBoundingBox - miny
  56. "9.838674658246807", // LatLongBoundingBox - maxx
  57. "41.31378404137082", // LatLongBoundingBox - maxy
  58. ]);
  59. }, Core_AclHelper::getCustomAclList()));
  60. exit;
  61. }
  62. static function sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList) {
  63. header('Content-type: application/xml; charset=utf-8');
  64. $xmlWriter = new Core_XmlWriter();
  65. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  66. $xmlWriter->openUri('php://output');
  67. $xmlWriter->setIndent(true);
  68. $xmlWriter->startDocument('1.0','UTF-8');
  69. $xmlWriter->startElement('wps:Capabilities');
  70. $xmlWriter->writeAttribute('service', "WPS");
  71. $xmlWriter->writeAttribute('version', "1.0.0");
  72. // $xmlWriter->writeAttribute('xml:lang', "en-GB");
  73. $xmlWriter->writeAttribute('xmlns:xlink', "http://www.w3.org/1999/xlink");
  74. $xmlWriter->writeAttribute('xmlns:wps', "http://www.opengis.net/wps/1.0.0");
  75. $xmlWriter->writeAttribute('xmlns:ows', "http://www.opengis.net/ows/1.1");
  76. $xmlWriter->writeAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
  77. // $xmlWriter->writeAttribute('xsi:schemaLocation', "http://www.opengis.net/wps/1.0.0 ../wpsGetCapabilities_response.xsd");
  78. $xmlWriter->writeAttribute('updateSequence', "1");
  79. $xmlWriter->writeAttribute('xmlns:ogc', "http://www.opengis.net/ogc");
  80. // $xmlWriter->writeAttribute('xmlns', 'http://www.opengis.net/wfs');
  81. // $xmlWriter->writeAttribute('xmlns:ogc', 'http://www.opengis.net/ogc');
  82. // $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  83. foreach (Api_WfsNs::getNsList() as $uri => $prefix) {
  84. $xmlWriter->writeAttribute("xmlns:{$prefix}", $uri);
  85. }
  86. $schemaLocations = [];
  87. //$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
  88. if (!empty($schemaLocations)) $xmlWriter->writeAttribute('xsi:schemaLocation', implode(' ', $schemaLocations));
  89. $xmlWriter->h('ows:ServiceIdentification', [
  90. ['ows:Title', $serviceTitle],
  91. ['ows:Abstract', $serviceDescription],
  92. ['ows:Keywords', [
  93. ['ows:Keyword', "WPS"],
  94. ] ],
  95. ['ows:ServiceType', "WPS"],
  96. ['ows:ServiceTypeVersion', "1.0.0"],
  97. // ['ows:Profile', ...],
  98. // Unordered list of identifiers of Application Profiles that are implemented by this server.
  99. // This element should be included for each specified application profile implemented by this server.
  100. // The identifier value should be specified by each Application Profile. If this element is omitted, no meaning is implied.
  101. // ['ows:Fees', "NONE"],
  102. // ['ows:AccessConstraints', "NONE"], // @from xsd: Unordered list of access constraints applied to assure the protection of privacy or intellectual property,
  103. // and any other restrictions on retrieving or using data from or otherwise using this server.
  104. // The reserved value NONE (case insensitive) shall be used to mean no access constraints are imposed.
  105. // When this element is omitted, no meaning is implied.
  106. ]);
  107. // @from http://schemas.opengis.net/wps/1.0.0/examples/20_wpsGetCapabilities_response.xml
  108. // <ows:ServiceProvider>
  109. // <ows:ProviderName>Agriculture and Agri-Food Canada</ows:ProviderName>
  110. // <ows:ProviderSite xlink:href="http://gis.agr.gc.ca/"/>
  111. // <ows:ServiceContact>
  112. // <ows:IndividualName>Peter Schut</ows:IndividualName>
  113. // <ows:PositionName>Information System Scientist</ows:PositionName>
  114. // <ows:ContactInfo>
  115. // <ows:Phone>
  116. // <ows:Voice>+1 613 759-1874</ows:Voice>
  117. // <ows:Facsimile>+1 613 759-1937</ows:Facsimile>
  118. // </ows:Phone>
  119. // <ows:Address>
  120. // <ows:DeliveryPoint>Room 1135, Neatby Building, 960, Carling Avenue</ows:DeliveryPoint>
  121. // <ows:City>Ottawa</ows:City>
  122. // <ows:AdministrativeArea>ON</ows:AdministrativeArea>
  123. // <ows:PostalCode>K1AOC6</ows:PostalCode>
  124. // <ows:Country>Canada</ows:Country>
  125. // <ows:ElectronicMailAddress>schutp@agr.gc.ca</ows:ElectronicMailAddress>
  126. // </ows:Address>
  127. // </ows:ContactInfo>
  128. // </ows:ServiceContact>
  129. // </ows:ServiceProvider>
  130. $xmlWriter->h('ows:ServiceProvider', [
  131. [ 'ows:ProviderName', $_SERVER['SERVER_NAME'] ], // TODO: company name - from config?
  132. [ 'ows:ProviderSite', [ 'xlink:href' => $wpsServerUrl ], null ],
  133. // [ 'ows:ServiceContact', [
  134. // [ 'ows:IndividualName', "..." ],
  135. // ] ],
  136. ]);
  137. $xmlWriter->h('ows:OperationsMetadata', [
  138. [ 'ows:Operation', [ 'name' => "GetCapabilities" ], [
  139. [ 'ows:DCP', [
  140. [ 'ows:HTTP', [
  141. [ 'ows:Get', [ 'xlink:href' => $wpsServerUrl ], null ],
  142. ] ]
  143. ] ]
  144. ] ],
  145. [ 'ows:Operation', [ 'name' => "DescribeProcess" ], [
  146. [ 'ows:DCP', [
  147. [ 'ows:HTTP', [
  148. [ 'ows:Get', [ 'xlink:href' => $wpsServerUrl ], null ],
  149. // [ 'ows:Post', [ 'xlink:href' => $wpsServerUrl ], null ], // TODO: POST xml with DescribeProcess
  150. ] ]
  151. ] ]
  152. ] ],
  153. [ 'ows:Operation', [ 'name' => "Execute" ], [
  154. [ 'ows:DCP', [
  155. [ 'ows:HTTP', [
  156. [ 'ows:Get', [ 'xlink:href' => $wpsServerUrl ], null ],
  157. // [ 'ows:Post', [ 'xlink:href' => $wpsServerUrl ], null ], // TODO: POST xml with DescribeProcess
  158. ] ]
  159. ] ]
  160. ] ],
  161. ]);
  162. // @from http://schemas.opengis.net/wps/1.0.0/examples/20_wpsGetCapabilities_response.xml
  163. // <wps:ProcessOfferings>
  164. // <wps:Process wps:processVersion="1">
  165. // <ows:Identifier>buffer</ows:Identifier>
  166. // <ows:Title>Buffer a polygon feature</ows:Title>
  167. // <ows:Abstract>Buffer the polygon coordinates found in one GML stream by a given buffer distance, and output the results in GML.</ows:Abstract>
  168. // <ows:Metadata xlink:title="buffer" />
  169. // <ows:Metadata xlink:title="polygon" />
  170. // </wps:Process>
  171. // </wps:ProcessOfferings>
  172. // <wps:Languages>
  173. // <wps:Default>
  174. // <ows:Language>en-CA</ows:Language>
  175. // </wps:Default>
  176. // <wps:Supported>
  177. // <ows:Language>en-CA</ows:Language>
  178. // <ows:Language>fr-CA</ows:Language>
  179. // </wps:Supported>
  180. // </wps:Languages>
  181. // </wps:Capabilities>
  182. $xmlWriter->h('wps:ProcessOfferings', array_map(function ($wpsProcess) {
  183. return [ 'wps:Process', [ 'wps:processVersion' => $wpsProcess->version ], [
  184. [ 'ows:Identifier', $wpsProcess->identifier ],
  185. [ 'ows:Title', $wpsProcess->title ],
  186. [ 'ows:Abstract', $wpsProcess->description ],
  187. ] ];
  188. }, $wpsProcessList));
  189. // $xmlWriter->h('wps:ProcessOfferings', [
  190. // [ 'wps:Process', [ 'wps:processVersion' => "1.0.0" ], [
  191. // [ 'ows:Identifier', "buffer" ],
  192. // [ 'ows:Title', "Buffer a polygon feature" ],
  193. // [ 'ows:Abstract', "Buffer the polygon coordinates found in one GML stream by a given buffer distance, and output the results in GML." ],
  194. // ] ],
  195. // [ 'wps:Process', [ 'wps:processVersion' => "1.0.0" ], [
  196. // [ 'ows:Identifier', "JTS:area" ],
  197. // [ 'ows:Title', "Area" ],
  198. // [ '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." ],
  199. // ] ]
  200. // ]);
  201. $xmlWriter->h('wps:Languages', [
  202. [ 'wps:Default', [
  203. [ 'ows:Language', "en-GB" ],
  204. ] ],
  205. [ 'wps:Supported', [
  206. [ 'ows:Language', "pl-PL" ],
  207. ] ]
  208. ]);
  209. // $xmlWriter->h('wps:Contents', [
  210. // [ 'wps:ProcessSummary', [ 'jobControlOptions' => "sync-execute async-execute dismiss" ], [
  211. // [ 'ows:Title', "example 1" ],
  212. // [ 'ows:Identifier', "{$wpsServerUrl}/task/example1" ],
  213. // ] ],
  214. // [ 'wps:ProcessSummary', [ 'jobControlOptions' => "async-execute dismiss", 'processVersion' => "1.4.0" ], [
  215. // [ 'ows:Title', "example 2" ],
  216. // [ 'ows:Identifier', "{$wpsServerUrl}/task/example2" ],
  217. // ] ],
  218. // ]);
  219. // $xmlWriter->h('wps:WSDL', [ 'xlink:href' => "http://foo.bar/wps?WSDL" ], null);
  220. $xmlWriter->endElement();// WFS_Capabilities
  221. $xmlWriter->endDocument();
  222. exit;
  223. }
  224. }