WfsServer.php 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  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 describeFeatureTypeAction() {
  848. $type = V::get('TYPENAME', '', $_REQUEST);
  849. if (empty($type)) {
  850. throw new HttpException("Wrong param TYPENAME", 400);
  851. }
  852. $typeEx = explode(':', $type);
  853. if (count($typeEx) != 2) {
  854. throw new HttpException("Wrong param TYPENAME", 400);
  855. }
  856. return $this->getDescribeFeatureType($typeEx[0], $typeEx[1]);
  857. }
  858. private function getDescribeFeatureType($nsPrefix, $type) {
  859. $typeName = "{$nsPrefix}:{$type}";
  860. $acl = $this->getAclFromTypeName($typeName);
  861. $wfsNs = 'p5_default_db_' . $type;//$nsPrefix;
  862. $wfsNsUri = 'https://biuro.biall-net.pl/wfs/' . substr($nsPrefix, 3) . '/' . $type;
  863. if (empty($type)) {
  864. throw new HttpException("Feature Type Name not defined", 400);
  865. }
  866. if (!$this->isAllowedFeatureType($nsPrefix, $type)) {
  867. throw new Api_WfsException("Could not find type: " . htmlspecialchars($type));
  868. }
  869. $typeName = $type . 'Type';
  870. $fldList = $acl->getRealFieldList();
  871. header('Content-type: application/xml');
  872. // <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://webgis.regione.sardegna.it:80/geoserver/schemas/gml/2.1.2/feature.xsd"/>
  873. // <xsd:element name="{type}" substitutionGroup="gml:_Feature" type="dbu:{typeName}"/>
  874. $dom = new DOMDocument('1.0', 'utf-8');
  875. $dom->formatOutput = true;
  876. $dom->preserveWhiteSpace = false;
  877. $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
  878. $dom->appendChild($rootNode);
  879. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  880. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
  881. $rootNode->setAttribute('elementFormDefault', 'qualified');
  882. $rootNode->setAttribute('targetNamespace', $wfsNsUri);
  883. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  884. $rootNode->appendChild($cTypeNode);
  885. $cTypeNode->setAttribute('name', $typeName);
  886. $cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
  887. $cTypeNode->appendChild($cConNode);
  888. $extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
  889. $cConNode->appendChild($extNode);
  890. $extNode->setAttribute('base', 'gml:AbstractFeatureType');
  891. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  892. $extNode->appendChild($seqNode);
  893. // <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
  894. $pKeyField = $acl->getPrimaryKeyField();
  895. foreach ($fldList as $fldName) {
  896. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  897. $seqNode->appendChild($elNode);
  898. $elNode->setAttribute('name', $fldName);
  899. $minOccurs = 0;
  900. if ($pKeyField == $fldName) {
  901. $minOccurs = '1';
  902. } else {
  903. $minOccurs = '0';
  904. }
  905. $elNode->setAttribute('minOccurs', $minOccurs);
  906. if ($acl->isIntegerField($fldName)) {
  907. $fldType = 'xsd:integer';
  908. }
  909. else if ($acl->isDecimalField($fldName)) {
  910. $fldType = 'xsd:decimal';
  911. }
  912. else if ($acl->isDateField($fldName)) {
  913. $fldType = 'xsd:date';
  914. }
  915. else if ($acl->isDateTimeField($fldName)) {
  916. $fldType = 'xsd:dateTime';
  917. }
  918. else if ($acl->isGeomField($fldName)) {
  919. $fldType = 'gml:GeometryPropertyType';
  920. //$fldType = 'gml:Polygon';// nie działa musi być gml:GeometryPropertyType
  921. }
  922. else {
  923. $fldType = 'xsd:string';
  924. }
  925. $elNode->setAttribute('type', $fldType);
  926. $elNode->setAttribute('nillable', 'true');
  927. }
  928. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  929. $rootNode->appendChild($elNode);
  930. $elNode->setAttribute('name', $type);
  931. $elNode->setAttribute('type', $wfsNs . ':' . $typeName);
  932. echo $dom->saveXML();
  933. //print_r($acl);
  934. }
  935. public function isAllowedFeatureType($nsPrefix, $type) {
  936. if ('p5_' != substr($nsPrefix, 0, 3)) return false;
  937. if ('p5_default_db' == $nsPrefix) {
  938. $typeName = "p5_default_db:{$type}";
  939. try {
  940. $acl = $this->getAclFromTypeName($typeName);
  941. } catch (Exception $e) {
  942. return false;
  943. }
  944. if ($acl) {
  945. return true;
  946. }
  947. }
  948. return false;
  949. }
  950. public function getCapabilitiesAction() {
  951. $wfsServerUrl = 'https://biuro.biall-net.pl/dev-pl/se-feature-api/wfs.php/xml/wfs/default_db';
  952. $serviceTitle = "BIALL-NET Web Feature Service";
  953. $serviceDescription = "This is the reference implementation of WFS 1.0.0 and WFS 1.1.0, supports all WFS operations including Transaction.";
  954. //header('Content-type: application/xml; charset="utf-8"');
  955. header('Content-type: application/xml');
  956. echo '<?xml version="1.0" encoding="UTF-8"?>';
  957. ?>
  958. <WFS_Capabilities version="1.0.0"
  959. xmlns="http://www.opengis.net/wfs"
  960. xmlns:ogc="http://www.opengis.net/ogc"
  961. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  962. <?php echo $this->_getXmlNamespaceList(); ?>
  963. xsi:schemaLocation="http://www.opengis.net/wfs <?php echo $this->_getSchemaLocationString(); ?>">
  964. <Service>
  965. <Name>WFS</Name>
  966. <Title><?php echo $serviceTitle; ?></Title>
  967. <Abstract><?php echo $serviceDescription; ?></Abstract>
  968. <Keywords>WFS, WMS</Keywords>
  969. <OnlineResource><?php echo $wfsServerUrl; ?></OnlineResource>
  970. <Fees>NONE</Fees>
  971. <AccessConstraints>NONE</AccessConstraints>
  972. </Service>
  973. <Capability>
  974. <Request>
  975. <?php $this->_printGetCapabilitiesXml($wfsServerUrl); ?>
  976. <?php $this->_printDescribeFeatureTypeXml($wfsServerUrl); ?>
  977. <?php $this->_printGetFeatureXml($wfsServerUrl); ?>
  978. <?php $this->_printTransactionXml($wfsServerUrl); ?>
  979. <?php $this->_printLockFeatureXml($wfsServerUrl); ?>
  980. <?php $this->_printGetFeatureWithLockXml($wfsServerUrl); ?>
  981. </Request>
  982. </Capability>
  983. <FeatureTypeList>
  984. <Operations>
  985. <Query />
  986. <Insert />
  987. <Update />
  988. <Delete />
  989. <Lock />
  990. </Operations>
  991. <?php echo $this->_printFeatureTypeListXml(); ?>
  992. </FeatureTypeList>
  993. <ogc:Filter_Capabilities>
  994. <ogc:Spatial_Capabilities>
  995. <ogc:Spatial_Operators>
  996. <ogc:Disjoint />
  997. <ogc:Equals />
  998. <ogc:DWithin />
  999. <ogc:Beyond />
  1000. <ogc:Intersect />
  1001. <ogc:Touches />
  1002. <ogc:Crosses />
  1003. <ogc:Within />
  1004. <ogc:Contains />
  1005. <ogc:Overlaps />
  1006. <ogc:BBOX />
  1007. </ogc:Spatial_Operators>
  1008. </ogc:Spatial_Capabilities>
  1009. <ogc:Scalar_Capabilities>
  1010. <ogc:Logical_Operators />
  1011. <ogc:Comparison_Operators>
  1012. <ogc:Simple_Comparisons />
  1013. <ogc:Between />
  1014. <ogc:Like />
  1015. <ogc:NullCheck />
  1016. </ogc:Comparison_Operators>
  1017. <ogc:Arithmetic_Operators>
  1018. <ogc:Simple_Arithmetic />
  1019. <ogc:Functions>
  1020. <ogc:Function_Names>
  1021. <ogc:Function_Name nArgs="1">abs</ogc:Function_Name>
  1022. <ogc:Function_Name nArgs="1">abs_2</ogc:Function_Name>
  1023. <ogc:Function_Name nArgs="1">abs_3</ogc:Function_Name>
  1024. <ogc:Function_Name nArgs="1">abs_4</ogc:Function_Name>
  1025. <ogc:Function_Name nArgs="1">acos</ogc:Function_Name>
  1026. <ogc:Function_Name nArgs="2">AddCoverages</ogc:Function_Name>
  1027. <ogc:Function_Name nArgs="4">Aggregate</ogc:Function_Name>
  1028. <ogc:Function_Name nArgs="1">Area</ogc:Function_Name>
  1029. <ogc:Function_Name nArgs="1">area2</ogc:Function_Name>
  1030. <ogc:Function_Name nArgs="3">AreaGrid</ogc:Function_Name>
  1031. <ogc:Function_Name nArgs="1">asin</ogc:Function_Name>
  1032. <ogc:Function_Name nArgs="1">atan</ogc:Function_Name>
  1033. <ogc:Function_Name nArgs="2">atan2</ogc:Function_Name>
  1034. <ogc:Function_Name nArgs="14">BarnesSurface</ogc:Function_Name>
  1035. <ogc:Function_Name nArgs="3">between</ogc:Function_Name>
  1036. <ogc:Function_Name nArgs="1">boundary</ogc:Function_Name>
  1037. <ogc:Function_Name nArgs="1">boundaryDimension</ogc:Function_Name>
  1038. <ogc:Function_Name nArgs="1">Bounds</ogc:Function_Name>
  1039. <ogc:Function_Name nArgs="2">buffer</ogc:Function_Name>
  1040. <ogc:Function_Name nArgs="3">BufferFeatureCollection</ogc:Function_Name>
  1041. <ogc:Function_Name nArgs="3">bufferWithSegments</ogc:Function_Name>
  1042. <ogc:Function_Name nArgs="7">Categorize</ogc:Function_Name>
  1043. <ogc:Function_Name nArgs="1">ceil</ogc:Function_Name>
  1044. <ogc:Function_Name nArgs="1">Centroid</ogc:Function_Name>
  1045. <ogc:Function_Name nArgs="2">classify</ogc:Function_Name>
  1046. <ogc:Function_Name nArgs="2">Clip</ogc:Function_Name>
  1047. <ogc:Function_Name nArgs="1">CollectGeometries</ogc:Function_Name>
  1048. <ogc:Function_Name nArgs="1">Collection_Average</ogc:Function_Name>
  1049. <ogc:Function_Name nArgs="1">Collection_Bounds</ogc:Function_Name>
  1050. <ogc:Function_Name nArgs="0">Collection_Count</ogc:Function_Name>
  1051. <ogc:Function_Name nArgs="1">Collection_Max</ogc:Function_Name>
  1052. <ogc:Function_Name nArgs="1">Collection_Median</ogc:Function_Name>
  1053. <ogc:Function_Name nArgs="1">Collection_Min</ogc:Function_Name>
  1054. <ogc:Function_Name nArgs="1">Collection_Sum</ogc:Function_Name>
  1055. <ogc:Function_Name nArgs="1">Collection_Unique</ogc:Function_Name>
  1056. <ogc:Function_Name nArgs="1">Concatenate</ogc:Function_Name>
  1057. <ogc:Function_Name nArgs="2">contains</ogc:Function_Name>
  1058. <ogc:Function_Name nArgs="7">Contour</ogc:Function_Name>
  1059. <ogc:Function_Name nArgs="2">convert</ogc:Function_Name>
  1060. <ogc:Function_Name nArgs="1">convexHull</ogc:Function_Name>
  1061. <ogc:Function_Name nArgs="1">cos</ogc:Function_Name>
  1062. <ogc:Function_Name nArgs="1">Count</ogc:Function_Name>
  1063. <ogc:Function_Name nArgs="2">CropCoverage</ogc:Function_Name>
  1064. <ogc:Function_Name nArgs="2">crosses</ogc:Function_Name>
  1065. <ogc:Function_Name nArgs="2">dateFormat</ogc:Function_Name>
  1066. <ogc:Function_Name nArgs="2">dateParse</ogc:Function_Name>
  1067. <ogc:Function_Name nArgs="2">difference</ogc:Function_Name>
  1068. <ogc:Function_Name nArgs="1">dimension</ogc:Function_Name>
  1069. <ogc:Function_Name nArgs="2">disjoint</ogc:Function_Name>
  1070. <ogc:Function_Name nArgs="2">disjoint3D</ogc:Function_Name>
  1071. <ogc:Function_Name nArgs="2">distance</ogc:Function_Name>
  1072. <ogc:Function_Name nArgs="2">distance3D</ogc:Function_Name>
  1073. <ogc:Function_Name nArgs="1">double2bool</ogc:Function_Name>
  1074. <ogc:Function_Name nArgs="1">endAngle</ogc:Function_Name>
  1075. <ogc:Function_Name nArgs="1">endPoint</ogc:Function_Name>
  1076. <ogc:Function_Name nArgs="1">env</ogc:Function_Name>
  1077. <ogc:Function_Name nArgs="1">envelope</ogc:Function_Name>
  1078. <ogc:Function_Name nArgs="2">EqualInterval</ogc:Function_Name>
  1079. <ogc:Function_Name nArgs="2">equalsExact</ogc:Function_Name>
  1080. <ogc:Function_Name nArgs="3">equalsExactTolerance</ogc:Function_Name>
  1081. <ogc:Function_Name nArgs="2">equalTo</ogc:Function_Name>
  1082. <ogc:Function_Name nArgs="1">exp</ogc:Function_Name>
  1083. <ogc:Function_Name nArgs="1">exteriorRing</ogc:Function_Name>
  1084. <ogc:Function_Name nArgs="3">Feature</ogc:Function_Name>
  1085. <ogc:Function_Name nArgs="1">floor</ogc:Function_Name>
  1086. <ogc:Function_Name nArgs="1">geometryType</ogc:Function_Name>
  1087. <ogc:Function_Name nArgs="1">geomFromWKT</ogc:Function_Name>
  1088. <ogc:Function_Name nArgs="1">geomLength</ogc:Function_Name>
  1089. <ogc:Function_Name nArgs="2">getGeometryN</ogc:Function_Name>
  1090. <ogc:Function_Name nArgs="1">getX</ogc:Function_Name>
  1091. <ogc:Function_Name nArgs="1">getY</ogc:Function_Name>
  1092. <ogc:Function_Name nArgs="1">getz</ogc:Function_Name>
  1093. <ogc:Function_Name nArgs="2">greaterEqualThan</ogc:Function_Name>
  1094. <ogc:Function_Name nArgs="2">greaterThan</ogc:Function_Name>
  1095. <ogc:Function_Name nArgs="5">Grid</ogc:Function_Name>
  1096. <ogc:Function_Name nArgs="7">Heatmap</ogc:Function_Name>
  1097. <ogc:Function_Name nArgs="0">id</ogc:Function_Name>
  1098. <ogc:Function_Name nArgs="2">IEEEremainder</ogc:Function_Name>
  1099. <ogc:Function_Name nArgs="3">if_then_else</ogc:Function_Name>
  1100. <ogc:Function_Name nArgs="11">in10</ogc:Function_Name>
  1101. <ogc:Function_Name nArgs="3">in2</ogc:Function_Name>
  1102. <ogc:Function_Name nArgs="4">in3</ogc:Function_Name>
  1103. <ogc:Function_Name nArgs="5">in4</ogc:Function_Name>
  1104. <ogc:Function_Name nArgs="6">in5</ogc:Function_Name>
  1105. <ogc:Function_Name nArgs="7">in6</ogc:Function_Name>
  1106. <ogc:Function_Name nArgs="8">in7</ogc:Function_Name>
  1107. <ogc:Function_Name nArgs="9">in8</ogc:Function_Name>
  1108. <ogc:Function_Name nArgs="10">in9</ogc:Function_Name>
  1109. <ogc:Function_Name nArgs="2">InclusionFeatureCollection</ogc:Function_Name>
  1110. <ogc:Function_Name nArgs="1">int2bbool</ogc:Function_Name>
  1111. <ogc:Function_Name nArgs="1">int2ddouble</ogc:Function_Name>
  1112. <ogc:Function_Name nArgs="1">interiorPoint</ogc:Function_Name>
  1113. <ogc:Function_Name nArgs="2">interiorRingN</ogc:Function_Name>
  1114. <ogc:Function_Name nArgs="3">Interpolate</ogc:Function_Name>
  1115. <ogc:Function_Name nArgs="2">intersection</ogc:Function_Name>
  1116. <ogc:Function_Name nArgs="7">IntersectionFeatureCollection</ogc:Function_Name>
  1117. <ogc:Function_Name nArgs="2">intersects</ogc:Function_Name>
  1118. <ogc:Function_Name nArgs="2">intersects3D</ogc:Function_Name>
  1119. <ogc:Function_Name nArgs="1">isClosed</ogc:Function_Name>
  1120. <ogc:Function_Name nArgs="0">isCoverage</ogc:Function_Name>
  1121. <ogc:Function_Name nArgs="1">isEmpty</ogc:Function_Name>
  1122. <ogc:Function_Name nArgs="2">isLike</ogc:Function_Name>
  1123. <ogc:Function_Name nArgs="1">isNull</ogc:Function_Name>
  1124. <ogc:Function_Name nArgs="2">isometric</ogc:Function_Name>
  1125. <ogc:Function_Name nArgs="1">isRing</ogc:Function_Name>
  1126. <ogc:Function_Name nArgs="1">isSimple</ogc:Function_Name>
  1127. <ogc:Function_Name nArgs="1">isValid</ogc:Function_Name>
  1128. <ogc:Function_Name nArgs="3">isWithinDistance</ogc:Function_Name>
  1129. <ogc:Function_Name nArgs="3">isWithinDistance3D</ogc:Function_Name>
  1130. <ogc:Function_Name nArgs="2">Jenks</ogc:Function_Name>
  1131. <ogc:Function_Name nArgs="1">length</ogc:Function_Name>
  1132. <ogc:Function_Name nArgs="2">lessEqualThan</ogc:Function_Name>
  1133. <ogc:Function_Name nArgs="2">lessThan</ogc:Function_Name>
  1134. <ogc:Function_Name nArgs="1">list</ogc:Function_Name>
  1135. <ogc:Function_Name nArgs="1">log</ogc:Function_Name>
  1136. <ogc:Function_Name nArgs="4">LRSGeocode</ogc:Function_Name>
  1137. <ogc:Function_Name nArgs="5">LRSMeasure</ogc:Function_Name>
  1138. <ogc:Function_Name nArgs="5">LRSSegment</ogc:Function_Name>
  1139. <ogc:Function_Name nArgs="2">max</ogc:Function_Name>
  1140. <ogc:Function_Name nArgs="2">max_2</ogc:Function_Name>
  1141. <ogc:Function_Name nArgs="2">max_3</ogc:Function_Name>
  1142. <ogc:Function_Name nArgs="2">max_4</ogc:Function_Name>
  1143. <ogc:Function_Name nArgs="2">min</ogc:Function_Name>
  1144. <ogc:Function_Name nArgs="2">min_2</ogc:Function_Name>
  1145. <ogc:Function_Name nArgs="2">min_3</ogc:Function_Name>
  1146. <ogc:Function_Name nArgs="2">min_4</ogc:Function_Name>
  1147. <ogc:Function_Name nArgs="1">mincircle</ogc:Function_Name>
  1148. <ogc:Function_Name nArgs="1">minimumdiameter</ogc:Function_Name>
  1149. <ogc:Function_Name nArgs="1">minrectangle</ogc:Function_Name>
  1150. <ogc:Function_Name nArgs="2">modulo</ogc:Function_Name>
  1151. <ogc:Function_Name nArgs="2">MultiplyCoverages</ogc:Function_Name>
  1152. <ogc:Function_Name nArgs="3">Nearest</ogc:Function_Name>
  1153. <ogc:Function_Name nArgs="1">not</ogc:Function_Name>
  1154. <ogc:Function_Name nArgs="2">notEqualTo</ogc:Function_Name>
  1155. <ogc:Function_Name nArgs="2">numberFormat</ogc:Function_Name>
  1156. <ogc:Function_Name nArgs="5">numberFormat2</ogc:Function_Name>
  1157. <ogc:Function_Name nArgs="1">numGeometries</ogc:Function_Name>
  1158. <ogc:Function_Name nArgs="1">numInteriorRing</ogc:Function_Name>
  1159. <ogc:Function_Name nArgs="1">numPoints</ogc:Function_Name>
  1160. <ogc:Function_Name nArgs="1">octagonalenvelope</ogc:Function_Name>
  1161. <ogc:Function_Name nArgs="3">offset</ogc:Function_Name>
  1162. <ogc:Function_Name nArgs="2">overlaps</ogc:Function_Name>
  1163. <ogc:Function_Name nArgs="1">parameter</ogc:Function_Name>
  1164. <ogc:Function_Name nArgs="1">parseBoolean</ogc:Function_Name>
  1165. <ogc:Function_Name nArgs="1">parseDouble</ogc:Function_Name>
  1166. <ogc:Function_Name nArgs="1">parseInt</ogc:Function_Name>
  1167. <ogc:Function_Name nArgs="1">parseLong</ogc:Function_Name>
  1168. <ogc:Function_Name nArgs="0">pi</ogc:Function_Name>
  1169. <ogc:Function_Name nArgs="4">PointBuffers</ogc:Function_Name>
  1170. <ogc:Function_Name nArgs="2">pointN</ogc:Function_Name>
  1171. <ogc:Function_Name nArgs="7">PointStacker</ogc:Function_Name>
  1172. <ogc:Function_Name nArgs="6">PolygonExtraction</ogc:Function_Name>
  1173. <ogc:Function_Name nArgs="2">pow</ogc:Function_Name>
  1174. <ogc:Function_Name nArgs="1">property</ogc:Function_Name>
  1175. <ogc:Function_Name nArgs="1">PropertyExists</ogc:Function_Name>
  1176. <ogc:Function_Name nArgs="2">Quantile</ogc:Function_Name>
  1177. <ogc:Function_Name nArgs="3">Query</ogc:Function_Name>
  1178. <ogc:Function_Name nArgs="0">random</ogc:Function_Name>
  1179. <ogc:Function_Name nArgs="5">RangeLookup</ogc:Function_Name>
  1180. <ogc:Function_Name nArgs="1">RasterAsPointCollection</ogc:Function_Name>
  1181. <ogc:Function_Name nArgs="4">RasterZonalStatistics</ogc:Function_Name>
  1182. <ogc:Function_Name nArgs="5">Recode</ogc:Function_Name>
  1183. <ogc:Function_Name nArgs="2">RectangularClip</ogc:Function_Name>
  1184. <ogc:Function_Name nArgs="2">relate</ogc:Function_Name>
  1185. <ogc:Function_Name nArgs="3">relatePattern</ogc:Function_Name>
  1186. <ogc:Function_Name nArgs="3">Reproject</ogc:Function_Name>
  1187. <ogc:Function_Name nArgs="1">rint</ogc:Function_Name>
  1188. <ogc:Function_Name nArgs="1">round</ogc:Function_Name>
  1189. <ogc:Function_Name nArgs="1">round_2</ogc:Function_Name>
  1190. <ogc:Function_Name nArgs="1">roundDouble</ogc:Function_Name>
  1191. <ogc:Function_Name nArgs="6">ScaleCoverage</ogc:Function_Name>
  1192. <ogc:Function_Name nArgs="4">sdo_nn</ogc:Function_Name>
  1193. <ogc:Function_Name nArgs="2">setCRS</ogc:Function_Name>
  1194. <ogc:Function_Name nArgs="3">Simplify</ogc:Function_Name>
  1195. <ogc:Function_Name nArgs="1">sin</ogc:Function_Name>
  1196. <ogc:Function_Name nArgs="3">Snap</ogc:Function_Name>
  1197. <ogc:Function_Name nArgs="1">sqrt</ogc:Function_Name>
  1198. <ogc:Function_Name nArgs="2">StandardDeviation</ogc:Function_Name>
  1199. <ogc:Function_Name nArgs="1">startAngle</ogc:Function_Name>
  1200. <ogc:Function_Name nArgs="1">startPoint</ogc:Function_Name>
  1201. <ogc:Function_Name nArgs="1">strCapitalize</ogc:Function_Name>
  1202. <ogc:Function_Name nArgs="2">strConcat</ogc:Function_Name>
  1203. <ogc:Function_Name nArgs="2">strEndsWith</ogc:Function_Name>
  1204. <ogc:Function_Name nArgs="2">strEqualsIgnoreCase</ogc:Function_Name>
  1205. <ogc:Function_Name nArgs="2">strIndexOf</ogc:Function_Name>
  1206. <ogc:Function_Name nArgs="2">strLastIndexOf</ogc:Function_Name>
  1207. <ogc:Function_Name nArgs="1">strLength</ogc:Function_Name>
  1208. <ogc:Function_Name nArgs="2">strMatches</ogc:Function_Name>
  1209. <ogc:Function_Name nArgs="3">strPosition</ogc:Function_Name>
  1210. <ogc:Function_Name nArgs="4">strReplace</ogc:Function_Name>
  1211. <ogc:Function_Name nArgs="2">strStartsWith</ogc:Function_Name>
  1212. <ogc:Function_Name nArgs="3">strSubstring</ogc:Function_Name>
  1213. <ogc:Function_Name nArgs="2">strSubstringStart</ogc:Function_Name>
  1214. <ogc:Function_Name nArgs="1">strToLowerCase</ogc:Function_Name>
  1215. <ogc:Function_Name nArgs="1">strToUpperCase</ogc:Function_Name>
  1216. <ogc:Function_Name nArgs="1">strTrim</ogc:Function_Name>
  1217. <ogc:Function_Name nArgs="3">strTrim2</ogc:Function_Name>
  1218. <ogc:Function_Name nArgs="2">StyleCoverage</ogc:Function_Name>
  1219. <ogc:Function_Name nArgs="2">symDifference</ogc:Function_Name>
  1220. <ogc:Function_Name nArgs="1">tan</ogc:Function_Name>
  1221. <ogc:Function_Name nArgs="1">toDegrees</ogc:Function_Name>
  1222. <ogc:Function_Name nArgs="1">toRadians</ogc:Function_Name>
  1223. <ogc:Function_Name nArgs="2">touches</ogc:Function_Name>
  1224. <ogc:Function_Name nArgs="1">toWKT</ogc:Function_Name>
  1225. <ogc:Function_Name nArgs="2">Transform</ogc:Function_Name>
  1226. <ogc:Function_Name nArgs="2">union</ogc:Function_Name>
  1227. <ogc:Function_Name nArgs="2">UnionFeatureCollection</ogc:Function_Name>
  1228. <ogc:Function_Name nArgs="2">Unique</ogc:Function_Name>
  1229. <ogc:Function_Name nArgs="2">UniqueInterval</ogc:Function_Name>
  1230. <ogc:Function_Name nArgs="6">VectorToRaster</ogc:Function_Name>
  1231. <ogc:Function_Name nArgs="3">VectorZonalStatistics</ogc:Function_Name>
  1232. <ogc:Function_Name nArgs="1">vertices</ogc:Function_Name>
  1233. <ogc:Function_Name nArgs="2">within</ogc:Function_Name>
  1234. </ogc:Function_Names>
  1235. </ogc:Functions>
  1236. </ogc:Arithmetic_Operators>
  1237. </ogc:Scalar_Capabilities>
  1238. </ogc:Filter_Capabilities>
  1239. </WFS_Capabilities>
  1240. <?php
  1241. }
  1242. private function _getSchemaLocationString() {
  1243. $schemaLocations = array();
  1244. // $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
  1245. return implode(' ', $schemaLocations);
  1246. }
  1247. private function _getXmlNamespaceList() {
  1248. $namespaceList = $this->_getSourceNsList();
  1249. $namespaceListOut = array();
  1250. foreach ($namespaceList as $nsObj) {
  1251. $ns = "p5_{$nsObj[0]}_{$nsObj[1]}";
  1252. $uri = "https://biuro.biall-net.pl/wfs/{$nsObj[0]}/{$nsObj[1]}";
  1253. $namespaceListOut[] = 'xmlns:' . $ns . '="' . $uri . '"';
  1254. }
  1255. return implode(' ', $namespaceListOut);
  1256. }
  1257. private function _getSourceNsList() {
  1258. $usrObjList = array();
  1259. $tblsAcl = $this->_usrAcl->getTablesAcl();
  1260. foreach ($tblsAcl as $tblAcl) {
  1261. $dataSourceName = 'default_db';// TODO: getSourceName
  1262. $tblName = $tblAcl->getName();
  1263. $usrObjList[] = array($dataSourceName, $tblName);
  1264. }
  1265. return $usrObjList;
  1266. }
  1267. private function _printGetCapabilitiesXml($wfsServerUrl) {
  1268. ?>
  1269. <GetCapabilities>
  1270. <DCPType>
  1271. <HTTP>
  1272. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetCapabilities" />
  1273. </HTTP>
  1274. </DCPType>
  1275. <DCPType>
  1276. <HTTP>
  1277. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1278. </HTTP>
  1279. </DCPType>
  1280. </GetCapabilities>
  1281. <?php
  1282. }
  1283. private function _printDescribeFeatureTypeXml($wfsServerUrl) {
  1284. ?>
  1285. <DescribeFeatureType>
  1286. <SchemaDescriptionLanguage>
  1287. <XMLSCHEMA />
  1288. </SchemaDescriptionLanguage>
  1289. <DCPType>
  1290. <HTTP>
  1291. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=DescribeFeatureType" />
  1292. </HTTP>
  1293. </DCPType>
  1294. <DCPType>
  1295. <HTTP>
  1296. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1297. </HTTP>
  1298. </DCPType>
  1299. </DescribeFeatureType>
  1300. <?php
  1301. }
  1302. private function _printGetFeatureXml($wfsServerUrl) {
  1303. ?>
  1304. <GetFeature>
  1305. <ResultFormat>
  1306. <WFSKMLOutputFormat />
  1307. <GML2 />
  1308. <GML3 />
  1309. <SHAPE-ZIP />
  1310. <CSV />
  1311. <JSON />
  1312. </ResultFormat>
  1313. <DCPType>
  1314. <HTTP>
  1315. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeature" />
  1316. </HTTP>
  1317. </DCPType>
  1318. <DCPType>
  1319. <HTTP>
  1320. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1321. </HTTP>
  1322. </DCPType>
  1323. </GetFeature>
  1324. <?php
  1325. }
  1326. private function _printTransactionXml($wfsServerUrl) {
  1327. ?>
  1328. <Transaction>
  1329. <DCPType>
  1330. <HTTP>
  1331. <Get onlineResource="<?php echo $wfsServerUrl; ?>?request=Transaction" />
  1332. </HTTP>
  1333. </DCPType>
  1334. <DCPType>
  1335. <HTTP>
  1336. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1337. </HTTP>
  1338. </DCPType>
  1339. </Transaction>
  1340. <?php
  1341. }
  1342. private function _printLockFeatureXml($wfsServerUrl) {
  1343. ?>
  1344. <LockFeature>
  1345. <DCPType>
  1346. <HTTP>
  1347. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=LockFeature" />
  1348. </HTTP>
  1349. </DCPType>
  1350. <DCPType>
  1351. <HTTP>
  1352. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1353. </HTTP>
  1354. </DCPType>
  1355. </LockFeature>
  1356. <?php
  1357. }
  1358. private function _printGetFeatureWithLockXml($wfsServerUrl) {
  1359. ?>
  1360. <GetFeatureWithLock>
  1361. <ResultFormat>
  1362. <GML2 />
  1363. </ResultFormat>
  1364. <DCPType>
  1365. <HTTP>
  1366. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeatureWithLock" />
  1367. </HTTP>
  1368. </DCPType>
  1369. <DCPType>
  1370. <HTTP>
  1371. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  1372. </HTTP>
  1373. </DCPType>
  1374. </GetFeatureWithLock>
  1375. <?php
  1376. }
  1377. private function _printFeatureTypeListXml() {
  1378. // TODO: get list from userAcl
  1379. $featureTypes = array();
  1380. $tblsAcl = $this->_usrAcl->getTablesAcl();
  1381. foreach ($tblsAcl as $tblAcl) {
  1382. $dataSourceName = 'default_db';// TODO: getSourceName
  1383. $tblName = $tblAcl->getName();
  1384. $usrObjList[] = array($dataSourceName, $tblName);
  1385. $featureType = array();
  1386. $featureType['ns'] = "p5_{$dataSourceName}";
  1387. $featureType['Title'] = $tblAcl->getRawLabel();
  1388. $featureType['Abstract'] = $tblAcl->getRawLabel();
  1389. $featureType['Keywords'] = array();
  1390. $featureType['Keywords'][] = $tblAcl->getID();
  1391. $featureType['Keywords'][] = $tblName;
  1392. $featureType['Keywords'][] = $tblAcl->getRawLabel();
  1393. $featureType['Keywords'] = implode(", ", $featureType['Keywords']);
  1394. $featureType['SRS'] = "EPSG:4326";
  1395. $featureType['LatLongBoundingBox'] = array();// TODO: feature LatLongBoundingBox
  1396. $featureType['LatLongBoundingBox']['minx'] = "8.12328509871721";
  1397. $featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
  1398. $featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
  1399. $featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
  1400. $featureTypes[$tblName] = $featureType;
  1401. }
  1402. /*
  1403. <FeatureType>
  1404. <Name>ppr06:AMBITIPAESAGGIO</Name>
  1405. <Title>AMBITIPAESAGGIO</Title>
  1406. <Abstract />
  1407. <Keywords>features, AMBITIPAESAGGIO</Keywords>
  1408. <SRS>EPSG:4326</SRS>
  1409. <LatLongBoundingBox minx="8.12328509871721" miny="38.8575126897477" maxx="9.838674658246807" maxy="41.31378404137082" />
  1410. </FeatureType>
  1411. */
  1412. $featureTypesXml = '';
  1413. foreach ($featureTypes as $tblName => $feature) {
  1414. $featureTypesXml .= '<FeatureType>' . "\n";
  1415. $featureTypesXml .= '<Name>' . "{$feature['ns']}:{$tblName}" . '</Name>' . "\n";
  1416. $featureTypesXml .= '<Title>' . "{$feature['Title']}" . '</Title>' . "\n";
  1417. if (!empty($feature['Abstract'])) {
  1418. $featureTypesXml .= '<Abstract>' . "{$feature['Abstract']}" . '</Abstract>' . "\n";
  1419. } else {
  1420. $featureTypesXml .= '<Abstract/>' . "\n";
  1421. }
  1422. if (!empty($feature['Keywords'])) {
  1423. $featureTypesXml .= '<Keywords>' . "{$feature['Keywords']}" . '</Keywords>' . "\n";
  1424. } else {
  1425. $featureTypesXml .= '<Keywords/>' . "\n";
  1426. }
  1427. $featureTypesXml .= '<SRS>' . "{$feature['SRS']}" . '</SRS>' . "\n";
  1428. if (!empty($feature['LatLongBoundingBox'])) {
  1429. $latLongBoundingBoxOut = array();
  1430. $latLongBoundingBoxOut[] = 'minx="' . $feature['LatLongBoundingBox']['minx'] . '"';
  1431. $latLongBoundingBoxOut[] = 'miny="' . $feature['LatLongBoundingBox']['miny'] . '"';
  1432. $latLongBoundingBoxOut[] = 'maxx="' . $feature['LatLongBoundingBox']['maxx'] . '"';
  1433. $latLongBoundingBoxOut[] = 'maxy="' . $feature['LatLongBoundingBox']['maxy'] . '"';
  1434. $featureTypesXml .= '<LatLongBoundingBox ' . implode(' ', $latLongBoundingBoxOut) . ' />';
  1435. }
  1436. $featureTypesXml .= '</FeatureType>' . "\n";
  1437. }
  1438. return $featureTypesXml;
  1439. }
  1440. }