superedit-OPEN_LAYERS_WPS.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. <?php
  2. /**
  3. * http://openlayers.org/dev/examples/wps.html
  4. * http://geoinformatyka.com.pl/usluga-wfs-jak-to-dziala/
  5. *
  6. * TODO: brak ModifyFeature - html btn: olControlModifyFeatureItemInactive
  7. */
  8. function OPEN_LAYERS_WPS() {
  9. $task = V::get('task', '', $_GET);
  10. switch ($task) {
  11. case 'proxy': {
  12. $url = V::get('url', '', $_GET);
  13. // 1. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DGetCapabilities
  14. // 2. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DDescribeProcess%26VERSION%3D1.0.0%26IDENTIFIER%3Dpozdrawiam
  15. header('Content-Type: application/xml; charset=utf-8');
  16. $urlParts = parse_url($url);
  17. $urlQuery = array();
  18. $urlQueryTmp = V::get('query', '', $urlParts);
  19. $urlQueryTmp = explode('&', $urlQueryTmp);
  20. foreach ($urlQueryTmp as $vQuery) {
  21. $parts = explode('=', $vQuery, 2);
  22. $urlQuery[$parts[0]] = $parts[1];
  23. }
  24. if ('WPS' == V::get('SERVICE', '', $urlQuery)) {
  25. $req = V::get('REQUEST', '', $urlQuery);
  26. $wps = new WpsServer();
  27. $methodName = "{$req}Action";
  28. if (method_exists($wps, $methodName)) {
  29. $wps->$methodName($urlQuery);
  30. }
  31. }
  32. else {
  33. $wps = new WpsServer();
  34. $wps->parseXMLRequest();
  35. }
  36. exit;
  37. break;
  38. }
  39. case 'import_from_postgis': {
  40. $gis_zas_id = 13102;
  41. $pgDB = DB::getDB($gis_zas_id);
  42. $db = DB::getDB();
  43. // POSTGIS_to_MYSQL_Tables('BUILDINGS','geoportal_gml_punkty_adr_gml_id','MK_Budynki','geoportal_gml_punkty_adr_gml_id');
  44. // function POSTGIS_to_MYSQL_Tables($local_table_mysql,$local_key,$remote_table_postgis,$remote_key){
  45. // global $db,$gdb;
  46. $local_table_mysql = 'BUILDINGS';
  47. $local_key = 'geoportal_gml_punkty_adr_gml_id';
  48. $remote_table_postgis = 'MK_Budynki';
  49. $remote_key = 'geoportal_gml_punkty_adr_gml_id';
  50. // BUG: ST_AsEWKT @see http://postgis.org/docs/ST_AsEWKT.html
  51. $pgSql = <<<SQL
  52. select "{$remote_key}"
  53. -- , ST_AsEWKT(the_geom) as the_geom -- The WKT spec does not include the SRID. To get the OGC WKT format use ST_AsText
  54. , ST_AsText(the_geom) as the_geom
  55. from "{$remote_table_postgis}"
  56. where "{$remote_key}"!=''
  57. and "{$remote_key}" is not null
  58. and the_geom != ''
  59. and the_geom is not null
  60. SQL;
  61. $pgRes = $pgDB->query($pgSql);
  62. echo '<pre>';
  63. echo "Start...\n";
  64. while ($r = $pgDB->fetch($pgRes)) {
  65. $r->{$remote_key} = trim($r->{$remote_key});
  66. $sql = "update `{$local_table_mysql}` set `the_geom`=GeomFromText('{$r->the_geom}')
  67. where `{$local_key}`='{$r->$remote_key}'
  68. and `{$local_key}`!=''
  69. and `{$local_key}` is not null
  70. and (`the_geom`='' or `the_geom` is null)
  71. ";
  72. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';
  73. echo "Fethed remote_key: {$remote_key}={$r->$remote_key}| ";
  74. $testRow = null;
  75. $testSql = "select t.`ID`, t.`{$local_key}`, AsWKT(t.`the_geom`) as the_geom from `{$local_table_mysql}` as t where t.`{$local_key}`='{$r->$remote_key}' ";
  76. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">testSql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($testSql);echo'</pre>';
  77. $testRes = $db->query($testSql);
  78. if ($testRow = $db->fetch($testRes)) {
  79. echo " mysql row exists in table `{$local_table_mysql}` (ID={$testRow->ID}) ";
  80. echo " | the_geom is ";
  81. echo (!empty($testRow->the_geom))? " set " : " not set ";
  82. } else {
  83. echo " mysql row not exists in table `{$local_table_mysql}`! ";
  84. }
  85. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid green;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($testRow);echo'</pre>';
  86. $res = $db->query($sql);
  87. if (!$res) {
  88. echo "| ERROR: problem with query!";
  89. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;display:none"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';
  90. }
  91. else {
  92. echo "| done ";
  93. }
  94. echo "\n";
  95. }
  96. echo '</pre>';
  97. break;
  98. }
  99. default:
  100. }
  101. //$_POST['url'] = 'http://demo.opengeo.org/geoserver/wfs';
  102. //$entityBody = file_get_contents('php://input');
  103. $url = V::get('_url', '', $_GET);
  104. if ($url) {// @see OpenLayers/examples/proxy.cgi
  105. $allowedHosts = array('www.openlayers.org', 'openlayers.org',
  106. 'labs.metacarta.com', 'world.freemap.in',
  107. 'prototype.openmnnd.org', 'geo.openplans.org',
  108. 'sigma.openplans.org', 'demo.opengeo.org',
  109. 'www.openstreetmap.org', 'sample.azavea.com',
  110. 'v2.suite.opengeo.org', 'v-swe.uni-muenster.de:8080',
  111. 'vmap0.tiles.osgeo.org', 'www.openrouteservice.org',
  112. 'maps.wien.gv.at');
  113. if (!empty($_POST)) {
  114. // qs = os.environ["QUERY_STRING"]
  115. // d = cgi.parse_qs(qs)
  116. // if d.has_key("url"):
  117. // url = d["url"][0]
  118. // else:
  119. // url = "http://www.openlayers.org"
  120. }
  121. else {
  122. // fs = cgi.FieldStorage()
  123. // url = fs.getvalue('url', "http://www.openlayers.org")
  124. }
  125. $host = explode('/', $url);
  126. $host = $host[2];
  127. if (!in_array($host, $allowedHosts)) {
  128. header("Status: 502 Bad Gateway");
  129. header("Content-Type: text/plain");
  130. echo "\nThis proxy does not allow you to access that location ({$host}).";
  131. exit;
  132. }
  133. else if (substr($url, 0, 7) == 'http://' || substr($url, 0, 8) == 'https://') {
  134. $ch = curl_init();
  135. if (!empty($_POST)) {
  136. /*
  137. length = int(os.environ["CONTENT_LENGTH"])
  138. headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
  139. body = sys.stdin.read(length)
  140. r = urllib2.Request(url, body, headers)
  141. y = urllib2.urlopen(r)
  142. */
  143. }
  144. else {
  145. curl_setopt($ch, CURLOPT_URL, $url);
  146. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// return the transfer as a string
  147. //curl_setopt($ch, CURLOPT_VERBOSE, 1);
  148. curl_setopt($ch, CURLOPT_HEADER, 1);
  149. $response = curl_exec($ch);
  150. // Then, after your curl_exec call:
  151. $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  152. $header = substr($response, 0, $header_size);
  153. $body = substr($response, $header_size);
  154. curl_close($ch);
  155. $contentType = 'text/plain';
  156. $headers = explode("\n", $header);
  157. foreach ($headers as $vHeader) {
  158. if (substr($vHeader, 0, 13) == 'Content-Type:') {
  159. $contentType = trim(substr($vHeader, 14));
  160. }
  161. }
  162. header("Content-Type: {$contentType}");
  163. echo $body . "\n";
  164. }
  165. }
  166. else {
  167. header("Content-Type: text/plain");
  168. echo "\nIllegal request.";
  169. exit;
  170. }
  171. exit;
  172. }
  173. ?>
  174. <link rel="stylesheet" href="stuff/open-layers/theme/default/style.css" type="text/css">
  175. <link rel="stylesheet" href="stuff/open-layers/style.css" type="text/css">
  176. <style type="text/css">
  177. .olControlEditingToolbar .olControlModifyFeatureItemInactive {
  178. background-image: url(stuff/open-layers/theme/default/img/draw_point_off.png);
  179. }
  180. .olControlEditingToolbar .olControlModifyFeatureItemActive {
  181. background-image: url(stuff/open-layers/theme/default/img/draw_point_on.png);
  182. }
  183. .olControlRefresh {
  184. background-image: url(stuff/open-layers/theme/default/img/save_features_off.png);
  185. }
  186. .olControlZoomToPoly {
  187. background-image: url(stuff/open-layers/theme/default/img/ruler.png);
  188. }
  189. .olControlLayerSwitcher .layersDiv {
  190. border-radius: 10px 0 0 10px;
  191. opacity: 0.75;
  192. filter: alpha(opacity=75);
  193. }
  194. textarea {
  195. display: block;
  196. width: 100%;
  197. height: 3em;
  198. }
  199. label {
  200. display: block;
  201. }
  202. .notsupported {
  203. color: red;
  204. }
  205. button {
  206. display: block;
  207. margin-top: 10px;
  208. }
  209. </style>
  210. <div id="TreeTableMap"></div>
  211. <script src="stuff/open-layers/OpenLayers.js"></script>
  212. <!-- <script src="stuff/open-layers/wps.js"></script> -->
  213. <script>
  214. (function ( $ ) {
  215. var TableAjaxMap = function() {
  216. var priv = {}; //private api
  217. var publ = {}; //public api
  218. priv.options = {};
  219. var defaults = {
  220. wpsUrl: '',
  221. wfsUrl: '',
  222. domProcessId: '',
  223. urlInit: true, // try to load services on init
  224. preloadData: null,
  225. menuid: '',
  226. debug: false
  227. };
  228. var _nodeMapId;
  229. var _nodeMap;
  230. var _nodeProcesses;
  231. var _nodeAbstract;
  232. var _nodeInput;
  233. var _nodeOutput;
  234. var _capabilities;
  235. var _process;
  236. var _layer;
  237. /*
  238. initialize the plugin.
  239. */
  240. priv.init = function() {
  241. console.log('test jQuery plugin init...', priv);
  242. // create dom:
  243. /*
  244. <div id="map" class="smallmap"></div>
  245. <div>
  246. <select id="processes"><option>Select a process</option></select>
  247. <p id="abstract"></p>
  248. <div id="input"></div>
  249. <div id="output"></div>
  250. </div>
  251. */
  252. _nodeMapId = 'Map-' + Math.random(1).toString().substr(2);
  253. _nodeMap = $('<div id="' + _nodeMapId + '" class="smallmap"></div>');
  254. _nodeProcesses = $('<select></select>');
  255. _nodeProcesses.append('<option>Wybierz funkcję</option>');
  256. _nodeAbstract = $('<p></p>');
  257. _nodeInput = $('<div></div>');
  258. _nodeOutput = $('<div></div>');
  259. var div = $('<div></div>');
  260. div.append(_nodeProcesses);
  261. div.append(_nodeAbstract);
  262. div.append(_nodeInput);
  263. div.append(_nodeOutput);
  264. $(priv.options.id).append(_nodeMap);
  265. $(priv.options.id).append(div);
  266. _nodeProcesses.on('change', function() {
  267. console.log("onchange this:", this, this.selectedIndex, this.options);
  268. var selection = this.options[this.selectedIndex].value;
  269. if (this.selectedIndex > 0) {
  270. OpenLayers.Request.GET({
  271. url: priv.options.wpsUrl,
  272. params: {
  273. "SERVICE": "WPS",
  274. "REQUEST": "DescribeProcess",
  275. "VERSION": _capabilities.version,
  276. "IDENTIFIER": selection
  277. },
  278. success: function(response) {
  279. _process = new OpenLayers.Format.WPSDescribeProcess().read(
  280. response.responseText
  281. ).processDescriptions[selection];
  282. console.log("Process:", _process);
  283. priv.buildForm();
  284. }
  285. });
  286. }
  287. });
  288. priv.getCapabilities();
  289. var style = new OpenLayers.Style();
  290. var rule = new OpenLayers.Rule({
  291. symbolizer: {strokeWidth: 4}
  292. });
  293. style.addRules([rule]);
  294. _layer = new OpenLayers.Layer.Vector("Warstwa rysowania", {
  295. strategies: [new OpenLayers.Strategy.BBOX()],
  296. projection: new OpenLayers.Projection("EPSG:4326"),
  297. styleMap: new OpenLayers.StyleMap(style),
  298. protocol: new OpenLayers.Protocol.WFS({
  299. version: "1.1.0",
  300. srsName: "EPSG:4326",
  301. url: priv.options.wfsUrl,
  302. featureNS : "http://opengeo.org",
  303. featureType: "restricted",
  304. geometryName: "the_geom",
  305. schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=og:restricted"
  306. })
  307. });
  308. var toolbar = new OpenLayers.Control.EditingToolbar(_layer);
  309. toolbar.addControls([new OpenLayers.Control.ModifyFeature(_layer, {
  310. title: "Wybierz",
  311. mode: OpenLayers.Control.ModifyFeature.DRAG | OpenLayers.Control.ModifyFeature.RESHAPE
  312. })]);
  313. var btnZoomToPoly = new OpenLayers.Control.Button({
  314. displayClass: "olControlZoomToPoly",
  315. title: "Zbliz",
  316. trigger:
  317. function() {
  318. var multiPolygon = OpenLayers.Geometry.fromWKT(
  319. "MULTIPOLYGON(((2072016.74395199 7234076.79293037,2072016.74395199 7234115.01144451,2072131.3994944 7234115.01144451,2072131.3994944 7234076.79293037,2072016.74395199 7234076.79293037)))"
  320. ).getBounds();
  321. map.zoomToExtent(multiPolygon);
  322. }
  323. });
  324. toolbar.addControls([btnZoomToPoly]);
  325. var btnRefresh = new OpenLayers.Control.Button({
  326. displayClass: "olControlRefresh",
  327. title: "Odswiez",
  328. trigger:
  329. function() {
  330. _layer.refresh({force:true});
  331. }
  332. });
  333. toolbar.addControls([btnRefresh]);
  334. var deleteFeatureControl = new OpenLayers.Control.SelectFeature(_layer, OpenLayers.Handler.Path, {
  335. clickout: false,
  336. toggle: false,
  337. displayClass: "olControlDelete",
  338. title: "Usun"
  339. });
  340. deleteFeatureControl.events.register("featurehighlighted", this, function(e) {
  341. if (confirm('Czy na pewno chcesz usunąć ten obiekt?')) {
  342. _layer.removeFeatures([e.feature]);
  343. deleteFeatureControl.deactivate();
  344. } else {
  345. deleteFeatureControl.unselect(e.feature);
  346. }
  347. });
  348. toolbar.addControls([deleteFeatureControl]);
  349. var extent = new OpenLayers.Bounds(
  350. 2035059.4410645328, 7200979.560689885, 2113330.958028555, 7279251.0776539035
  351. );
  352. var gphy = new OpenLayers.Layer.OSM("Mapa", null, {
  353. resolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
  354. 19567.87923828125, 9783.939619140625, 4891.9698095703125,
  355. 2445.9849047851562, 1222.9924523925781, 611.4962261962891,
  356. 305.74811309814453, 152.87405654907226, 76.43702827453613,
  357. 38.218514137268066, 19.109257068634033, 9.554628534317017,
  358. 4.777314267158508, 2.388657133579254, 1.194328566789627,
  359. 0.5971642833948135, 0.25, 0.1, 0.05],
  360. serverResolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
  361. 19567.87923828125, 9783.939619140625,
  362. 4891.9698095703125, 2445.9849047851562,
  363. 1222.9924523925781, 611.4962261962891,
  364. 305.74811309814453, 152.87405654907226,
  365. 76.43702827453613, 38.218514137268066,
  366. 19.109257068634033, 9.554628534317017,
  367. 4.777314267158508, 2.388657133579254,
  368. 1.194328566789627, 0.5971642833948135],
  369. transitionEffect: 'resize'
  370. });
  371. var map = new OpenLayers.Map(_nodeMapId, {
  372. projection: new OpenLayers.Projection("EPSG:4326"),
  373. displayProjection: new OpenLayers.Projection("EPSG:4326"),
  374. restrictedExtent: extent,
  375. controls: [
  376. toolbar,
  377. new OpenLayers.Control.ZoomPanel(),
  378. new OpenLayers.Control.PanPanel(),
  379. new OpenLayers.Control.LayerSwitcher(),
  380. new OpenLayers.Control.ScaleLine(),
  381. new OpenLayers.Control.KeyboardDefaults()
  382. // new OpenLayers.Control.MousePosition()
  383. ], layers: [gphy,_layer]
  384. });
  385. map.zoomToMaxExtent();
  386. };
  387. // using OpenLayers.Format.WPSCapabilities to read the capabilities
  388. priv.getCapabilities = function() {
  389. OpenLayers.Request.GET({
  390. url: priv.options.wpsUrl,
  391. params: {
  392. "SERVICE": "WPS",
  393. "REQUEST": "GetCapabilities"
  394. },
  395. success: function(response){
  396. _capabilities = new OpenLayers.Format.WPSCapabilities().read(
  397. response.responseText
  398. );
  399. var dropdown = _nodeProcesses;
  400. var offerings = _capabilities.processOfferings, option;
  401. // populate the dropdown
  402. for (var p in offerings) {
  403. option = document.createElement("option");
  404. option.innerHTML = offerings[p].identifier;
  405. option.value = p;
  406. dropdown.append(option);
  407. }
  408. }
  409. });
  410. };
  411. priv.buildForm = function() {
  412. _nodeAbstract.html(_process["abstract"]);
  413. _nodeInput.html("<h3>Input:</h3>");
  414. _nodeOutput.html('');
  415. var inputs = _process.dataInputs, supported = true,
  416. sld = "text/xml; subtype=sld/1.0.0",
  417. input;
  418. for (var i = 0, ii = inputs.length; i < ii; ++i) {
  419. input = inputs[i];
  420. if (input.complexData) {
  421. var formats = input.complexData.supported.formats;
  422. if (formats["application/wkt"]) {
  423. priv.addWKTInput(input);
  424. } else if (formats["text/xml; subtype=wfs-collection/1.0"]) {
  425. priv.addWFSCollectionInput(input);
  426. } else if (formats["image/tiff"]) {
  427. //priv.addRasterInput(input);
  428. } else if (formats[sld]) {
  429. priv.addXMLInput(input, sld);
  430. } else {
  431. supported = false;
  432. }
  433. } else if (input.boundingBoxData) {
  434. priv.addBoundingBoxInput(input);
  435. } else if (input.literalData) {
  436. priv.addLiteralInput(input);
  437. } else {
  438. supported = false;
  439. }
  440. if (input.minOccurs > 0) {
  441. _nodeInput.append(document.createTextNode("* "));
  442. }
  443. }
  444. if (supported) {
  445. var executeButton = document.createElement("button");
  446. executeButton.innerHTML = "Execute";
  447. _nodeInput.append(executeButton);
  448. executeButton.onclick = priv.execute;
  449. } else {
  450. _nodeInput.html('<span class="notsupported">' +
  451. "Sorry, the WPS builder does not support the selected process." +
  452. "</span>");
  453. }
  454. };
  455. // helper function to dynamically create a textarea for geometry (WKT) data
  456. // input
  457. priv.addWKTInput = function(input, previousSibling) {
  458. var name = input.identifier;
  459. var container = _nodeInput.get(0);
  460. var label = document.createElement("label");
  461. label["for"] = name;
  462. label.title = input["abstract"];
  463. label.innerHTML = name + " (select feature, then click field):";
  464. previousSibling && previousSibling.nextSibling ?
  465. container.insertBefore(label, previousSibling.nextSibling) :
  466. container.appendChild(label);
  467. var field = document.createElement("textarea");
  468. field.onclick = function () {
  469. if (_layer.selectedFeatures.length) {
  470. this.innerHTML = new OpenLayers.Format.WKT().write(
  471. _layer.selectedFeatures[0]
  472. );
  473. console.log('_layer.selectedFeatures[0]: ', _layer.selectedFeatures[0]);
  474. }
  475. priv.createCopy(input, this, priv.addWKTInput);
  476. };
  477. field.onblur = function() {
  478. input.data = field.value ? {
  479. complexData: {
  480. mimeType: "application/wkt",
  481. value: this.value
  482. }
  483. } : undefined;
  484. };
  485. field.title = input["abstract"];
  486. field.id = name;
  487. previousSibling && previousSibling.nextSibling ?
  488. container.insertBefore(field, previousSibling.nextSibling.nextSibling) :
  489. container.appendChild(field);
  490. };
  491. // helper function for xml input
  492. priv.addXMLInput = function(input, type) {
  493. var name = input.identifier;
  494. var field = document.createElement("input");
  495. field.title = input["abstract"];
  496. field.value = name + " (" + type + ")";
  497. field.onblur = function() {
  498. input.data = field.value ? {
  499. complexData: {
  500. mimeType: type,
  501. value: this.value
  502. }
  503. } : undefined;
  504. };
  505. _nodeInput.append(field);
  506. };
  507. // helper function to dynamically create a WFS collection reference input
  508. priv.addWFSCollectionInput = function(input) {
  509. var name = input.identifier;
  510. var field = document.createElement("input");
  511. field.title = input["abstract"];
  512. field.value = name + " (layer on demo server)";
  513. priv.addValueHandlers(field, function() {
  514. input.reference = field.value ? {
  515. mimeType: "text/xml; subtype=wfs-collection/1.0",
  516. href: "http://geoserver/wfs",
  517. method: "POST",
  518. body: {
  519. wfs: {
  520. version: "1.0.0",
  521. outputFormat: "GML2",
  522. featureType: field.value
  523. }
  524. }
  525. } : undefined;
  526. });
  527. _nodeInput.append(field);
  528. };
  529. // helper function to dynamically create a raster (GeoTIFF) url input
  530. priv.addRasterInput = function(input) {
  531. var name = input.identifier;
  532. var field = document.createElement("input");
  533. field.title = input["abstract"];
  534. var url = window.location.href.split("?")[0];
  535. field.value = url.substr(0, url.lastIndexOf("/")+1) + "data/tazdem.tiff";// TODO: file path to options
  536. document.getElementById("input").appendChild(field);
  537. (field.onblur = function() {
  538. input.reference = {
  539. mimeType: "image/tiff",
  540. href: field.value,
  541. method: "GET"
  542. };
  543. })();
  544. };
  545. // helper function to dynamically create a bounding box input
  546. priv.addBoundingBoxInput = function(input) {
  547. var name = input.identifier;
  548. var field = document.createElement("input");
  549. field.title = input["abstract"];
  550. field.value = "left,bottom,right,top (EPSG:4326)";
  551. _nodeInput.append(field);
  552. priv.addValueHandlers(field, function() {
  553. input.boundingBoxData = {
  554. projection: "EPSG:4326",
  555. bounds: OpenLayers.Bounds.fromString(field.value)
  556. };
  557. });
  558. };
  559. // helper function to create a literal input textfield or dropdown
  560. priv.addLiteralInput = function(input, previousSibling) {
  561. var name = input.identifier;
  562. var container = _nodeInput.get(0);
  563. var anyValue = input.literalData.anyValue;
  564. // anyValue means textfield, otherwise we create a dropdown
  565. var field = document.createElement(anyValue ? "input" : "select");
  566. field.id = name;
  567. field.title = input["abstract"];
  568. previousSibling && previousSibling.nextSibling ?
  569. container.insertBefore(field, previousSibling.nextSibling) :
  570. container.appendChild(field);
  571. if (anyValue) {
  572. var dataType = input.literalData.dataType;
  573. field.value = name + (dataType ? " (" + dataType + ")" : "");
  574. priv.addValueHandlers(field, function() {
  575. input.data = field.value ? {
  576. literalData: {
  577. value: field.value
  578. }
  579. } : undefined;
  580. priv.createCopy(input, field, priv.addLiteralInput);
  581. });
  582. } else {
  583. var option;
  584. option = document.createElement("option");
  585. option.innerHTML = name;
  586. field.appendChild(option);
  587. for (var v in input.literalData.allowedValues) {
  588. option = document.createElement("option");
  589. option.value = v;
  590. option.innerHTML = v;
  591. field.appendChild(option);
  592. }
  593. field.onchange = function() {
  594. priv.createCopy(input, field, priv.addLiteralInput);
  595. input.data = this.selectedIndex ? {
  596. literalData: {
  597. value: this.options[this.selectedIndex].value
  598. }
  599. } : undefined;
  600. };
  601. }
  602. };
  603. // if maxOccurs is > 1, this will add a copy of the field
  604. priv.createCopy = function(input, field, fn) {
  605. if (input.maxOccurs && input.maxOccurs > 1 && !field.userSelected) {
  606. // add another copy of the field - we don't check maxOccurs
  607. field.userSelected = true;
  608. var newInput = OpenLayers.Util.extend({}, input);
  609. // we recognize copies by the occurrence property
  610. newInput.occurrence = (input.occurrence || 0) + 1;
  611. _process.dataInputs.push(newInput);
  612. fn(newInput, field);
  613. }
  614. };
  615. // helper function for adding events to form fields
  616. priv.addValueHandlers = function(field, onblur) {
  617. field.onclick = function() {
  618. if (!this.initialValue) {
  619. this.initialValue = this.value;
  620. this.value = "";
  621. }
  622. };
  623. field.onblur = function() {
  624. if (!this.value) {
  625. this.value = this.initialValue;
  626. delete this.initialValue;
  627. }
  628. onblur.apply(this, arguments);
  629. };
  630. };
  631. // execute the process
  632. priv.execute = function() {
  633. var output = _process.processOutputs[0];
  634. var input;
  635. // remove occurrences that the user has not filled out
  636. for (var i = _process.dataInputs.length - 1; i >= 0; --i) {
  637. input = _process.dataInputs[i];
  638. if ((input.minOccurs === 0 || input.occurrence) && !input.data && !input.reference) {
  639. OpenLayers.Util.removeItem(_process.dataInputs, input);
  640. }
  641. }
  642. _process.responseForm = {
  643. rawDataOutput: {
  644. identifier: output.identifier
  645. }
  646. };
  647. if (output.complexOutput && output.complexOutput.supported.formats["application/wkt"]) {
  648. _process.responseForm.rawDataOutput.mimeType = "application/wkt";
  649. }
  650. OpenLayers.Request.POST({
  651. url: priv.options.wpsUrl,
  652. data: new OpenLayers.Format.WPSExecute().write(_process),
  653. success: priv.showOutput
  654. });
  655. }
  656. // add the process's output to the page
  657. priv.showOutput = function(response) {
  658. var result = _nodeOutput.get(0);
  659. result.innerHTML = "<h3>Output:</h3>";
  660. var features;
  661. var contentType = response.getResponseHeader("Content-Type");
  662. if (contentType == "application/wkt") {
  663. features = new OpenLayers.Format.WKT().read(response.responseText);
  664. } else if (contentType == "text/xml; subtype=wfs-collection/1.0") {
  665. features = new OpenLayers.Format.WFST.v1_0_0().read(response.responseText);
  666. }
  667. if (features && (features instanceof OpenLayers.Feature.Vector || features.length)) {
  668. _layer.addFeatures(features);
  669. result.innerHTML += "The result should also be visible on the map.";
  670. }
  671. result.innerHTML += "<textarea>" + response.responseText + "</textarea>";
  672. }
  673. publ.init = function(options) {
  674. if (priv.options.debug) console.log('TableAjaxMap initialization...');
  675. //merge supplied options with defaults
  676. $.extend(priv.options, defaults, options);
  677. priv.init();
  678. return publ;
  679. };
  680. return publ;
  681. };
  682. $.fn.TableAjaxMap = function(options) {
  683. options = options || {};
  684. return this.each(function() {
  685. options.id = this;
  686. $(this).data('TableAjaxMap', new TableAjaxMap().init(options));
  687. });
  688. return this;
  689. };
  690. }(jQuery));
  691. </script>
  692. <script>
  693. OpenLayers.ProxyHost = "index.php?FUNCTION_INIT=<?php echo __FUNCTION__; ?>&HEADER_NOT_INIT=YES&task=proxy&url=";
  694. jQuery('#TreeTableMap').TableAjaxMap({
  695. wpsUrl: 'http://biuro.biall-net.pl/wps',
  696. wfsUrl: 'http://biuro.biall-net.pl/wps'
  697. });
  698. </script>
  699. <?php
  700. }
  701. class WpsActionBase {
  702. public $title = '';
  703. public $description = '';
  704. public $dataInputs = array();
  705. public function execute($args) {
  706. var_dump($args);
  707. }
  708. }
  709. class WpsActionPrzypiszDoRekordu extends WpsActionBase {
  710. public function __construct() {
  711. $this->title = 'Przypisz';
  712. $this->description = 'Przypisuje położenie do wybranego rekordu w tabeli.';
  713. $this->dataInputs['geom'] = new stdClass();
  714. $this->dataInputs['geom']->title = 'geom';
  715. $this->dataInputs['geom']->description = 'Input geometry';
  716. $this->dataInputs['geom']->type = 'geom';// CoomplexData
  717. $this->dataInputs['idTable'] = new stdClass();
  718. $this->dataInputs['idTable']->title = 'geom';
  719. $this->dataInputs['idTable']->description = 'Table ID';
  720. $this->dataInputs['idTable']->type = 'integer';// LiteralData: xs:integer
  721. $this->dataInputs['idRecord'] = new stdClass();
  722. $this->dataInputs['idRecord']->title = 'idRecord';
  723. $this->dataInputs['idRecord']->description = 'Record ID';
  724. $this->dataInputs['idRecord']->type = 'integer';// LiteralData: xs:integer
  725. }
  726. }
  727. class WfsAction {
  728. /**
  729. * example: MULTIPOLYGON(((2072016.74395199 7234076.79293037,2072016.74395199 7234115.01144451,2072131.3994944 7234115.01144451,2072131.3994944 7234076.79293037,2072016.74395199 7234076.79293037)))
  730. */
  731. public function generateGmlFromWKT($wkt) {
  732. $gml = '';
  733. $wktParts = explode('(', $wkt, 2);
  734. ob_start();
  735. switch ($wktParts[0]) {
  736. case 'MULTIPOLYGON':
  737. case 'POLYGON': {
  738. $points = trim($wktParts[1], '() ');
  739. $points = str_replace(',', "\n", $points);
  740. ?>
  741. <gml:boundedBy>
  742. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  743. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  744. <gml:upperCorner>180 90</gml:upperCorner>
  745. </gml:Envelope>
  746. </gml:boundedBy>
  747. <og:the_geom>
  748. <gml:MultiSurface srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  749. <gml:surfaceMember>
  750. <gml:Polygon srsDimension="2">
  751. <gml:exterior>
  752. <gml:LinearRing srsDimension="2">
  753. <gml:posList>
  754. <?php echo $points; ?>
  755. </gml:posList>
  756. </gml:LinearRing>
  757. </gml:exterior>
  758. </gml:Polygon>
  759. </gml:surfaceMember>
  760. </gml:MultiSurface>
  761. </og:the_geom>
  762. <?php
  763. }
  764. break;
  765. default:
  766. }
  767. $gml = ob_get_contents();
  768. ob_clean();
  769. return $gml;
  770. }
  771. public function execute($args) {
  772. /*
  773. * Mapa odczytywanie punktów: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
  774. *
  775. * CI50:
  776. 18.613243103027344 54.33614429135817
  777. 18.613243103027344 54.33634445792519
  778. 18.614273071289062 54.33634445792519
  779. 18.614273071289062 54.33614429135817
  780. */
  781. $tblId = 16;// `BUILDINGS`
  782. $buildingsGml = array();
  783. $db = DB::getDB();
  784. $sql = "select b.`ID`, AsWKT(b.`the_geom`) as the_geom
  785. from `BUILDINGS` as b
  786. where b.`the_geom` is not null and b.`the_geom`!=''
  787. limit 10;
  788. ";
  789. $res = $db->query($sql);
  790. while ($r = $db->fetch($res)) {
  791. $buildingsGml[$r->ID] = $this->generateGmlFromWKT($r->the_geom);
  792. }
  793. /**
  794. * <og:recordId><?php echo $kId; ?></og:recordId>
  795. * <og:tblId><?php echo $tblId; ?></og:tblId>
  796. *
  797. * goes to js: @see priv.addWKTInput _layer.selectedFeatures[0]
  798. *
  799. * attributes: Object
  800. recordId: "1130"
  801. tblId: "16"
  802. */
  803. echo '<?xml version="1.0" encoding="UTF-8"?>';
  804. ?>
  805. <wfs:FeatureCollection xmlns:nasa="http://nasa.gov" xmlns:topp="http://www.openplans.org/topp" xmlns:usgs="http://www.usgs.gov/" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:ne="http://naturalearthdata.com" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml" xmlns:osm="http://openstreemap.org" xmlns:nurc="http://www.nurc.nato.int" xmlns:og="http://opengeo.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="4" timeStamp="2014-07-16T13:22:43.307Z" xsi:schemaLocation="http://opengeo.org http://demo.opengeo.org:80/geoserver/wfs?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;typeName=og%3Arestricted http://www.opengis.net/wfs http://demo.opengeo.org:80/geoserver/schemas/wfs/1.1.0/wfs.xsd">
  806. <gml:boundedBy>
  807. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  808. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  809. <gml:upperCorner>180 90</gml:upperCorner>
  810. </gml:Envelope>
  811. </gml:boundedBy>
  812. <gml:featureMembers>
  813. <?php foreach ($buildingsGml as $kId => $vGml) : ?>
  814. <og:restricted gml:id="restricted.<?php echo $kId; ?>">
  815. <?php echo $vGml; ?>
  816. <og:recordId><?php echo $kId; ?></og:recordId>
  817. <og:tblId><?php echo $tblId; ?></og:tblId>
  818. </og:restricted>
  819. <?php endforeach; ?>
  820. </gml:featureMembers>
  821. </wfs:FeatureCollection>
  822. <?php
  823. }
  824. }
  825. class WpsServer {
  826. private $_fun;// config for identifiers
  827. public function __construct() {
  828. $this->_fun['przypiszDoRekordu'] = new WpsActionPrzypiszDoRekordu();
  829. $this->_wfsAction = new WfsAction();
  830. }
  831. public function parseXMLRequest() {
  832. $data = array();
  833. $reqContent = file_get_contents('php://input');
  834. $xml = new SimpleXMLElement($reqContent);
  835. if ('GetFeature' == $xml->getName()) {
  836. // TODO: parse xml and set query params
  837. $this->_wfsAction->execute($data);
  838. }
  839. else if (isset($xml->children('ows', TRUE)->Identifier)) {
  840. $identifier = (string)$xml->children('ows', TRUE)->Identifier;
  841. if (array_key_exists($identifier, $this->_fun)) {
  842. foreach ($xml->children('wps', TRUE)->DataInputs->children('wps', TRUE) as $input) {
  843. $inputIdentifier = (string)$input->children('ows', TRUE)->Identifier;
  844. if (array_key_exists($inputIdentifier, $this->_fun[$identifier]->dataInputs)) {
  845. $inputType = (string)$this->_fun[$identifier]->dataInputs[$inputIdentifier]->type;
  846. switch ($inputType) {
  847. case 'integer':
  848. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->LiteralData;
  849. break;
  850. case 'geom':
  851. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->ComplexData;
  852. break;
  853. default:
  854. }
  855. } else {
  856. // brak zdefiniowanego inputa
  857. }
  858. }
  859. $this->_fun['przypiszDoRekordu']->execute($data);
  860. } else {
  861. echo "TODO: brak zdefiniowanej funkcji '{$identifier}'";
  862. var_dump($identifier);
  863. }
  864. }
  865. else {
  866. echo "TODO: '" . $xml->getName() . "' ...";
  867. }
  868. }
  869. public function getCapabilitiesAction() {
  870. echo '<?xml version="1.0" encoding="UTF-8"?>';
  871. ?>
  872. <wps:Capabilities xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" 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">
  873. <ows:ServiceIdentification>
  874. <ows:Title>Prototype GeoServer WPS</ows:Title>
  875. <ows:Abstract />
  876. <ows:Keywords>
  877. <ows:Keyword>wps</ows:Keyword>
  878. <ows:Keyword>geoserver</ows:Keyword>
  879. </ows:Keywords>
  880. <ows:ServiceType>WPS</ows:ServiceType>
  881. <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
  882. <ows:Fees>NONE</ows:Fees>
  883. <ows:AccessConstraints>NONE</ows:AccessConstraints>
  884. </ows:ServiceIdentification>
  885. <ows:ServiceProvider>
  886. <ows:ProviderName>GeoServer</ows:ProviderName>
  887. <ows:ProviderSite />
  888. <ows:ServiceContact />
  889. </ows:ServiceProvider>
  890. <ows:OperationsMetadata>
  891. <ows:Operation name="GetCapabilities">
  892. <ows:DCP>
  893. <ows:HTTP>
  894. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  895. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  896. </ows:HTTP>
  897. </ows:DCP>
  898. </ows:Operation>
  899. <ows:Operation name="DescribeProcess">
  900. <ows:DCP>
  901. <ows:HTTP>
  902. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  903. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  904. </ows:HTTP>
  905. </ows:DCP>
  906. </ows:Operation>
  907. <ows:Operation name="Execute">
  908. <ows:DCP>
  909. <ows:HTTP>
  910. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  911. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  912. </ows:HTTP>
  913. </ows:DCP>
  914. </ows:Operation>
  915. </ows:OperationsMetadata>
  916. <wps:ProcessOfferings>
  917. <?php foreach($this->_fun as $kFun => $vFun) : ?>
  918. <wps:Process wps:processVersion="1.0.0">
  919. <ows:Identifier><?php echo $kFun; ?></ows:Identifier>
  920. <ows:Title><?php echo $vFun->title; ?></ows:Title>
  921. <ows:Abstract><?php echo $vFun->description; ?></ows:Abstract>
  922. </wps:Process>
  923. <?php endforeach; ?>
  924. </wps:ProcessOfferings>
  925. <wps:Languages>
  926. <wps:Default>
  927. <ows:Language>en-US</ows:Language>
  928. </wps:Default>
  929. <wps:Supported>
  930. <ows:Language>en-US</ows:Language>
  931. </wps:Supported>
  932. </wps:Languages>
  933. </wps:Capabilities>
  934. <?php
  935. }
  936. public function describeProcessAction($args) {
  937. // TODO: xml z opiesem procese $args['IDENTIFIER']
  938. /**
  939. * should work like JTS:densify - geom field (map object) and integer field (record ID)
  940. * http://openlayers.org/dev/examples/proxy.cgi?url=http%3A%2F%2Fdemo.opengeo.org%2Fgeoserver%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DDescribeProcess%26VERSION%3D1.0.0%26IDENTIFIER%3DJTS%253Adensify
  941. * http://demo.opengeo.org/geoserver/wps?SERVICE=WPS&REQUEST=DescribeProcess&VERSION=1.0.0&IDENTIFIER=JTS%3Adensify
  942. */
  943. echo '<?xml version="1.0" encoding="UTF-8"?>';
  944. if (array_key_exists($args['IDENTIFIER'], $this->_fun)) {
  945. $identifier = $this->_fun[$args['IDENTIFIER']];
  946. ?>
  947. <wps:ProcessDescriptions xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" 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">
  948. <ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true">
  949. <ows:Identifier><?php echo $args['IDENTIFIER']; ?></ows:Identifier>
  950. <ows:Title><?php echo $identifier->title; ?></ows:Title>
  951. <ows:Abstract><?php echo $identifier->description; ?></ows:Abstract>
  952. <DataInputs>
  953. <?php foreach ($identifier->dataInputs as $kInput => $vInput) : ?>
  954. <Input maxOccurs="1" minOccurs="1">
  955. <ows:Identifier><?php echo $kInput; ?></ows:Identifier>
  956. <ows:Title><?php echo $vInput->title; ?></ows:Title>
  957. <ows:Abstract><?php echo $vInput->description; ?></ows:Abstract>
  958. <?php if ($vInput->type == 'geom') : ?>
  959. <ComplexData>
  960. <Default>
  961. <Format>
  962. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  963. </Format>
  964. </Default>
  965. <Supported>
  966. <Format>
  967. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  968. </Format>
  969. <Format>
  970. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  971. </Format>
  972. <Format>
  973. <MimeType>application/wkt</MimeType>
  974. </Format>
  975. <Format>
  976. <MimeType>application/gml-3.1.1</MimeType>
  977. </Format>
  978. <Format>
  979. <MimeType>application/gml-2.1.2</MimeType>
  980. </Format>
  981. </Supported>
  982. </ComplexData>
  983. <?php elseif ($vInput->type == 'integer') : ?>
  984. <LiteralData>
  985. <ows:DataType>xs:integer</ows:DataType>
  986. <ows:AnyValue />
  987. </LiteralData>
  988. <?php else : ?>
  989. <?php endif; ?>
  990. </Input>
  991. <?php endforeach; ?>
  992. </DataInputs>
  993. <ProcessOutputs>
  994. <Output>
  995. <ows:Identifier>result</ows:Identifier>
  996. <ows:Title>result</ows:Title>
  997. <ComplexOutput>
  998. <Default>
  999. <Format>
  1000. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1001. </Format>
  1002. </Default>
  1003. <Supported>
  1004. <Format>
  1005. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1006. </Format>
  1007. <Format>
  1008. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  1009. </Format>
  1010. <Format>
  1011. <MimeType>application/wkt</MimeType>
  1012. </Format>
  1013. <Format>
  1014. <MimeType>application/gml-3.1.1</MimeType>
  1015. </Format>
  1016. <Format>
  1017. <MimeType>application/gml-2.1.2</MimeType>
  1018. </Format>
  1019. </Supported>
  1020. </ComplexOutput>
  1021. </Output>
  1022. </ProcessOutputs>
  1023. </ProcessDescription>
  1024. </wps:ProcessDescriptions>
  1025. <?php
  1026. } else {
  1027. echo 'TODO: brak funkcji';
  1028. }
  1029. }
  1030. }