WfsServer.php 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615
  1. <?php
  2. Lib::loadClass('Api_WfsException');
  3. Lib::loadClass('Api_WfsGeomTypeConverter');
  4. class Api_WfsServer {
  5. private $_usrAcl;
  6. private $_typeConverter;
  7. public function __construct($usrAcl) {
  8. $this->_usrAcl = $usrAcl;
  9. $this->_typeConverter = new Api_WfsGeomTypeConverter();
  10. }
  11. public function parseXMLRequest() {
  12. $data = array();
  13. $reqContent = file_get_contents('php://input');
  14. if (empty($reqContent)) {
  15. throw new Exception("Empty request");
  16. }
  17. $parserXml = xml_parser_create();
  18. xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
  19. xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
  20. if (0 == xml_parse_into_struct($parserXml, $reqContent, $tags)) {
  21. throw new Exception("Error parsing xml");
  22. }
  23. xml_parser_free($parserXml);
  24. if (empty($tags)) {
  25. throw new Exception("Empty structure from request");
  26. }
  27. $rootTagName = V::get('tag', '', $tags[0]);
  28. if ('Transaction' == $rootTagName) {
  29. return $this->_parseTransactionXmlStruct($reqContent, $tags);
  30. }
  31. throw new Api_WfsException("TODO ... L." . __LINE__, 501);
  32. $xml = new SimpleXMLElement($reqContent);
  33. $namespaces = $xml->getNameSpaces(true);
  34. if ('Transaction' == $xml->getName()) {
  35. $this->_parseTransactionXml($xml);
  36. }
  37. else {
  38. throw new Api_WfsException("Not Implemented " . htmlspecialchars($xml->getName()), 501);
  39. }
  40. }
  41. private function _parseTransactionXmlStruct($requestXml, $requestXmlTags) {
  42. $DBG = (V::get('DBG_XML', '', $_GET) > 0);// TODO: Profiler
  43. $rootTagName = V::get('tag', '', $requestXmlTags[0]);
  44. if ('Transaction' != $rootTagName) {
  45. throw new Exception("Parse Request xml error #" . __LINE__);
  46. }
  47. // 1. convert request: wfs.transaction.convert-wfs-request.xsl
  48. // 2. validate converted request: wfs.transaction-converted-request.xsd
  49. // 3. execute request in data source
  50. // ? acl check?
  51. $usedSourceNsList = array();
  52. $sourceNsList = $this->_getSourceNsList();
  53. //$sourceNsList = array();
  54. //foreach ($requestXmlTags[0]['attributes'] as $attrName => $attrValue) {
  55. // if ('xmlns:p5_' == substr($attrName, 0, 9)) {
  56. // $sourceNsList[substr($attrName, 6)] = $attrValue;
  57. // }
  58. //}
  59. {// get used typeNames
  60. $usedTypeNames = array();
  61. // <Update xmlns="http://www.opengis.net/wfs" typeName="p5_default_db:TEST_PERMS">
  62. foreach ($requestXmlTags as $tag) {
  63. if ('Update' == $tag['tag'] && 'open' == $tag['type']) {
  64. $typeName = $tag['attributes']['typeName'];
  65. foreach ($sourceNsList as $nsInd => $ns) {
  66. if ("p5_{$ns[0]}:{$ns[1]}" == $typeName) {
  67. $usedSourceNsList[$nsInd] = $ns;
  68. }
  69. }
  70. }
  71. }
  72. // TODO: check: <Transaction xmlns:p5_default_db="https://biuro.biall-net.pl/wfs/default_db/TEST_PERMS"
  73. // <Insert xmlns="http://www.opengis.net/wfs">
  74. // <TEST_PERMS xmlns="https://biuro.biall-net.pl/wfs/default_db/TEST_PERMS">
  75. $lastTagName = '';
  76. foreach ($requestXmlTags as $tag) {
  77. if ('Insert' == $lastTagName) {
  78. $typeName = $tag['tag'];
  79. foreach ($sourceNsList as $nsInd => $ns) {
  80. if ("{$ns[1]}" == $typeName) {
  81. $usedSourceNsList[$nsInd] = $ns;
  82. }
  83. }
  84. }
  85. $lastTagName = $tag['tag'];
  86. }
  87. }
  88. if (empty($usedSourceNsList)) {
  89. throw new Exception("Parse Request xml error #" . __LINE__ . ": not implemented");
  90. }
  91. $convertedTransaction = $this->_convertTransactionXml($requestXml, $usedSourceNsList);
  92. if($DBG){echo '$convertedTransaction:';print_r($convertedTransaction);echo "\n";}
  93. if (empty($convertedTransaction)) {
  94. throw new Exception("Parse Request xml error #" . __LINE__ . ": convert Transaction");
  95. }
  96. //echo "\ntags[0]:\n" . json_encode($requestXmlTags[0]) . "\n";
  97. //echo "\nconvertedTransaction:\n" . $convertedTransaction . "\n";
  98. //echo "\nsourceNsList:\n" . json_encode($sourceNsList) . "\n";
  99. if (!$this->_validateConvertedTransactionXml($convertedTransaction, $usedSourceNsList)) {
  100. throw new Exception("Parse Request xml error #" . __LINE__ . ": schema validation failed");
  101. }
  102. $parserXml = xml_parser_create();
  103. xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
  104. xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
  105. if (0 == xml_parse_into_struct($parserXml, $convertedTransaction, $tags)) {
  106. throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction failed");
  107. }
  108. xml_parser_free($parserXml);
  109. if (empty($tags)) {
  110. throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction returns empty structure");
  111. }
  112. // [{"tag":"Transaction","type":"open","level":1,"attributes":{"version":"1.0.0","service":"WFS"}},
  113. // {"tag":"Update","type":"open","level":2,"attributes":
  114. // {"typeName":"p5_default_db_13051:TEST_PERMS","featureId":"TEST_PERMS.25"}},
  115. // {"tag":"PARENT_ID","type":"complete","level":3,"value":"0"},
  116. // {"tag":"Update","type":"close","level":2},
  117. // {"tag":"Transaction","type":"close","level":1}]
  118. if($DBG){echo "\nTODO: tags L." . __LINE__ . ":\n"; print_r($tags);echo "\n";}
  119. $actionTag = null;
  120. $prevTagName = '';
  121. $theGeomField = 'the_geom';// TODO: get the geom field name from acl
  122. $itemPatchs = array();
  123. foreach ($tags as $tag) {
  124. switch (substr($tag['tag'], 0, 6)) {
  125. case 'Transa': continue; break;// Transaction
  126. case 'Update':
  127. case 'Insert':
  128. case 'Delete':
  129. case 'Native':
  130. if ('open' == $tag['type']) {
  131. $actionTag = array();
  132. $actionTag['tag'] = substr($tag['tag'], 0, 6);
  133. $actionTag['typeName'] = $tag['attributes']['typeName'];
  134. if ('Insert' == substr($tag['tag'], 0, 6)) {
  135. $actionTag['typeName'] = "p5_default_db:{$actionTag['typeName']}";
  136. }
  137. $featureEx = explode('.', $tag['attributes']['featureId'], 2);
  138. $actionTag['featureId'] = $featureEx[1];
  139. if ('Update' == substr($tag['tag'], 0, 6) && empty($actionTag['featureId'])) {
  140. throw new Api_WfsException("Syntax error - could not read feature id!");
  141. }
  142. $actionTag['itemPatch'] = array();
  143. } else {
  144. $itemPatchs[] = $actionTag;
  145. $actionTag = null;
  146. }
  147. break;
  148. default: {// fields
  149. if (3 != $tag['level'] && 'close' == $tag['type']) {
  150. $actionTag = null;
  151. }
  152. if (3 != $tag['level']) continue;
  153. if (empty($actionTag)) continue;
  154. if ('Update' == $actionTag['tag']) {
  155. if ($theGeomField == $tag['tag']) {
  156. $actionTag['itemPatch'][$tag['tag']] = $this->_typeConverter->convertGmlCoordinatesToWkt($tag['value']);
  157. } else {
  158. $actionTag['itemPatch'][$tag['tag']] = $tag['value'];
  159. }
  160. }
  161. else if ('Insert' == $actionTag['tag']) {
  162. if ($theGeomField == $tag['tag']) {
  163. $actionTag['itemPatch'][$tag['tag']] = $this->_typeConverter->convertGmlCoordinatesToWkt($tag['value']);
  164. } else {
  165. $actionTag['itemPatch'][$tag['tag']] = $tag['value'];
  166. }
  167. }
  168. }
  169. }
  170. if (empty($prevTagName)) $prevTagName = $tag['tag'];
  171. }
  172. if($DBG){echo "\nTODO: itemPatchs L." . __LINE__ . ":\n"; print_r($itemPatchs);echo "\n";}
  173. if($DBG){echo "\nTODO: _user_id L." . __LINE__ . ":\n"; print_r($this->_usrAcl->_user_id);echo "\n";}
  174. $changesList = array();
  175. if (!empty($itemPatchs)) {
  176. foreach ($itemPatchs as $itemPatchInfo) {
  177. if($DBG){echo "itemPatchInfo['itemPatch']:\n";print_r($itemPatchInfo['itemPatch']);}
  178. if (empty($itemPatchInfo['itemPatch'])) continue;
  179. $acl = $this->getAclFromTypeName($itemPatchInfo['typeName']);
  180. $itemPatch = $itemPatchInfo['itemPatch'];
  181. if ('Update' == $itemPatchInfo['tag']) {
  182. $itemPatch[$acl->getPrimaryKeyField()] = $itemPatchInfo['featureId'];
  183. }
  184. else if ('Insert' == $itemPatchInfo['tag']) {
  185. if (!empty($itemPatch[$acl->getPrimaryKeyField()])) {
  186. $itemPatchInfo['featureId'] = $itemPatch[$acl->getPrimaryKeyField()];
  187. }
  188. else {
  189. //throw new Exception("TODO: Insert #" . __LINE__ . ": Create new record");
  190. }
  191. }
  192. if($DBG){echo "TODO update itemPatch:\n";print_r($itemPatch);}
  193. if ('Insert' == $itemPatchInfo['tag'] && empty($itemPatch[$acl->getPrimaryKeyField()])) {
  194. $newId = $acl->addItem($itemPatch);
  195. $changesList[$newId] = array('Status'=>(($newId > 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"created {$newId}.");
  196. if ($newId > 0) {
  197. $changesList[$newId]['fid'] = $acl->getName() . '.' . $newId;
  198. }
  199. if($DBG){echo "created {$newId}.\n";}
  200. } else {
  201. $affected = $acl->updateItem($itemPatch);
  202. $changesList[$itemPatchInfo['featureId']] = array('Status'=>(($affected >= 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"affected {$affected}.");
  203. if($DBG){echo "affected {$affected}.\n";}
  204. }
  205. }
  206. //throw new Exception("TODO: run query #" . __LINE__ . " \nitemPatchs:\n" . json_encode($itemPatchs) . " \ntags:\n" . json_encode($tags) . "\n");
  207. }
  208. else {
  209. throw new Exception("Parse Request xml error #" . __LINE__ . ": Nothing to change");
  210. }
  211. return $this->_transactionResponse($changesList);
  212. }
  213. private function _transactionResponse($changesList) {
  214. // <WFS_TransactionResponse>
  215. // <TransactionResult>
  216. // <Status> : SUCCESS / FAILED / PARTIAL
  217. // [<Locator]
  218. // [<Message]
  219. $messageTag = '';
  220. $statusTag = '';
  221. $statusIsFailed = false;
  222. $statusAll = null;
  223. $createdFetureId = '';
  224. foreach ($changesList as $featureId => $change) {
  225. if ('FAILED' == $change['Status']) {
  226. $statusIsFailed = true;
  227. }
  228. if ('SUCCESS' == $change['Status'] && !empty($change['fid'])) {
  229. $createdFetureId = $change['fid'];
  230. }
  231. if (!empty($change['Message'])) $messageTag .= "Feature '{$featureId}' {$change['Status']}: {$change['Message']}\n";
  232. }
  233. $statusTag = ($statusIsFailed)? 'FAILED' : 'SUCCESS';
  234. $statusTag = "<wfs:{$statusTag}/>";
  235. $messageTag = '';//"<wfs:Message>{$messageTag}</wfs:Message>";
  236. /* Example:
  237. <?xml version="1.0" encoding="UTF-8"?>
  238. <wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs"
  239. xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  240. xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd">
  241. <wfs:InsertResult>
  242. <ogc:FeatureId fid="archsites.26" />
  243. </wfs:InsertResult>
  244. <wfs:TransactionResult handle="Updating Signature rock label">
  245. <wfs:Status>
  246. <wfs:SUCCESS />
  247. </wfs:Status>
  248. </wfs:TransactionResult>
  249. </wfs:WFS_TransactionResponse>*/
  250. // TODO: build xml by DOMDocument
  251. // TODO: xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd"
  252. $wfsInsertResult = '';
  253. if (!empty($createdFetureId)) {
  254. $wfsInsertResult = <<<EOF
  255. <wfs:InsertResult>
  256. <ogc:FeatureId fid="{$createdFetureId}" xmlns:ogc="http://www.opengis.net/ogc"/>
  257. </wfs:InsertResult>
  258. EOF;
  259. }
  260. $tranRes = <<<EOF
  261. <wfs:WFS_TransactionResponse version="1.0.0"
  262. xmlns:wfs="http://www.opengis.net/wfs"
  263. xmlns:ogc="http://www.opengis.net/ogc"
  264. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  265. {$wfsInsertResult}
  266. <wfs:TransactionResult>
  267. <wfs:Status>{$statusTag}</wfs:Status>
  268. {$messageTag}
  269. </wfs:TransactionResult>
  270. </wfs:WFS_TransactionResponse>
  271. EOF;
  272. return $tranRes;
  273. }
  274. private function _convertTransactionXml($requestXmlString, $sourceNsList) {
  275. $DBG = (V::get('DBG_XSL', '', $_GET) > 0);// TODO: Profiler
  276. if($DBG){echo 'sourceNsList:';print_r($sourceNsList);echo "\n";}
  277. $updateActionsXsd = array();
  278. $insertActionsXsd = array();
  279. //<!-- TODO: create tag Update{X} where X is namespace index -->
  280. foreach ($sourceNsList as $nsInd => $sourceNs) {
  281. // <Update>
  282. $theGeomField = 'the_geom';// TODO: get from fields list
  283. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  284. $updateElementName = "UpdateNs{$nsInd}";
  285. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  286. $geomCoordsInsertXpath = "//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  287. $acl = $this->getAclFromTypeName($typeName);
  288. $geomType = $acl->getGeomFieldType($theGeomField);
  289. if ('polygon' == $geomType) {
  290. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  291. $geomCoordsUpdateXpath = "((<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>))";
  292. $geomCoordsInsertXpath = "//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  293. $geomCoordsInsertXpath = "((<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>))";
  294. } else if ('linestring' == $geomType) {
  295. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:coordinates";
  296. $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
  297. $geomCoordsInsertXpath = "//*/gml:coordinates";
  298. $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
  299. } else if ('point' == $geomType) {
  300. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:coordinates";
  301. $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
  302. $geomCoordsInsertXpath = "//*/gml:coordinates";
  303. $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
  304. }
  305. $actionXsd = <<<EOF
  306. <xsl:when test="@typeName = '{$typeName}'">
  307. <xsl:element name="{$updateElementName}">
  308. <xsl:attribute name="typeName"><xsl:value-of select="@typeName" /></xsl:attribute>
  309. <xsl:attribute name="featureId"><xsl:value-of select="ogc:Filter/ogc:FeatureId/@fid" /></xsl:attribute>
  310. <xsl:for-each select="wfs:Property">
  311. <xsl:element name="{wfs:Name}">
  312. <xsl:choose>
  313. <xsl:when test="wfs:Name = '{$theGeomField}'"><xsl:value-of select="local-name(//wfs:Value/*[1])"/>{$geomCoordsUpdateXpath}</xsl:when>
  314. <xsl:otherwise><xsl:value-of select="wfs:Value"/></xsl:otherwise>
  315. </xsl:choose>
  316. </xsl:element>
  317. </xsl:for-each>
  318. </xsl:element>
  319. </xsl:when>
  320. EOF;
  321. $updateActionsXsd[] = $actionXsd;
  322. $typeName = "{$sourceNs[1]}";//"p5_{$sourceNs[0]}:{$sourceNs[1]}";
  323. $insertElementName = "InsertNs{$nsInd}";
  324. $actionXsd = <<<EOF
  325. <xsl:when test="local-name() = '{$typeName}'">
  326. <xsl:element name="{$insertElementName}">
  327. <xsl:attribute name="typeName"><xsl:value-of select="local-name()" /></xsl:attribute>
  328. <xsl:for-each select="*">
  329. <xsl:element name="{local-name()}">
  330. <xsl:choose>
  331. <xsl:when test="local-name() = '{$theGeomField}'"><xsl:value-of select="local-name(*[1])"/>{$geomCoordsInsertXpath}</xsl:when>
  332. <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
  333. </xsl:choose>
  334. </xsl:element>
  335. </xsl:for-each>
  336. </xsl:element>
  337. </xsl:when>
  338. EOF;
  339. $insertActionsXsd[] = $actionXsd;
  340. }
  341. if (!empty($updateActionsXsd)) {
  342. $updateActionsXsd = implode("\n", $updateActionsXsd);
  343. $updateActionsXsd = <<<EOF
  344. <xsl:choose>
  345. {$updateActionsXsd}
  346. </xsl:choose>
  347. EOF;
  348. } else {
  349. $updateActionsXsd = '';
  350. }
  351. if (!empty($insertActionsXsd)) {
  352. $insertActionsXsd = implode("\n", $insertActionsXsd);
  353. $insertActionsXsd = <<<EOF
  354. <xsl:choose>
  355. {$insertActionsXsd}
  356. </xsl:choose>
  357. EOF;
  358. } else {
  359. $insertActionsXsd = '';
  360. }
  361. $convertTransactionXslString = <<<EOF
  362. <?xml version="1.0"?>
  363. <xsl:transform version="1.0"
  364. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  365. xmlns:wfs="http://www.opengis.net/wfs"
  366. xmlns:ogc="http://www.opengis.net/ogc"
  367. xmlns:gml="http://www.opengis.net/gml">
  368. <xsl:template match="/">
  369. <xsl:for-each select="wfs:Transaction">
  370. <Transaction>
  371. <xsl:attribute name="version"><xsl:value-of select="@version" /></xsl:attribute>
  372. <xsl:attribute name="service"><xsl:value-of select="@service" /></xsl:attribute>
  373. <xsl:for-each select="wfs:Update">
  374. {$updateActionsXsd}
  375. </xsl:for-each>
  376. <!-- TODO: Insert -->
  377. <xsl:for-each select="wfs:Insert/*">
  378. {$insertActionsXsd}
  379. </xsl:for-each>
  380. <!-- TODO: Delete -->
  381. <!-- TODO: Native -->
  382. </Transaction>
  383. </xsl:for-each>
  384. </xsl:template>
  385. </xsl:transform>
  386. EOF;
  387. if($DBG){echo '$convertTransactionXslString:' . $convertTransactionXslString . "\n";}
  388. $requestXml = new DOMDocument();
  389. $requestXml->loadXml($requestXmlString);
  390. $convertTransactionXsl = new DOMDocument();
  391. $convertTransactionXsl->loadXml($convertTransactionXslString);
  392. $proc = new XSLTProcessor();
  393. $proc->importStylesheet($convertTransactionXsl);
  394. return $proc->transformToXML($requestXml);
  395. }
  396. private function _validateConvertedTransactionXml($convertedTransaction, $sourceNsList) {
  397. $DBG = (V::get('DBG_XSD', '', $_GET) > 0);// TODO: Profiler
  398. if($DBG){echo 'sourceNsList:';print_r($sourceNsList);echo "\n";}
  399. $dom = new DOMDocument('1.0', 'utf-8');
  400. $dom->formatOutput = true;
  401. $dom->preserveWhiteSpace = false;
  402. $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
  403. $dom->appendChild($rootNode);
  404. // $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  405. // $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
  406. $rootNode->setAttribute('elementFormDefault', 'qualified');
  407. // $rootNode->setAttribute('targetNamespace', $wfsNsUri);
  408. $rootNode->setAttribute('version', '1.0');
  409. {// <xsd:element name="Transaction" type="TransactionType">
  410. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  411. $rootNode->appendChild($elNode);
  412. $elNode->setAttribute('name', 'Transaction');
  413. $elNode->setAttribute('type', 'TransactionType');
  414. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  415. $rootNode->appendChild($cTypeNode);
  416. $cTypeNode->setAttribute('name', 'TransactionType');
  417. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  418. $cTypeNode->appendChild($seqNode);
  419. $choiceNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:choice');
  420. $seqNode->appendChild($choiceNode);
  421. $choiceNode->setAttribute('minOccurs', '0');
  422. $choiceNode->setAttribute('maxOccurs', 'unbounded');
  423. // <!-- <xsd:element ref="Update"/> -->
  424. foreach ($sourceNsList as $nsInd => $sourceNs) {
  425. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  426. $updateElementName = "UpdateNs{$nsInd}";
  427. $updateElementType = "UpdateNs{$nsInd}ElementType";
  428. $updateElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  429. $choiceNode->appendChild($updateElemNode);
  430. $updateElemNode->setAttribute('name', $updateElementName);
  431. $updateElemNode->setAttribute('type', $updateElementType);
  432. }
  433. // <!-- <xsd:element ref="Insert"/> -->
  434. foreach ($sourceNsList as $nsInd => $sourceNs) {
  435. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  436. $insertElementName = "InsertNs{$nsInd}";
  437. $insertElementType = "InsertNs{$nsInd}ElementType";
  438. $insertElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  439. $choiceNode->appendChild($insertElemNode);
  440. $insertElemNode->setAttribute('name', $insertElementName);
  441. $insertElemNode->setAttribute('type', $insertElementType);
  442. }
  443. // <!-- <xsd:element ref="Delete"/> -->
  444. // <!-- <xsd:element ref="Native"/> -->
  445. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  446. $cTypeNode->appendChild($attrNode);
  447. $attrNode->setAttribute('name', 'version');
  448. $attrNode->setAttribute('type', 'xsd:string');
  449. $attrNode->setAttribute('use', 'required');
  450. $attrNode->setAttribute('fixed', '1.0.0');
  451. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  452. $cTypeNode->appendChild($attrNode);
  453. $attrNode->setAttribute('name', 'service');
  454. $attrNode->setAttribute('type', 'xsd:string');
  455. $attrNode->setAttribute('use', 'required');
  456. $attrNode->setAttribute('fixed', 'WFS');
  457. }
  458. foreach ($sourceNsList as $nsInd => $sourceNs) {
  459. $transactionTypesList = array();
  460. $transactionTypesList[] = 'Update';
  461. $transactionTypesList[] = 'Insert';
  462. foreach ($transactionTypesList as $transactionType) {
  463. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  464. $acl = $this->getAclFromTypeName($typeName);
  465. $updateElementName = "{$transactionType}Ns{$nsInd}";
  466. $updateElementType = "{$transactionType}Ns{$nsInd}ElementType";
  467. /*
  468. <xsd:complexType name="{$updateElementType}">
  469. <xsd:sequence>
  470. <xsd:element name="PARENT_ID" minOccurs="0" maxOccurs="1" type="xsd:integer" />
  471. </xsd:sequence>
  472. */
  473. $updateTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  474. $rootNode->appendChild($updateTypeNode);
  475. $updateTypeNode->setAttribute('name', $updateElementType);
  476. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  477. $updateTypeNode->appendChild($seqNode);
  478. $pKeyField = $acl->getPrimaryKeyField();
  479. $fldList = $acl->getRealFieldList();
  480. foreach ($fldList as $fldName) {
  481. if ($acl->isGeomField($fldName)) continue;
  482. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  483. $seqNode->appendChild($elNode);
  484. $elNode->setAttribute('name', $fldName);
  485. $minOccurs = 0;
  486. if ($pKeyField == $fldName) {
  487. $minOccurs = '1';
  488. } else {
  489. $minOccurs = '0';
  490. }
  491. $elNode->setAttribute('minOccurs', $minOccurs);
  492. $fldType = null;
  493. if ($acl->isIntegerField($fldName)) {
  494. $fldType = 'xsd:integer';
  495. }
  496. else if ($acl->isDecimalField($fldName)) {
  497. $fldType = 'xsd:decimal';
  498. }
  499. else if ($acl->isDateField($fldName)) {
  500. $fldType = 'xsd:date';
  501. }
  502. else if ($acl->isDateTimeField($fldName)) {
  503. $fldType = 'xsd:dateTime';
  504. }
  505. else if ($acl->isGeomField($fldName)) {
  506. //$fldType = 'gml:GeometryPropertyType';
  507. // TODO: use geom types from gml to wkt
  508. // TODO: pattern wg atrybutów gml:coordinates decimal="." cs="," ts=" "
  509. $patternWkt = '';// TODO: error if empty - unsupported geom type
  510. $patternNum = '\-?\d+\.?\d*';
  511. $patternPoint = $patternNum . ',' . $patternNum;
  512. $patternPoints = '(' . $patternPoint . ')( ' . $patternPoint . ')+';
  513. $geomType = $acl->getGeomFieldType($fldName);
  514. if ('polygon' == $geomType) {
  515. // [a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)\)
  516. $patternWkt = '[a-zA-Z]+\(\(' . $patternPoints . '\)\)';
  517. } else if ('linestring' == $geomType) {
  518. // [a-zA-Z]+\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)
  519. $patternWkt = '[a-zA-Z]+\(' . $patternPoints . '\)';
  520. } else if ('point' == $geomType) {
  521. // [a-zA-Z]+\(\-?\d\.?\d*,\-?\d\.?\d*\)
  522. $patternWkt = '[a-zA-Z]+\(' . $patternPoint . '\)';
  523. }
  524. $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  525. $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  526. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  527. $restrictionNode->setAttribute('base', 'xsd:string');
  528. $patternNode->setAttribute('value', $patternWkt);
  529. $restrictionNode->appendChild($patternNode);
  530. $simpleTypeNode->appendChild($restrictionNode);
  531. $elNode->appendChild($simpleTypeNode);
  532. }
  533. else {
  534. $fldType = 'xsd:string';
  535. }
  536. if ($fldType) $elNode->setAttribute('type', $fldType);
  537. $elNode->setAttribute('nillable', 'true');
  538. $elNode->setAttribute('minOccurs', '0');
  539. }
  540. foreach ($fldList as $fldName) {
  541. if (!$acl->isGeomField($fldName)) continue;
  542. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  543. $seqNode->appendChild($elNode);
  544. $elNode->setAttribute('name', $fldName);
  545. $minOccurs = 0;
  546. if ($pKeyField == $fldName) {
  547. $minOccurs = '1';
  548. } else {
  549. $minOccurs = '0';
  550. }
  551. $elNode->setAttribute('minOccurs', $minOccurs);
  552. if ($acl->isGeomField($fldName)) {
  553. //$fldType = 'gml:GeometryPropertyType';
  554. // TODO: use geom types from gml to wkt
  555. // TODO: pattern wg atrybutów gml:coordinates decimal="." cs="," ts=" "
  556. $patternWkt = '';// TODO: error if empty - unsupported geom type
  557. $patternNum = '\-?\d+\.?\d*';
  558. $patternPoint = $patternNum . ',' . $patternNum;
  559. $patternPoints = '(' . $patternPoint . ')( ' . $patternPoint . ')+';
  560. $geomType = $acl->getGeomFieldType($fldName);
  561. if ('polygon' == $geomType) {
  562. // [a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)\)
  563. $patternWkt = '[a-zA-Z]+\(\(' . $patternPoints . '\)\)';
  564. } else if ('linestring' == $geomType) {
  565. // [a-zA-Z]+\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)
  566. $patternWkt = '[a-zA-Z]+\(' . $patternPoints . '\)';
  567. } else if ('point' == $geomType) {
  568. // [a-zA-Z]+\(\-?\d\.?\d*,\-?\d\.?\d*\)
  569. $patternWkt = '[a-zA-Z]+\(' . $patternPoint . '\)';
  570. }
  571. $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  572. $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  573. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  574. $restrictionNode->setAttribute('base', 'xsd:string');
  575. $patternNode->setAttribute('value', $patternWkt);
  576. $restrictionNode->appendChild($patternNode);
  577. $simpleTypeNode->appendChild($restrictionNode);
  578. $elNode->appendChild($simpleTypeNode);
  579. }
  580. $elNode->setAttribute('nillable', 'true');
  581. $elNode->setAttribute('minOccurs', '0');
  582. }
  583. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  584. $updateTypeNode->appendChild($attrNode);
  585. $attrNode->setAttribute('name', 'typeName');
  586. $attrNode->setAttribute('type', 'xsd:token');
  587. $attrNode->setAttribute('use', 'required');
  588. if ($transactionType == 'Update') {
  589. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  590. $updateTypeNode->appendChild($attrNode);
  591. $attrNode->setAttribute('name', 'featureId');
  592. $attrNode->setAttribute('use', 'required');
  593. $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  594. $attrNode->appendChild($sTypeNode);
  595. $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  596. $sTypeNode->appendChild($resNode);
  597. $resNode->setAttribute('base', 'xsd:string');
  598. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  599. $resNode->appendChild($patternNode);
  600. $patternNode->setAttribute('value', '[a-zA-Z_]*\.[0-9]*');
  601. }
  602. }
  603. }
  604. $validateConvertedTransactionXsdString = $dom->saveXml();
  605. if($DBG){echo '$validateConvertedTransactionXsdString:';print_r($validateConvertedTransactionXsdString);echo "\n";}
  606. $reqXml = new DOMDocument();
  607. $reqXml->loadXml($convertedTransaction);
  608. // TODO: fetch PHP Warning: DOMDocument::schemaValidateSource(): Element 'PARENT_ID': 'abc' is not a valid value of the atomic type 'xs:integer'.
  609. return $reqXml->schemaValidateSource($validateConvertedTransactionXsdString);
  610. }
  611. private function _generateXsdTypeNode($ns, $typeName, $dom, $parentNode) {
  612. //$fieldsXsd = '';
  613. //$fieldsXsd .= '<xsd:element name="PARENT_ID" minOccurs="0" maxOccurs="1" type="xsd:integer" />';
  614. $acl = $this->getAclFromTypeName($typeName);
  615. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  616. $rootNode = $cTypeNode;
  617. $cTypeNode->setAttribute('name', $typeName);
  618. $cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
  619. $cTypeNode->appendChild($cConNode);
  620. $extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
  621. $cConNode->appendChild($extNode);
  622. $extNode->setAttribute('base', 'gml:AbstractFeatureType');
  623. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');// or xsd:all ?
  624. $extNode->appendChild($seqNode);
  625. // <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
  626. $pKeyField = $acl->getPrimaryKeyField();
  627. $fldList = $acl->getRealFieldList();
  628. foreach ($fldList as $fldName) {
  629. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  630. $seqNode->appendChild($elNode);
  631. $elNode->setAttribute('name', $fldName);
  632. $minOccurs = 0;
  633. if ($pKeyField == $fldName) {
  634. $minOccurs = '1';
  635. } else {
  636. $minOccurs = '0';
  637. }
  638. $elNode->setAttribute('minOccurs', $minOccurs);
  639. if ($acl->isIntegerField($fldName)) {
  640. $fldType = 'xsd:integer';
  641. }
  642. else if ($acl->isDecimalField($fldName)) {
  643. $fldType = 'xsd:decimal';
  644. }
  645. else if ($acl->isDateField($fldName)) {
  646. $fldType = 'xsd:date';
  647. }
  648. else if ($acl->isDateTimeField($fldName)) {
  649. $fldType = 'xsd:dateTime';
  650. }
  651. else if ($acl->isGeomField($fldName)) {
  652. $fldType = 'gml:GeometryPropertyType';
  653. //$fldType = 'gml:Polygon';// nie działa musi być gml:GeometryPropertyType
  654. }
  655. else {
  656. $fldType = 'xsd:string';
  657. }
  658. $elNode->setAttribute('type', $fldType);
  659. $elNode->setAttribute('nillable', 'true');
  660. }
  661. /*
  662. <xsd:attribute name="typeName" type="xsd:token" use="required"/>
  663. <xsd:attribute name="featureId" use="required">
  664. <xsd:simpleType>
  665. <xsd:restriction base="xsd:string">
  666. <xsd:pattern value="[a-zA-Z_]*\.[0-9]*"/>
  667. </xsd:restriction>
  668. </xsd:simpleType>
  669. </xsd:attribute>
  670. */
  671. $cAttrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  672. $rootNode->appendChild($cAttrNode);
  673. $cAttrNode->setAttribute('name', 'typeName');
  674. $cAttrNode->setAttribute('type', 'xsd:token');
  675. $cAttrNode->setAttribute('use', 'required');
  676. $cAttrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  677. $rootNode->appendChild($cAttrNode);
  678. $cAttrNode->setAttribute('name', 'featureId');
  679. $cAttrNode->setAttribute('use', 'required');
  680. $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  681. $cAttrNode->appendChild($sTypeNode);
  682. $restrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  683. $cAttrNode->appendChild($restrNode);
  684. $restrNode->setAttribute('base', 'xsd:string');
  685. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  686. $restrNode->appendChild($patternNode);
  687. $patternNode->setAttribute('value', '[a-zA-Z_]*\.[0-9]*');
  688. return $dom->saveXml($cTypeNode);
  689. $typeXsd = <<<EOF
  690. <xsd:complexType name="{$typeName}">
  691. <xsd:all>
  692. {$fieldsXsd}
  693. </xsd:all>
  694. <xsd:attribute name="typeName" type="xsd:token" use="required"/>
  695. <xsd:attribute name="featureId" use="required">
  696. <xsd:simpleType>
  697. <xsd:restriction base="xsd:string">
  698. <xsd:pattern value="[a-zA-Z_]*\.[0-9]*"/>
  699. </xsd:restriction>
  700. </xsd:simpleType>
  701. </xsd:attribute>
  702. </xsd:complexType>
  703. EOF;
  704. return $typeXsd;
  705. }
  706. /**
  707. * @param string $typeName - 'p5_default_db:TEST_PERMS'
  708. */
  709. public function getAclFromTypeName($typeName) {
  710. $typeEx = explode(':', $typeName);
  711. if (2 != count($typeEx)) {
  712. throw new Api_WfsException("Could not get acl for '{$typeName}' - syntax error");
  713. }
  714. if ('p5_' != substr($typeEx[0], 0, 3)) {
  715. throw new Api_WfsException("Could not get acl for '{$typeName}' - prefix error");
  716. }
  717. $sourceName = substr($typeEx[0], 3);
  718. $objName = $typeEx[1];
  719. $acl = $this->_usrAcl->getObjectAcl($sourceName, $objName);
  720. if (!$acl) {
  721. throw new Api_WfsException("Could not get acl for '{$typeName}'");
  722. }
  723. $forceTblAclInit = 0;//('1' == V::get('_force', '', $_GET));
  724. $acl->init($forceTblAclInit);
  725. return $acl;
  726. }
  727. public function getFeatureAction() {
  728. $type = V::get('TYPENAME', '', $_REQUEST);
  729. $typeEx = explode(':', $type);
  730. $maxFeatures = V::get('MAXFEATURES', '10000', $_REQUEST, 'int');// TODO: Set Deafult Limit
  731. $srsname = V::get('SRSNAME', '', $_REQUEST);// eg. EPSG:4326
  732. if (count($typeEx) == 2) {
  733. return $this->getFeatures($typeEx[0], $typeEx[1], $maxFeatures, $srsname);
  734. } else {
  735. throw new HttpException("Wrong param TYPENAME", 400);
  736. }
  737. }
  738. public function getFeatures($nsPrefix, $type, $maxFeatures, $srsname) {
  739. $DBG = (V::get('DBG_GEO', '', $_GET) > 0);// TODO: Profiler
  740. $typeName = "{$nsPrefix}:{$type}";
  741. $acl = $this->getAclFromTypeName($typeName);
  742. $fldList = $acl->getRealFieldList();
  743. $wfsNs = 'p5_default_db_' . $type;//$nsPrefix;
  744. $wfsNsUri = 'https://biuro.biall-net.pl/wfs/' . substr($nsPrefix, 3) . '/' . $type;
  745. // get BBox from geom_field (only one geom fld is allowed)
  746. $geomFld = null;
  747. {
  748. foreach ($fldList as $fldName) {
  749. if ($acl->isGeomField($fldName)) {
  750. $geomFld = $fldName;
  751. }
  752. }
  753. }
  754. $dbGeomType = $acl->getGeomFieldType($geomFld);
  755. $searchParams = array();
  756. $searchParams['limit'] = $maxFeatures;
  757. $searchParams['order_by'] = $acl->getPrimaryKeyField();
  758. $searchParams['order_dir'] = 'DESC';
  759. if ($geomFld) $searchParams["f_{$geomFld}"] = 'IS NOT NULL';
  760. if ($geomFld) $searchParams["f_{$geomFld}"] = 'GeometryType=' . strtoupper($dbGeomType);
  761. //if ($geomFld) $searchParams["f_{$geomFld}"] = 'GeometryType=LINESTRING';
  762. if($DBG){echo 'getItems:';print_r($searchParams);echo "\n";}
  763. $items = $acl->getItems($searchParams);
  764. $dom = new DOMDocument('1.0', 'utf-8');
  765. $dom->formatOutput = true;
  766. $dom->preserveWhiteSpace = false;
  767. $rootNode = $dom->createElementNS('http://www.opengis.net/wfs', 'wfs:FeatureCollection');
  768. $dom->appendChild($rootNode);
  769. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.opengis.net/wfs');
  770. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:wfs', 'http://www.opengis.net/wfs');
  771. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  772. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  773. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
  774. $rootNode->setAttribute('xsi:schemaLocation', 'http://www.opengis.net/wfs');// TODO: add DescribeFeatureType xsd uri
  775. if(0){// TODO: get BBOX for add features
  776. $boundedByNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:boundedBy');
  777. $rootNode->appendChild($boundedByNode);
  778. $boxNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:Box');
  779. $boundedByNode->appendChild($boxNode);
  780. $boxNode->setAttribute('srsName', "http://www.opengis.net/gml/srs/epsg.xml#4326");// TODO: EPSG
  781. $coordinatesNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:coordinates');
  782. $boxNode->appendChild($coordinatesNode);
  783. $coordinatesNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  784. $coordinatesNode->setAttribute('decimal', '.');
  785. $coordinatesNode->setAttribute('cs', ',');
  786. $coordinatesNode->setAttribute('ts', ' ');
  787. $coordinatesNode->nodeValue = '1544947.6295,4322758.105 1548002.2259,4330464.1001';// TODO: coordinates for all items?
  788. }
  789. if($DBG){echo '(geomFld: '.$geomFld.'):';print_r($acl->getFieldType($geomFld));echo "\n";}
  790. if (empty($items)) {
  791. $pKeyField = $acl->getPrimaryKeyField();
  792. $fakeItem = new stdClass();
  793. $fakeItem->{$pKeyField} = 0;
  794. if ('polygon' == $dbGeomType) {
  795. $fakeItem->the_geom = "POLYGON(())";
  796. } else if ('linestring' == $dbGeomType) {
  797. $fakeItem->the_geom = "LINESTRING()";
  798. } else if ('point' == $dbGeomType) {
  799. $fakeItem->the_geom = "POINT(0,0)";
  800. }
  801. $items[0] = $fakeItem;
  802. }
  803. foreach ($items as $itemKey => $item) {
  804. //if($item->ID == 19)continue;
  805. if($DBG){echo 'item['.$itemKey.'] ('.$geomFld.')isEmpty('.empty($item->{$geomFld}).'):';print_r($item->{$geomFld});echo "\n";}
  806. if ($geomFld) {
  807. if (empty($item->{$geomFld})) {
  808. continue;// QGIS crash when WFS contain features with empty geom field
  809. }
  810. }
  811. $featureMemberNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:featureMember');
  812. $rootNode->appendChild($featureMemberNode);
  813. $featureNode = $dom->createElementNS($wfsNsUri, "{$wfsNs}:{$type}");
  814. $featureMemberNode->appendChild($featureNode);
  815. $featureNode->setAttribute('fid', "{$type}.{$itemKey}");
  816. if(0){// TODO: get BBOX
  817. $boundedByNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:boundedBy');
  818. $featureNode->appendChild($boundedByNode);
  819. $boxNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:Box');
  820. $boundedByNode->appendChild($boxNode);
  821. $boxNode->setAttribute('srsName', "http://www.opengis.net/gml/srs/epsg.xml#4326");// TODO: EPSG
  822. $coordinatesNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:coordinates');
  823. $boxNode->appendChild($coordinatesNode);
  824. $coordinatesNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  825. $coordinatesNode->setAttribute('decimal', '.');
  826. $coordinatesNode->setAttribute('cs', ',');
  827. $coordinatesNode->setAttribute('ts', ' ');
  828. $coordinatesNode->nodeValue = '1546472.2363,4328949.5775 1548002.2259,4330464.1001';// TODO: coordinates for item?
  829. }
  830. foreach ($fldList as $fldName) {
  831. $featureFldNode = $dom->createElementNS($wfsNsUri, "{$wfsNs}:{$fldName}");
  832. if ($acl->isGeomField($fldName)) {
  833. $geomNode = $this->_typeConverter->createGmlFromWkt($item->{$fldName}, $dom);
  834. if (!$geomNode) continue;
  835. $featureFldNode->appendChild($geomNode);
  836. } else {
  837. $featureFldNode->nodeValue = str_replace('&', '&amp;', $item->{$fldName});
  838. if (empty($featureFldNode->nodeValue)) {
  839. continue;
  840. }
  841. }
  842. $featureNode->appendChild($featureFldNode);
  843. }
  844. }
  845. return $dom->saveXml();
  846. }
  847. public function getObjectAction() {
  848. $type = V::get('TYPENAME', '', $_REQUEST);
  849. $typeEx = explode(':', $type);
  850. $maxFeatures = V::get('MAXFEATURES', '10000', $_REQUEST, 'int');// TODO: Set Deafult Limit
  851. $ogcFilter = V::get('Filter', '', $_REQUEST);
  852. $srsname = V::get('SRSNAME', '', $_REQUEST);// eg. EPSG:4326
  853. if (count($typeEx) == 2) {
  854. return $this->getObjects($typeEx[0], $typeEx[1], $maxFeatures, $srsname, $ogcFilter);
  855. } else {
  856. throw new HttpException("Wrong param TYPENAME", 400);
  857. }
  858. }
  859. public function getObjects($nsPrefix, $type, $maxFeatures, $srsname, $ogcFilter = '') {
  860. $DBG = (V::get('DBG_GEO', '', $_GET) > 0);// TODO: Profiler
  861. $typeName = "{$nsPrefix}:{$type}";
  862. $acl = $this->getAclFromTypeName($typeName);
  863. $fldList = $acl->getRealFieldList();
  864. $wfsNs = 'p5_default_db_' . $type;//$nsPrefix;
  865. $wfsNsUri = 'https://biuro.biall-net.pl/wfs/' . substr($nsPrefix, 3) . '/' . $type;
  866. // get BBox from geom_field (only one geom fld is allowed)
  867. $geomFld = null;
  868. {
  869. foreach ($fldList as $fldName) {
  870. if ($acl->isGeomField($fldName)) {
  871. $geomFld = $fldName;
  872. }
  873. }
  874. }
  875. if($DBG){echo "ogcFilter(" . strlen($ogcFilter) . "): {$ogcFilter}\n";}
  876. $searchParams = array();
  877. $searchParams['limit'] = $maxFeatures;
  878. $searchParams['order_by'] = $acl->getPrimaryKeyField();
  879. $searchParams['order_dir'] = 'DESC';
  880. if (strlen($ogcFilter) > 0) $searchParams['ogc:Filter'] = $ogcFilter;
  881. if($DBG){echo 'getItems:';print_r($searchParams);echo "\n";}
  882. $items = $acl->getItems($searchParams);
  883. $dom = new DOMDocument('1.0', 'utf-8');
  884. $dom->formatOutput = true;
  885. $dom->preserveWhiteSpace = false;
  886. $rootNode = $dom->createElementNS('http://www.opengis.net/wfs', 'wfs:FeatureCollection');
  887. $dom->appendChild($rootNode);
  888. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.opengis.net/wfs');
  889. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:wfs', 'http://www.opengis.net/wfs');
  890. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  891. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  892. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
  893. $rootNode->setAttribute('xsi:schemaLocation', 'http://www.opengis.net/wfs');// TODO: add DescribeFeatureType xsd uri
  894. if($DBG){echo '(geomFld: '.$geomFld.'):';print_r($acl->getFieldType($geomFld));echo "\n";}
  895. if (empty($items)) {
  896. $pKeyField = $acl->getPrimaryKeyField();
  897. $fakeItem = new stdClass();
  898. $fakeItem->{$pKeyField} = 0;
  899. $items[0] = $fakeItem;
  900. }
  901. foreach ($items as $itemKey => $item) {
  902. if($DBG){echo 'item['.$itemKey.'] ('.$geomFld.')isEmpty('.empty($item->{$geomFld}).'):';print_r($item->{$geomFld});echo "\n";}
  903. $featureMemberNode = $dom->createElementNS('http://www.opengis.net/gml', 'gml:featureMember');
  904. $rootNode->appendChild($featureMemberNode);
  905. $featureNode = $dom->createElementNS($wfsNsUri, "{$wfsNs}:{$type}");
  906. $featureMemberNode->appendChild($featureNode);
  907. $featureNode->setAttribute('fid', "{$type}.{$itemKey}");
  908. foreach ($fldList as $fldName) {
  909. $featureFldNode = $dom->createElementNS($wfsNsUri, "{$wfsNs}:{$fldName}");
  910. if ($acl->isGeomField($fldName)) {
  911. $geomNode = $this->_typeConverter->createGmlFromWkt($item->{$fldName}, $dom);
  912. if (!$geomNode) continue;
  913. $featureFldNode->appendChild($geomNode);
  914. } else {
  915. $featureFldNode->nodeValue = str_replace('&', '&amp;', $item->{$fldName});
  916. if (empty($featureFldNode->nodeValue)) {
  917. continue;
  918. }
  919. }
  920. $featureNode->appendChild($featureFldNode);
  921. }
  922. }
  923. return $dom->saveXml();
  924. }
  925. public function describeFeatureTypeAction() {
  926. $type = V::get('TYPENAME', '', $_REQUEST);
  927. if (empty($type)) {
  928. throw new HttpException("Wrong param TYPENAME", 400);
  929. }
  930. $typeEx = explode(':', $type);
  931. if (count($typeEx) != 2) {
  932. throw new HttpException("Wrong param TYPENAME", 400);
  933. }
  934. return $this->getDescribeFeatureType($typeEx[0], $typeEx[1]);
  935. }
  936. private function getDescribeFeatureType($nsPrefix, $type) {
  937. $typeName = "{$nsPrefix}:{$type}";
  938. $acl = $this->getAclFromTypeName($typeName);
  939. $wfsNs = 'p5_default_db_' . $type;//$nsPrefix;
  940. $wfsNsUri = 'https://biuro.biall-net.pl/wfs/' . substr($nsPrefix, 3) . '/' . $type;
  941. if (empty($type)) {
  942. throw new HttpException("Feature Type Name not defined", 400);
  943. }
  944. if (!$this->isAllowedFeatureType($nsPrefix, $type)) {
  945. throw new Api_WfsException("Could not find type: " . htmlspecialchars($type));
  946. }
  947. $typeName = $type . 'Type';
  948. $fldList = $acl->getRealFieldList();
  949. header('Content-type: application/xml');
  950. // <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://webgis.regione.sardegna.it:80/geoserver/schemas/gml/2.1.2/feature.xsd"/>
  951. // <xsd:element name="{type}" substitutionGroup="gml:_Feature" type="dbu:{typeName}"/>
  952. $dom = new DOMDocument('1.0', 'utf-8');
  953. $dom->formatOutput = true;
  954. $dom->preserveWhiteSpace = false;
  955. $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
  956. $dom->appendChild($rootNode);
  957. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  958. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
  959. $rootNode->setAttribute('elementFormDefault', 'qualified');
  960. $rootNode->setAttribute('targetNamespace', $wfsNsUri);
  961. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  962. $rootNode->appendChild($cTypeNode);
  963. $cTypeNode->setAttribute('name', $typeName);
  964. $cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
  965. $cTypeNode->appendChild($cConNode);
  966. $extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
  967. $cConNode->appendChild($extNode);
  968. $extNode->setAttribute('base', 'gml:AbstractFeatureType');
  969. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  970. $extNode->appendChild($seqNode);
  971. // <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
  972. $pKeyField = $acl->getPrimaryKeyField();
  973. foreach ($fldList as $fldName) {
  974. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  975. $seqNode->appendChild($elNode);
  976. $elNode->setAttribute('name', $fldName);
  977. $minOccurs = 0;
  978. if ($pKeyField == $fldName) {
  979. $minOccurs = '1';
  980. } else {
  981. $minOccurs = '0';
  982. }
  983. $elNode->setAttribute('minOccurs', $minOccurs);
  984. if ($acl->isIntegerField($fldName)) {
  985. $fldType = 'xsd:integer';
  986. }
  987. else if ($acl->isDecimalField($fldName)) {
  988. $fldType = 'xsd:decimal';
  989. }
  990. else if ($acl->isDateField($fldName)) {
  991. $fldType = 'xsd:date';
  992. }
  993. else if ($acl->isDateTimeField($fldName)) {
  994. $fldType = 'xsd:dateTime';
  995. }
  996. else if ($acl->isGeomField($fldName)) {
  997. $fldType = 'gml:GeometryPropertyType';
  998. //$fldType = 'gml:Polygon';// nie działa musi być gml:GeometryPropertyType
  999. }
  1000. else {
  1001. $fldType = 'xsd:string';
  1002. }
  1003. $elNode->setAttribute('type', $fldType);
  1004. $elNode->setAttribute('nillable', 'true');
  1005. }
  1006. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1007. $rootNode->appendChild($elNode);
  1008. $elNode->setAttribute('name', $type);
  1009. $elNode->setAttribute('type', $wfsNs . ':' . $typeName);
  1010. echo $dom->saveXML();
  1011. //print_r($acl);
  1012. }
  1013. public function isAllowedFeatureType($nsPrefix, $type) {
  1014. if ('p5_' != substr($nsPrefix, 0, 3)) return false;
  1015. if ('p5_default_db' == $nsPrefix) {
  1016. $typeName = "p5_default_db:{$type}";
  1017. try {
  1018. $acl = $this->getAclFromTypeName($typeName);
  1019. } catch (Exception $e) {
  1020. return false;
  1021. }
  1022. if ($acl) {
  1023. return true;
  1024. }
  1025. }
  1026. return false;
  1027. }
  1028. public function getCapabilitiesAction() {
  1029. $wfsServerUrl = 'https://biuro.biall-net.pl/dev-pl/se-feature-api/wfs.php/xml/wfs/default_db';
  1030. $serviceTitle = "BIALL-NET Web Feature Service";
  1031. $serviceDescription = "This is the reference implementation of WFS 1.0.0 and WFS 1.1.0, supports all WFS operations including Transaction.";
  1032. //header('Content-type: application/xml; charset="utf-8"');
  1033. header('Content-type: application/xml');
  1034. echo '<?xml version="1.0" encoding="UTF-8"?>';
  1035. ?>
  1036. <WFS_Capabilities version="1.0.0"
  1037. xmlns="http://www.opengis.net/wfs"
  1038. xmlns:ogc="http://www.opengis.net/ogc"
  1039. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  1040. <?php echo $this->_getXmlNamespaceList(); ?>
  1041. xsi:schemaLocation="http://www.opengis.net/wfs <?php echo $this->_getSchemaLocationString(); ?>">
  1042. <Service>
  1043. <Name>WFS</Name>
  1044. <Title><?php echo $serviceTitle; ?></Title>
  1045. <Abstract><?php echo $serviceDescription; ?></Abstract>
  1046. <Keywords>WFS, WMS</Keywords>
  1047. <OnlineResource><?php echo $wfsServerUrl; ?></OnlineResource>
  1048. <Fees>NONE</Fees>
  1049. <AccessConstraints>NONE</AccessConstraints>
  1050. </Service>
  1051. <Capability>
  1052. <Request>
  1053. <?php $this->_printGetCapabilitiesXml($wfsServerUrl); ?>
  1054. <?php $this->_printDescribeFeatureTypeXml($wfsServerUrl); ?>
  1055. <?php $this->_printGetFeatureXml($wfsServerUrl); ?>
  1056. <?php $this->_printTransactionXml($wfsServerUrl); ?>
  1057. <?php $this->_printLockFeatureXml($wfsServerUrl); ?>
  1058. <?php $this->_printGetFeatureWithLockXml($wfsServerUrl); ?>
  1059. </Request>
  1060. </Capability>
  1061. <FeatureTypeList>
  1062. <Operations>
  1063. <Query />
  1064. <Insert />
  1065. <Update />
  1066. <Delete />
  1067. <Lock />
  1068. </Operations>
  1069. <?php echo $this->_printFeatureTypeListXml(); ?>
  1070. </FeatureTypeList>
  1071. <ogc:Filter_Capabilities>
  1072. <ogc:Spatial_Capabilities>
  1073. <ogc:Spatial_Operators>
  1074. <ogc:Disjoint />
  1075. <ogc:Equals />
  1076. <ogc:DWithin />
  1077. <ogc:Beyond />
  1078. <ogc:Intersect />
  1079. <ogc:Touches />
  1080. <ogc:Crosses />
  1081. <ogc:Within />
  1082. <ogc:Contains />
  1083. <ogc:Overlaps />
  1084. <ogc:BBOX />
  1085. </ogc:Spatial_Operators>
  1086. </ogc:Spatial_Capabilities>
  1087. <ogc:Scalar_Capabilities>
  1088. <ogc:Logical_Operators />
  1089. <ogc:Comparison_Operators>
  1090. <ogc:Simple_Comparisons />
  1091. <ogc:Between />
  1092. <ogc:Like />
  1093. <ogc:NullCheck />
  1094. </ogc:Comparison_Operators>
  1095. <ogc:Arithmetic_Operators>
  1096. <ogc:Simple_Arithmetic />
  1097. <ogc:Functions>
  1098. <ogc:Function_Names>
  1099. <ogc:Function_Name nArgs="1">abs</ogc:Function_Name>
  1100. <ogc:Function_Name nArgs="1">abs_2</ogc:Function_Name>
  1101. <ogc:Function_Name nArgs="1">abs_3</ogc:Function_Name>
  1102. <ogc:Function_Name nArgs="1">abs_4</ogc:Function_Name>
  1103. <ogc:Function_Name nArgs="1">acos</ogc:Function_Name>
  1104. <ogc:Function_Name nArgs="2">AddCoverages</ogc:Function_Name>
  1105. <ogc:Function_Name nArgs="4">Aggregate</ogc:Function_Name>
  1106. <ogc:Function_Name nArgs="1">Area</ogc:Function_Name>
  1107. <ogc:Function_Name nArgs="1">area2</ogc:Function_Name>
  1108. <ogc:Function_Name nArgs="3">AreaGrid</ogc:Function_Name>
  1109. <ogc:Function_Name nArgs="1">asin</ogc:Function_Name>
  1110. <ogc:Function_Name nArgs="1">atan</ogc:Function_Name>
  1111. <ogc:Function_Name nArgs="2">atan2</ogc:Function_Name>
  1112. <ogc:Function_Name nArgs="14">BarnesSurface</ogc:Function_Name>
  1113. <ogc:Function_Name nArgs="3">between</ogc:Function_Name>
  1114. <ogc:Function_Name nArgs="1">boundary</ogc:Function_Name>
  1115. <ogc:Function_Name nArgs="1">boundaryDimension</ogc:Function_Name>
  1116. <ogc:Function_Name nArgs="1">Bounds</ogc:Function_Name>
  1117. <ogc:Function_Name nArgs="2">buffer</ogc:Function_Name>
  1118. <ogc:Function_Name nArgs="3">BufferFeatureCollection</ogc:Function_Name>
  1119. <ogc:Function_Name nArgs="3">bufferWithSegments</ogc:Function_Name>
  1120. <ogc:Function_Name nArgs="7">Categorize</ogc:Function_Name>
  1121. <ogc:Function_Name nArgs="1">ceil</ogc:Function_Name>
  1122. <ogc:Function_Name nArgs="1">Centroid</ogc:Function_Name>
  1123. <ogc:Function_Name nArgs="2">classify</ogc:Function_Name>
  1124. <ogc:Function_Name nArgs="2">Clip</ogc:Function_Name>
  1125. <ogc:Function_Name nArgs="1">CollectGeometries</ogc:Function_Name>
  1126. <ogc:Function_Name nArgs="1">Collection_Average</ogc:Function_Name>
  1127. <ogc:Function_Name nArgs="1">Collection_Bounds</ogc:Function_Name>
  1128. <ogc:Function_Name nArgs="0">Collection_Count</ogc:Function_Name>
  1129. <ogc:Function_Name nArgs="1">Collection_Max</ogc:Function_Name>
  1130. <ogc:Function_Name nArgs="1">Collection_Median</ogc:Function_Name>
  1131. <ogc:Function_Name nArgs="1">Collection_Min</ogc:Function_Name>
  1132. <ogc:Function_Name nArgs="1">Collection_Sum</ogc:Function_Name>
  1133. <ogc:Function_Name nArgs="1">Collection_Unique</ogc:Function_Name>
  1134. <ogc:Function_Name nArgs="1">Concatenate</ogc:Function_Name>
  1135. <ogc:Function_Name nArgs="2">contains</ogc:Function_Name>
  1136. <ogc:Function_Name nArgs="7">Contour</ogc:Function_Name>
  1137. <ogc:Function_Name nArgs="2">convert</ogc:Function_Name>
  1138. <ogc:Function_Name nArgs="1">convexHull</ogc:Function_Name>
  1139. <ogc:Function_Name nArgs="1">cos</ogc:Function_Name>
  1140. <ogc:Function_Name nArgs="1">Count</ogc:Function_Name>
  1141. <ogc:Function_Name nArgs="2">CropCoverage</ogc:Function_Name>
  1142. <ogc:Function_Name nArgs="2">crosses</ogc:Function_Name>
  1143. <ogc:Function_Name nArgs="2">dateFormat</ogc:Function_Name>
  1144. <ogc:Function_Name nArgs="2">dateParse</ogc:Function_Name>
  1145. <ogc:Function_Name nArgs="2">difference</ogc:Function_Name>
  1146. <ogc:Function_Name nArgs="1">dimension</ogc:Function_Name>
  1147. <ogc:Function_Name nArgs="2">disjoint</ogc:Function_Name>
  1148. <ogc:Function_Name nArgs="2">disjoint3D</ogc:Function_Name>
  1149. <ogc:Function_Name nArgs="2">distance</ogc:Function_Name>
  1150. <ogc:Function_Name nArgs="2">distance3D</ogc:Function_Name>
  1151. <ogc:Function_Name nArgs="1">double2bool</ogc:Function_Name>
  1152. <ogc:Function_Name nArgs="1">endAngle</ogc:Function_Name>
  1153. <ogc:Function_Name nArgs="1">endPoint</ogc:Function_Name>
  1154. <ogc:Function_Name nArgs="1">env</ogc:Function_Name>
  1155. <ogc:Function_Name nArgs="1">envelope</ogc:Function_Name>
  1156. <ogc:Function_Name nArgs="2">EqualInterval</ogc:Function_Name>
  1157. <ogc:Function_Name nArgs="2">equalsExact</ogc:Function_Name>
  1158. <ogc:Function_Name nArgs="3">equalsExactTolerance</ogc:Function_Name>
  1159. <ogc:Function_Name nArgs="2">equalTo</ogc:Function_Name>
  1160. <ogc:Function_Name nArgs="1">exp</ogc:Function_Name>
  1161. <ogc:Function_Name nArgs="1">exteriorRing</ogc:Function_Name>
  1162. <ogc:Function_Name nArgs="3">Feature</ogc:Function_Name>
  1163. <ogc:Function_Name nArgs="1">floor</ogc:Function_Name>
  1164. <ogc:Function_Name nArgs="1">geometryType</ogc:Function_Name>
  1165. <ogc:Function_Name nArgs="1">geomFromWKT</ogc:Function_Name>
  1166. <ogc:Function_Name nArgs="1">geomLength</ogc:Function_Name>
  1167. <ogc:Function_Name nArgs="2">getGeometryN</ogc:Function_Name>
  1168. <ogc:Function_Name nArgs="1">getX</ogc:Function_Name>
  1169. <ogc:Function_Name nArgs="1">getY</ogc:Function_Name>
  1170. <ogc:Function_Name nArgs="1">getz</ogc:Function_Name>
  1171. <ogc:Function_Name nArgs="2">greaterEqualThan</ogc:Function_Name>
  1172. <ogc:Function_Name nArgs="2">greaterThan</ogc:Function_Name>
  1173. <ogc:Function_Name nArgs="5">Grid</ogc:Function_Name>
  1174. <ogc:Function_Name nArgs="7">Heatmap</ogc:Function_Name>
  1175. <ogc:Function_Name nArgs="0">id</ogc:Function_Name>
  1176. <ogc:Function_Name nArgs="2">IEEEremainder</ogc:Function_Name>
  1177. <ogc:Function_Name nArgs="3">if_then_else</ogc:Function_Name>
  1178. <ogc:Function_Name nArgs="11">in10</ogc:Function_Name>
  1179. <ogc:Function_Name nArgs="3">in2</ogc:Function_Name>
  1180. <ogc:Function_Name nArgs="4">in3</ogc:Function_Name>
  1181. <ogc:Function_Name nArgs="5">in4</ogc:Function_Name>
  1182. <ogc:Function_Name nArgs="6">in5</ogc:Function_Name>
  1183. <ogc:Function_Name nArgs="7">in6</ogc:Function_Name>
  1184. <ogc:Function_Name nArgs="8">in7</ogc:Function_Name>
  1185. <ogc:Function_Name nArgs="9">in8</ogc:Function_Name>
  1186. <ogc:Function_Name nArgs="10">in9</ogc:Function_Name>
  1187. <ogc:Function_Name nArgs="2">InclusionFeatureCollection</ogc:Function_Name>
  1188. <ogc:Function_Name nArgs="1">int2bbool</ogc:Function_Name>
  1189. <ogc:Function_Name nArgs="1">int2ddouble</ogc:Function_Name>
  1190. <ogc:Function_Name nArgs="1">interiorPoint</ogc:Function_Name>
  1191. <ogc:Function_Name nArgs="2">interiorRingN</ogc:Function_Name>
  1192. <ogc:Function_Name nArgs="3">Interpolate</ogc:Function_Name>
  1193. <ogc:Function_Name nArgs="2">intersection</ogc:Function_Name>
  1194. <ogc:Function_Name nArgs="7">IntersectionFeatureCollection</ogc:Function_Name>
  1195. <ogc:Function_Name nArgs="2">intersects</ogc:Function_Name>
  1196. <ogc:Function_Name nArgs="2">intersects3D</ogc:Function_Name>
  1197. <ogc:Function_Name nArgs="1">isClosed</ogc:Function_Name>
  1198. <ogc:Function_Name nArgs="0">isCoverage</ogc:Function_Name>
  1199. <ogc:Function_Name nArgs="1">isEmpty</ogc:Function_Name>
  1200. <ogc:Function_Name nArgs="2">isLike</ogc:Function_Name>
  1201. <ogc:Function_Name nArgs="1">isNull</ogc:Function_Name>
  1202. <ogc:Function_Name nArgs="2">isometric</ogc:Function_Name>
  1203. <ogc:Function_Name nArgs="1">isRing</ogc:Function_Name>
  1204. <ogc:Function_Name nArgs="1">isSimple</ogc:Function_Name>
  1205. <ogc:Function_Name nArgs="1">isValid</ogc:Function_Name>
  1206. <ogc:Function_Name nArgs="3">isWithinDistance</ogc:Function_Name>
  1207. <ogc:Function_Name nArgs="3">isWithinDistance3D</ogc:Function_Name>
  1208. <ogc:Function_Name nArgs="2">Jenks</ogc:Function_Name>
  1209. <ogc:Function_Name nArgs="1">length</ogc:Function_Name>
  1210. <ogc:Function_Name nArgs="2">lessEqualThan</ogc:Function_Name>
  1211. <ogc:Function_Name nArgs="2">lessThan</ogc:Function_Name>
  1212. <ogc:Function_Name nArgs="1">list</ogc:Function_Name>
  1213. <ogc:Function_Name nArgs="1">log</ogc:Function_Name>
  1214. <ogc:Function_Name nArgs="4">LRSGeocode</ogc:Function_Name>
  1215. <ogc:Function_Name nArgs="5">LRSMeasure</ogc:Function_Name>
  1216. <ogc:Function_Name nArgs="5">LRSSegment</ogc:Function_Name>
  1217. <ogc:Function_Name nArgs="2">max</ogc:Function_Name>
  1218. <ogc:Function_Name nArgs="2">max_2</ogc:Function_Name>
  1219. <ogc:Function_Name nArgs="2">max_3</ogc:Function_Name>
  1220. <ogc:Function_Name nArgs="2">max_4</ogc:Function_Name>
  1221. <ogc:Function_Name nArgs="2">min</ogc:Function_Name>
  1222. <ogc:Function_Name nArgs="2">min_2</ogc:Function_Name>
  1223. <ogc:Function_Name nArgs="2">min_3</ogc:Function_Name>
  1224. <ogc:Function_Name nArgs="2">min_4</ogc:Function_Name>
  1225. <ogc:Function_Name nArgs="1">mincircle</ogc:Function_Name>
  1226. <ogc:Function_Name nArgs="1">minimumdiameter</ogc:Function_Name>
  1227. <ogc:Function_Name nArgs="1">minrectangle</ogc:Function_Name>
  1228. <ogc:Function_Name nArgs="2">modulo</ogc:Function_Name>
  1229. <ogc:Function_Name nArgs="2">MultiplyCoverages</ogc:Function_Name>
  1230. <ogc:Function_Name nArgs="3">Nearest</ogc:Function_Name>
  1231. <ogc:Function_Name nArgs="1">not</ogc:Function_Name>
  1232. <ogc:Function_Name nArgs="2">notEqualTo</ogc:Function_Name>
  1233. <ogc:Function_Name nArgs="2">numberFormat</ogc:Function_Name>
  1234. <ogc:Function_Name nArgs="5">numberFormat2</ogc:Function_Name>
  1235. <ogc:Function_Name nArgs="1">numGeometries</ogc:Function_Name>
  1236. <ogc:Function_Name nArgs="1">numInteriorRing</ogc:Function_Name>
  1237. <ogc:Function_Name nArgs="1">numPoints</ogc:Function_Name>
  1238. <ogc:Function_Name nArgs="1">octagonalenvelope</ogc:Function_Name>
  1239. <ogc:Function_Name nArgs="3">offset</ogc:Function_Name>
  1240. <ogc:Function_Name nArgs="2">overlaps</ogc:Function_Name>
  1241. <ogc:Function_Name nArgs="1">parameter</ogc:Function_Name>
  1242. <ogc:Function_Name nArgs="1">parseBoolean</ogc:Function_Name>
  1243. <ogc:Function_Name nArgs="1">parseDouble</ogc:Function_Name>
  1244. <ogc:Function_Name nArgs="1">parseInt</ogc:Function_Name>
  1245. <ogc:Function_Name nArgs="1">parseLong</ogc:Function_Name>
  1246. <ogc:Function_Name nArgs="0">pi</ogc:Function_Name>
  1247. <ogc:Function_Name nArgs="4">PointBuffers</ogc:Function_Name>
  1248. <ogc:Function_Name nArgs="2">pointN</ogc:Function_Name>
  1249. <ogc:Function_Name nArgs="7">PointStacker</ogc:Function_Name>
  1250. <ogc:Function_Name nArgs="6">PolygonExtraction</ogc:Function_Name>
  1251. <ogc:Function_Name nArgs="2">pow</ogc:Function_Name>
  1252. <ogc:Function_Name nArgs="1">property</ogc:Function_Name>
  1253. <ogc:Function_Name nArgs="1">PropertyExists</ogc:Function_Name>
  1254. <ogc:Function_Name nArgs="2">Quantile</ogc:Function_Name>
  1255. <ogc:Function_Name nArgs="3">Query</ogc:Function_Name>
  1256. <ogc:Function_Name nArgs="0">random</ogc:Function_Name>
  1257. <ogc:Function_Name nArgs="5">RangeLookup</ogc:Function_Name>
  1258. <ogc:Function_Name nArgs="1">RasterAsPointCollection</ogc:Function_Name>
  1259. <ogc:Function_Name nArgs="4">RasterZonalStatistics</ogc:Function_Name>
  1260. <ogc:Function_Name nArgs="5">Recode</ogc:Function_Name>
  1261. <ogc:Function_Name nArgs="2">RectangularClip</ogc:Function_Name>
  1262. <ogc:Function_Name nArgs="2">relate</ogc:Function_Name>
  1263. <ogc:Function_Name nArgs="3">relatePattern</ogc:Function_Name>
  1264. <ogc:Function_Name nArgs="3">Reproject</ogc:Function_Name>
  1265. <ogc:Function_Name nArgs="1">rint</ogc:Function_Name>
  1266. <ogc:Function_Name nArgs="1">round</ogc:Function_Name>
  1267. <ogc:Function_Name nArgs="1">round_2</ogc:Function_Name>
  1268. <ogc:Function_Name nArgs="1">roundDouble</ogc:Function_Name>
  1269. <ogc:Function_Name nArgs="6">ScaleCoverage</ogc:Function_Name>
  1270. <ogc:Function_Name nArgs="4">sdo_nn</ogc:Function_Name>
  1271. <ogc:Function_Name nArgs="2">setCRS</ogc:Function_Name>
  1272. <ogc:Function_Name nArgs="3">Simplify</ogc:Function_Name>
  1273. <ogc:Function_Name nArgs="1">sin</ogc:Function_Name>
  1274. <ogc:Function_Name nArgs="3">Snap</ogc:Function_Name>
  1275. <ogc:Function_Name nArgs="1">sqrt</ogc:Function_Name>
  1276. <ogc:Function_Name nArgs="2">StandardDeviation</ogc:Function_Name>
  1277. <ogc:Function_Name nArgs="1">startAngle</ogc:Function_Name>
  1278. <ogc:Function_Name nArgs="1">startPoint</ogc:Function_Name>
  1279. <ogc:Function_Name nArgs="1">strCapitalize</ogc:Function_Name>
  1280. <ogc:Function_Name nArgs="2">strConcat</ogc:Function_Name>
  1281. <ogc:Function_Name nArgs="2">strEndsWith</ogc:Function_Name>
  1282. <ogc:Function_Name nArgs="2">strEqualsIgnoreCase</ogc:Function_Name>
  1283. <ogc:Function_Name nArgs="2">strIndexOf</ogc:Function_Name>
  1284. <ogc:Function_Name nArgs="2">strLastIndexOf</ogc:Function_Name>
  1285. <ogc:Function_Name nArgs="1">strLength</ogc:Function_Name>
  1286. <ogc:Function_Name nArgs="2">strMatches</ogc:Function_Name>
  1287. <ogc:Function_Name nArgs="3">strPosition</ogc:Function_Name>
  1288. <ogc:Function_Name nArgs="4">strReplace</ogc:Function_Name>
  1289. <ogc:Function_Name nArgs="2">strStartsWith</ogc:Function_Name>
  1290. <ogc:Function_Name nArgs="3">strSubstring</ogc:Function_Name>
  1291. <ogc:Function_Name nArgs="2">strSubstringStart</ogc:Function_Name>
  1292. <ogc:Function_Name nArgs="1">strToLowerCase</ogc:Function_Name>
  1293. <ogc:Function_Name nArgs="1">strToUpperCase</ogc:Function_Name>
  1294. <ogc:Function_Name nArgs="1">strTrim</ogc:Function_Name>
  1295. <ogc:Function_Name nArgs="3">strTrim2</ogc:Function_Name>
  1296. <ogc:Function_Name nArgs="2">StyleCoverage</ogc:Function_Name>
  1297. <ogc:Function_Name nArgs="2">symDifference</ogc:Function_Name>
  1298. <ogc:Function_Name nArgs="1">tan</ogc:Function_Name>
  1299. <ogc:Function_Name nArgs="1">toDegrees</ogc:Function_Name>
  1300. <ogc:Function_Name nArgs="1">toRadians</ogc:Function_Name>
  1301. <ogc:Function_Name nArgs="2">touches</ogc:Function_Name>
  1302. <ogc:Function_Name nArgs="1">toWKT</ogc:Function_Name>
  1303. <ogc:Function_Name nArgs="2">Transform</ogc:Function_Name>
  1304. <ogc:Function_Name nArgs="2">union</ogc:Function_Name>
  1305. <ogc:Function_Name nArgs="2">UnionFeatureCollection</ogc:Function_Name>
  1306. <ogc:Function_Name nArgs="2">Unique</ogc:Function_Name>
  1307. <ogc:Function_Name nArgs="2">UniqueInterval</ogc:Function_Name>
  1308. <ogc:Function_Name nArgs="6">VectorToRaster</ogc:Function_Name>
  1309. <ogc:Function_Name nArgs="3">VectorZonalStatistics</ogc:Function_Name>
  1310. <ogc:Function_Name nArgs="1">vertices</ogc:Function_Name>
  1311. <ogc:Function_Name nArgs="2">within</ogc:Function_Name>
  1312. </ogc:Function_Names>
  1313. </ogc:Functions>
  1314. </ogc:Arithmetic_Operators>
  1315. </ogc:Scalar_Capabilities>
  1316. </ogc:Filter_Capabilities>
  1317. </WFS_Capabilities>
  1318. <?php
  1319. }
  1320. private function _getSchemaLocationString() {
  1321. $schemaLocations = array();
  1322. // $schemaLocations[] = '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
  1323. return implode(' ', $schemaLocations);
  1324. }
  1325. private function _getXmlNamespaceList() {
  1326. $namespaceList = $this->_getSourceNsList();
  1327. $namespaceListOut = array();
  1328. foreach ($namespaceList as $nsObj) {
  1329. $ns = "p5_{$nsObj[0]}_{$nsObj[1]}";
  1330. $uri = "https://biuro.biall-net.pl/wfs/{$nsObj[0]}/{$nsObj[1]}";
  1331. $namespaceListOut[] = 'xmlns:' . $ns . '="' . $uri . '"';
  1332. }
  1333. return implode(' ', $namespaceListOut);
  1334. }
  1335. private function _getSourceNsList() {
  1336. $usrObjList = array();
  1337. $tblsAcl = $this->_usrAcl->getTablesAcl();
  1338. foreach ($tblsAcl as $tblAcl) {
  1339. $dataSourceName = 'default_db';// TODO: getSourceName
  1340. $tblName = $tblAcl->getName();
  1341. $usrObjList[] = array($dataSourceName, $tblName);
  1342. }
  1343. return $usrObjList;
  1344. }
  1345. private function _printGetCapabilitiesXml($wfsServerUrl) {
  1346. ?>
  1347. <GetCapabilities>
  1348. <DCPType>
  1349. <HTTP>
  1350. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetCapabilities" />
  1351. </HTTP>
  1352. </DCPType>
  1353. <DCPType>
  1354. <HTTP>
  1355. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1356. </HTTP>
  1357. </DCPType>
  1358. </GetCapabilities>
  1359. <?php
  1360. }
  1361. private function _printDescribeFeatureTypeXml($wfsServerUrl) {
  1362. ?>
  1363. <DescribeFeatureType>
  1364. <SchemaDescriptionLanguage>
  1365. <XMLSCHEMA />
  1366. </SchemaDescriptionLanguage>
  1367. <DCPType>
  1368. <HTTP>
  1369. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=DescribeFeatureType" />
  1370. </HTTP>
  1371. </DCPType>
  1372. <DCPType>
  1373. <HTTP>
  1374. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1375. </HTTP>
  1376. </DCPType>
  1377. </DescribeFeatureType>
  1378. <?php
  1379. }
  1380. private function _printGetFeatureXml($wfsServerUrl) {
  1381. ?>
  1382. <GetFeature>
  1383. <ResultFormat>
  1384. <WFSKMLOutputFormat />
  1385. <GML2 />
  1386. <GML3 />
  1387. <SHAPE-ZIP />
  1388. <CSV />
  1389. <JSON />
  1390. </ResultFormat>
  1391. <DCPType>
  1392. <HTTP>
  1393. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeature" />
  1394. </HTTP>
  1395. </DCPType>
  1396. <DCPType>
  1397. <HTTP>
  1398. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1399. </HTTP>
  1400. </DCPType>
  1401. </GetFeature>
  1402. <?php
  1403. }
  1404. private function _printTransactionXml($wfsServerUrl) {
  1405. ?>
  1406. <Transaction>
  1407. <DCPType>
  1408. <HTTP>
  1409. <Get onlineResource="<?php echo $wfsServerUrl; ?>?request=Transaction" />
  1410. </HTTP>
  1411. </DCPType>
  1412. <DCPType>
  1413. <HTTP>
  1414. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1415. </HTTP>
  1416. </DCPType>
  1417. </Transaction>
  1418. <?php
  1419. }
  1420. private function _printLockFeatureXml($wfsServerUrl) {
  1421. ?>
  1422. <LockFeature>
  1423. <DCPType>
  1424. <HTTP>
  1425. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=LockFeature" />
  1426. </HTTP>
  1427. </DCPType>
  1428. <DCPType>
  1429. <HTTP>
  1430. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1431. </HTTP>
  1432. </DCPType>
  1433. </LockFeature>
  1434. <?php
  1435. }
  1436. private function _printGetFeatureWithLockXml($wfsServerUrl) {
  1437. ?>
  1438. <GetFeatureWithLock>
  1439. <ResultFormat>
  1440. <GML2 />
  1441. </ResultFormat>
  1442. <DCPType>
  1443. <HTTP>
  1444. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeatureWithLock" />
  1445. </HTTP>
  1446. </DCPType>
  1447. <DCPType>
  1448. <HTTP>
  1449. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1450. </HTTP>
  1451. </DCPType>
  1452. </GetFeatureWithLock>
  1453. <?php
  1454. }
  1455. private function _printFeatureTypeListXml() {
  1456. // TODO: get list from userAcl
  1457. $featureTypes = array();
  1458. $tblsAcl = $this->_usrAcl->getTablesAcl();
  1459. foreach ($tblsAcl as $tblAcl) {
  1460. $dataSourceName = 'default_db';// TODO: getSourceName
  1461. $tblName = $tblAcl->getName();
  1462. $usrObjList[] = array($dataSourceName, $tblName);
  1463. $featureType = array();
  1464. $featureType['ns'] = "p5_{$dataSourceName}";
  1465. $featureType['Title'] = $tblAcl->getRawLabel();
  1466. $featureType['Abstract'] = $tblAcl->getRawLabel();
  1467. $featureType['Keywords'] = array();
  1468. $featureType['Keywords'][] = $tblAcl->getID();
  1469. $featureType['Keywords'][] = $tblName;
  1470. $featureType['Keywords'][] = $tblAcl->getRawLabel();
  1471. $featureType['Keywords'] = implode(", ", $featureType['Keywords']);
  1472. $featureType['SRS'] = "EPSG:4326";
  1473. $featureType['LatLongBoundingBox'] = array();// TODO: feature LatLongBoundingBox
  1474. $featureType['LatLongBoundingBox']['minx'] = "8.12328509871721";
  1475. $featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
  1476. $featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
  1477. $featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
  1478. $featureTypes[$tblName] = $featureType;
  1479. }
  1480. /*
  1481. <FeatureType>
  1482. <Name>ppr06:AMBITIPAESAGGIO</Name>
  1483. <Title>AMBITIPAESAGGIO</Title>
  1484. <Abstract />
  1485. <Keywords>features, AMBITIPAESAGGIO</Keywords>
  1486. <SRS>EPSG:4326</SRS>
  1487. <LatLongBoundingBox minx="8.12328509871721" miny="38.8575126897477" maxx="9.838674658246807" maxy="41.31378404137082" />
  1488. </FeatureType>
  1489. */
  1490. $featureTypesXml = '';
  1491. foreach ($featureTypes as $tblName => $feature) {
  1492. $featureTypesXml .= '<FeatureType>' . "\n";
  1493. $featureTypesXml .= '<Name>' . "{$feature['ns']}:{$tblName}" . '</Name>' . "\n";
  1494. $featureTypesXml .= '<Title>' . "{$feature['Title']}" . '</Title>' . "\n";
  1495. if (!empty($feature['Abstract'])) {
  1496. $featureTypesXml .= '<Abstract>' . "{$feature['Abstract']}" . '</Abstract>' . "\n";
  1497. } else {
  1498. $featureTypesXml .= '<Abstract/>' . "\n";
  1499. }
  1500. if (!empty($feature['Keywords'])) {
  1501. $featureTypesXml .= '<Keywords>' . "{$feature['Keywords']}" . '</Keywords>' . "\n";
  1502. } else {
  1503. $featureTypesXml .= '<Keywords/>' . "\n";
  1504. }
  1505. $featureTypesXml .= '<SRS>' . "{$feature['SRS']}" . '</SRS>' . "\n";
  1506. if (!empty($feature['LatLongBoundingBox'])) {
  1507. $latLongBoundingBoxOut = array();
  1508. $latLongBoundingBoxOut[] = 'minx="' . $feature['LatLongBoundingBox']['minx'] . '"';
  1509. $latLongBoundingBoxOut[] = 'miny="' . $feature['LatLongBoundingBox']['miny'] . '"';
  1510. $latLongBoundingBoxOut[] = 'maxx="' . $feature['LatLongBoundingBox']['maxx'] . '"';
  1511. $latLongBoundingBoxOut[] = 'maxy="' . $feature['LatLongBoundingBox']['maxy'] . '"';
  1512. $featureTypesXml .= '<LatLongBoundingBox ' . implode(' ', $latLongBoundingBoxOut) . ' />';
  1513. }
  1514. $featureTypesXml .= '</FeatureType>' . "\n";
  1515. }
  1516. return $featureTypesXml;
  1517. }
  1518. }