cables_from_joins_to_PE.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
  5. exclude-result-prefixes="xs"
  6. version="2.0">
  7. <xsl:output indent="yes"/>
  8. <xsl:strip-space elements="*"/>
  9. <xsl:include href="asText.xsl"/>
  10. <xsl:variable name="PE_candidates_dump" select="doc('edge_paths_with_PE.xml')"/>
  11. <xsl:variable name="joins_asText" select="doc('joins_asText.xml')"/>
  12. <xsl:variable name="edge_joins_filled_paths" select="doc('edge_joins_filled_paths.xml') "/>
  13. <xsl:variable name="points2joins" select="doc('points2joins.xml')"/>
  14. <!-- <joins_asText>
  15. <item id="0">POINT (18.7909 51.701067999083)</item>-->
  16. <xsl:template match="joins2ways_z_ID_Way">
  17. <cables_from_joins_to_PE>
  18. <xsl:variable name="joins_asText_Path_Point">
  19. <xsl:apply-templates select="$joins_asText" mode="joins_asText"/>
  20. </xsl:variable>
  21. <!--<xsl:copy-of select="$joins_asText_Path_Point"/>-->
  22. <xsl:variable name="edge_joins_filled_paths">
  23. <xsl:apply-templates select="$edge_joins_filled_paths" mode="edge_joins_filled_paths"/>
  24. </xsl:variable>
  25. <!--<xsl:copy-of select="$edge_joins_filled_paths"/>-->
  26. <!-- jedziemy po joins2ways_z_ID_Way, sprawdzamy czy jest dla niego PE_candidates_dump , jak tak, to szukamy jego PE i liczymy sciezke
  27. lub probujemy rysowac zawsze od konca drogi-->
  28. <xsl:for-each select="item">
  29. <xsl:variable name="ID_Way" select="@ID_Way"/>
  30. <xsl:variable name="Joins" select="@id"/>
  31. <xsl:variable name="ID_Point" select="@ID_Point"/>
  32. <xsl:choose>
  33. <!-- trzeba sprawdzic czy join jest klientem - czy tylko PE! -->
  34. <xsl:when test="not(@ID_Point)">
  35. <not_candidate><xsl:attribute name="descr" select="'this is probably join from way'"/>
  36. <xsl:attribute name="Joins" select="@id"/></not_candidate>
  37. </xsl:when>
  38. <xsl:when test="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=current()/@ID_Way]">
  39. <cable_to_PE_to_be_calculated>
  40. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  41. <xsl:attribute name="Joins" select="@id"/>
  42. <xsl:attribute name="ID_Point" select="@ID_Point"/>
  43. <!-- idziemy po drodze, -->
  44. <xsl:variable name="Join_X" select="$joins_asText_Path_Point/joins_asText/item[@id=$Joins]/As_POINT_to_xml/@X"/>
  45. <xsl:variable name="Join_Y" select="$joins_asText_Path_Point/joins_asText/item[@id=$Joins]/As_POINT_to_xml/@Y"/>
  46. <xsl:attribute name="Join_X" select="$Join_X"/><xsl:attribute name="Join_Y" select="$Join_Y"/>
  47. <xsl:variable name="found_in_path_in_edge_joins_filled_path">
  48. <xsl:for-each select="$edge_joins_filled_paths/edge_joins_filled_paths/item[@id=$ID_Way]/bp:Path_Point">
  49. <xsl:variable name="diff_X" select=" number($Join_X)- number(@X)"/><xsl:variable name="diff_Y" select=" number($Join_Y)- number(@Y)"/>
  50. <xsl:variable name="bp:Path_Point" select="."/>
  51. <xsl:choose>
  52. <xsl:when test="(abs($diff_X)&lt;0.0001 and abs($diff_X)&lt;0.0001) or ( @X=$Join_X and @Y=$Join_Y )">
  53. <found_in_path_in_edge_joins_filled_path>
  54. <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
  55. <xsl:attribute name="position" select="position()"/>
  56. <!--<bp:Path_Point_var><xsl:copy-of select="$bp:Path_Point"/></bp:Path_Point_var>-->
  57. <xsl:copy-of select="."/>
  58. <xsl:call-template name="detect_next_PE">
  59. <xsl:with-param name="bp:Path_Point" select="$bp:Path_Point"/>
  60. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  61. <xsl:with-param name="Pos_found" select="position()"/>
  62. <xsl:with-param name="edge_joins_filled_paths" select="$edge_joins_filled_paths"/>
  63. <xsl:with-param name="ID_Point" select="$ID_Point"/>
  64. </xsl:call-template>
  65. </found_in_path_in_edge_joins_filled_path>
  66. </xsl:when>
  67. <xsl:otherwise>
  68. <not_found>
  69. <xsl:attribute name="Pos" select="position()"/>
  70. <xsl:attribute name="X" select="@X"/><xsl:attribute name="Y" select="@Y"/>
  71. <xsl:attribute name="srch_X" select="$Join_X"/><xsl:attribute name="srch_Y" select="$Join_Y"/>
  72. <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
  73. </not_found>
  74. </xsl:otherwise>
  75. </xsl:choose>
  76. </xsl:for-each>
  77. </xsl:variable>
  78. <xsl:choose>
  79. <xsl:when test="$found_in_path_in_edge_joins_filled_path/found_in_path_in_edge_joins_filled_path">
  80. <xsl:for-each select="$found_in_path_in_edge_joins_filled_path/found_in_path_in_edge_joins_filled_path[1]">
  81. <xsl:sort select="count(detect_next_PE/bp:Path_Point)" order="descending"/>
  82. <debug>
  83. <xsl:attribute name="debug_pos" select="position()"/>
  84. <xsl:attribute name="Path_Point_count" select="count(detect_next_PE/bp:Path_Point)"/>
  85. </debug>
  86. <!--<found_in_path_in_edge_joins_filled_path>
  87. <xsl:attribute name="debug_pos" select="position()"/>
  88. <xsl:copy-of select="@*"/>
  89. <xsl:call-template name="detect_next_PE">
  90. <xsl:with-param name="bp:Path_Point" select="bp:Path_Point_var"/>
  91. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  92. <xsl:with-param name="Pos_found" select="@position"/>
  93. <xsl:with-param name="edge_joins_filled_paths" select="$edge_joins_filled_paths"/>
  94. <xsl:with-param name="ID_Point" select="$ID_Point"/>
  95. </xsl:call-template>
  96. </found_in_path_in_edge_joins_filled_path>-->
  97. <xsl:copy-of select="."/>
  98. </xsl:for-each>
  99. <xsl:copy-of select="$found_in_path_in_edge_joins_filled_path/not_found"/>
  100. </xsl:when>
  101. <xsl:otherwise>
  102. <xsl:copy-of select="$found_in_path_in_edge_joins_filled_path"/>
  103. </xsl:otherwise>
  104. </xsl:choose>
  105. </cable_to_PE_to_be_calculated>
  106. </xsl:when>
  107. </xsl:choose>
  108. </xsl:for-each>
  109. </cables_from_joins_to_PE>
  110. </xsl:template>
  111. <!-- na podstawie Joins jade do PE raz z przodudrugi raz z tylu -->
  112. <xsl:template name="detect_next_PE">
  113. <xsl:param name="bp:Path_Point" required="yes"/>
  114. <xsl:param name="Pos_found" required="yes"/>
  115. <xsl:param name="ID_Way" required="yes"/>
  116. <xsl:param name="edge_joins_filled_paths" required="yes"/>
  117. <xsl:param name="ID_Point" required="yes"/>
  118. <!--<w_gore><xsl:attribute name="Pos_found" select="$Pos_found"/>
  119. <xsl:for-each select="$edge_joins_filled_paths/edge_joins_filled_paths/item[@id=$ID_Way]/bp:Path_Point">
  120. </xsl:for-each>
  121. </w_gore>-->
  122. <xsl:variable name="Next_PE_Pos" select="min($PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@Pos)&gt;number($Pos_found)]/@Pos)"/>
  123. <xsl:variable name="Prev_PE_Pos" select="max($PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@Pos)&lt;=number($Pos_found)]/@Pos)"/>
  124. <detect_next_PE>
  125. <xsl:attribute name="Pos_found" select="$Pos_found"/>
  126. <!--<xsl:copy-of select="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@Pos)&gt;number($Pos_found)]/@Pos"/>--> <!--[number(@Pos)&gt;number($Pos_found)]-->
  127. <xsl:attribute name="Next_PE_Pos" select="$Next_PE_Pos"/>
  128. <xsl:attribute name="Prev_PE_Pos" select="$Prev_PE_Pos"/>
  129. <xsl:choose>
  130. <xsl:when test="( abs($Pos_found - $Next_PE_Pos)&lt;=abs($Pos_found - $Prev_PE_Pos)) or ( not($Prev_PE_Pos) and $Next_PE_Pos )">
  131. <xsl:attribute name="Going_to_next" select="$Next_PE_Pos"/>
  132. <xsl:variable name="Path_Point">
  133. <xsl:for-each select="$edge_joins_filled_paths/edge_joins_filled_paths/item[@id=$ID_Way]/bp:Path_Point[ position()&gt;=$Pos_found and position()&lt;=$Next_PE_Pos ]">
  134. <xsl:copy-of select="."/>
  135. </xsl:for-each>
  136. </xsl:variable>
  137. <xsl:copy-of select="$Path_Point"/>
  138. <xsl:call-template name="To_LINESTRING">
  139. <xsl:with-param name="Path_Point" select="$Path_Point"/>
  140. </xsl:call-template>
  141. </xsl:when>
  142. <xsl:when test="(abs($Pos_found - $Next_PE_Pos)&gt;abs($Pos_found - $Prev_PE_Pos)) or ( $Prev_PE_Pos and not($Next_PE_Pos) )">
  143. <xsl:attribute name="Going_to_prev" select="$Prev_PE_Pos"/>
  144. <xsl:variable name="Path_Point">
  145. <xsl:for-each select="$edge_joins_filled_paths/edge_joins_filled_paths/item[@id=$ID_Way]/bp:Path_Point[ position()&lt;=$Pos_found and position()&gt;=$Prev_PE_Pos ]">
  146. <xsl:copy-of select="."/>
  147. </xsl:for-each>
  148. </xsl:variable>
  149. <xsl:copy-of select="$Path_Point"/>
  150. <xsl:call-template name="To_LINESTRING">
  151. <xsl:with-param name="Path_Point" select="$Path_Point"/>
  152. </xsl:call-template>
  153. </xsl:when>
  154. <xsl:otherwise><xsl:message terminate="yes">#Error 111 - nie moze byc innego wyjatku
  155. Pos_found=<xsl:value-of select="$Pos_found"/>;
  156. $Next_PE_Pos=<xsl:value-of select="$Next_PE_Pos"/>;
  157. $Prev_PE_Pos=<xsl:value-of select="$Prev_PE_Pos"/>;
  158. abs($Pos_found - $Next_PE_Pos)=<xsl:value-of select="abs($Pos_found - $Next_PE_Pos)"/>
  159. abs($Pos_found - $Prev_PE_Pos)=<xsl:value-of select="abs($Pos_found - $Prev_PE_Pos)"/>
  160. </xsl:message></xsl:otherwise>
  161. </xsl:choose>
  162. </detect_next_PE>
  163. </xsl:template>
  164. <xsl:template name="To_LINESTRING">
  165. <xsl:param name="Path_Point" required="yes"/>
  166. <LINESTRING>
  167. <xsl:value-of select="'LINESTRING ('"/>
  168. <xsl:for-each select="$Path_Point/bp:Path_Point">
  169. <xsl:value-of select="concat(@X,' ',@Y)"/>
  170. <xsl:if test="position()!=last()"><xsl:value-of select="', '"/></xsl:if>
  171. </xsl:for-each>
  172. <xsl:value-of select="')'"/>
  173. </LINESTRING>
  174. </xsl:template>
  175. <xsl:template match="edge_joins_filled_paths" mode="edge_joins_filled_paths">
  176. <edge_joins_filled_paths>
  177. <xsl:apply-templates mode="edge_joins_filled_paths"/>
  178. </edge_joins_filled_paths>
  179. </xsl:template>
  180. <xsl:template match="item" mode="edge_joins_filled_paths">
  181. <item>
  182. <xsl:copy-of select="@*"/>
  183. <xsl:copy-of select="tried"/>
  184. <xsl:variable name="Path_Point">
  185. <xsl:apply-templates/>
  186. </xsl:variable>
  187. <xsl:copy-of select="$Path_Point/tried"/>
  188. <xsl:for-each select="$Path_Point/bp:Path_Point">
  189. <bp:Path_Point>
  190. <xsl:attribute name="Pos" select="position()"/>
  191. <xsl:copy-of select="@*"/>
  192. </bp:Path_Point>
  193. </xsl:for-each>
  194. </item>
  195. </xsl:template>
  196. <xsl:template match="joins_asText" mode="joins_asText">
  197. <joins_asText>
  198. <xsl:apply-templates mode="joins_asText"/>
  199. </joins_asText>
  200. </xsl:template>
  201. <xsl:template match="item" mode="joins_asText">
  202. <item>
  203. <xsl:copy-of select="@*"/>
  204. <xsl:call-template name="As_POINT_to_xml">
  205. <xsl:with-param name="As_POINT" select="text()"/>
  206. </xsl:call-template>
  207. </item>
  208. </xsl:template>
  209. <!-- todo do wypchniecia do funkcji ogolnych -->
  210. <xsl:template name="As_POINT_to_xml">
  211. <xsl:param name="As_POINT"/>
  212. <xsl:variable name="As_POINT_tok" select=" substring-before( substring-after(normalize-space(.),'POINT (') , ')') "/>
  213. <!--<test1><xsl:copy-of select="$LINESTRING"/></test1>-->
  214. <xsl:variable name="As_POINT_pos">
  215. <xsl:for-each select="tokenize($As_POINT_tok,' ')">
  216. <pos>
  217. <xsl:attribute name="pos" select="position()"/>
  218. <xsl:value-of select="."/>
  219. </pos>
  220. </xsl:for-each>
  221. </xsl:variable>
  222. <As_POINT_to_xml>
  223. <xsl:attribute name="X" select="$As_POINT_pos/pos[@pos=1]"/>
  224. <xsl:attribute name="Y" select="$As_POINT_pos/pos[@pos=2]"/>
  225. </As_POINT_to_xml>
  226. </xsl:template>
  227. <xsl:template match="*"/>
  228. </xsl:stylesheet>