cables_from_joins_to_PE.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. <!-- <joins_asText>
  14. <item id="0">POINT (18.7909 51.701067999083)</item>-->
  15. <xsl:template match="joins2ways_z_ID_Way">
  16. <cables_from_joins_to_PE>
  17. <xsl:variable name="joins_asText_Path_Point">
  18. <xsl:apply-templates select="$joins_asText" mode="joins_asText"/>
  19. </xsl:variable>
  20. <!--<xsl:copy-of select="$joins_asText_Path_Point"/>-->
  21. <xsl:variable name="edge_joins_filled_paths">
  22. <xsl:apply-templates select="$edge_joins_filled_paths" mode="edge_joins_filled_paths"/>
  23. </xsl:variable>
  24. <!--<xsl:copy-of select="$edge_joins_filled_paths"/>-->
  25. <!-- jedziemy po joins2ways_z_ID_Way, sprawdzamy czy jest dla niego PE_candidates_dump , jak tak, to szukamy jego PE i liczymy sciezke
  26. lub probujemy rysowac zawsze od konca drogi-->
  27. <!-- trzeba sprawdzic czy join jest klientem - czy tylko PE! -->
  28. <xsl:for-each select="item">
  29. <xsl:choose>
  30. <xsl:when test="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=current()/@ID_Way]">
  31. <cable_to_PE_to_be_calculated>
  32. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  33. <xsl:attribute name="Joins" select="@id"/>
  34. <xsl:variable name="ID_Way" select="@ID_Way"/>
  35. <xsl:variable name="Joins" select="@ID_Way"/>
  36. <!-- idziemy po drodze, -->
  37. <xsl:variable name="Join_X" select="$joins_asText_Path_Point/joins_asText/item[@id=$Joins]/As_POINT_to_xml/@X"/>
  38. <xsl:variable name="Join_Y" select="$joins_asText_Path_Point/joins_asText/item[@id=$Joins]/As_POINT_to_xml/@Y"/>
  39. <xsl:attribute name="Join_X" select="$Join_X"/><xsl:attribute name="Join_Y" select="$Join_Y"/>
  40. <xsl:for-each select="$edge_joins_filled_paths/edge_joins_filled_paths/item[@id=$ID_Way]/bp:Path_Point">
  41. <xsl:variable name="diff_X" select=" number($Join_X)- number(@X)"/><xsl:variable name="diff_Y" select=" number($Join_Y)- number(@Y)"/>
  42. <xsl:variable name="bp:Path_Point" select="."/>
  43. <xsl:choose>
  44. <xsl:when test="(abs($diff_X)&lt;0.0001 and abs($diff_X)&lt;0.0001) or ( @X=$Join_X and @Y=$Join_Y )">
  45. <found_in_path_in_edge_joins_filled_path>
  46. <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
  47. <xsl:attribute name="position" select="position()"/>
  48. <xsl:copy-of select="."/>
  49. <xsl:call-template name="detect_next_PE">
  50. <xsl:with-param name="bp:Path_Point" select="$bp:Path_Point"/>
  51. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  52. <xsl:with-param name="Pos_found" select="position()"/>
  53. <xsl:with-param name="edge_joins_filled_paths" select="$edge_joins_filled_paths"/>
  54. </xsl:call-template>
  55. </found_in_path_in_edge_joins_filled_path>
  56. </xsl:when>
  57. <xsl:otherwise>
  58. <not_found>
  59. <xsl:attribute name="Pos" select="position()"/>
  60. <xsl:attribute name="X" select="@X"/><xsl:attribute name="Y" select="@Y"/>
  61. <xsl:attribute name="srch_X" select="$Join_X"/><xsl:attribute name="srch_Y" select="$Join_Y"/>
  62. <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
  63. </not_found>
  64. </xsl:otherwise>
  65. </xsl:choose>
  66. </xsl:for-each>
  67. </cable_to_PE_to_be_calculated>
  68. </xsl:when>
  69. </xsl:choose>
  70. </xsl:for-each>
  71. </cables_from_joins_to_PE>
  72. </xsl:template>
  73. <!-- na podstawie Joins jade do PE raz z przodudrugi raz z tylu -->
  74. <xsl:template name="detect_next_PE">
  75. <xsl:param name="bp:Path_Point" required="yes"/>
  76. <xsl:param name="Pos_found" required="yes"/>
  77. <xsl:param name="ID_Way" required="yes"/>
  78. <xsl:param name="edge_joins_filled_paths" required="yes"/>
  79. <!--<w_gore><xsl:attribute name="Pos_found" select="$Pos_found"/>
  80. <xsl:for-each select="$edge_joins_filled_paths/edge_joins_filled_paths/item[@id=$ID_Way]/bp:Path_Point">
  81. </xsl:for-each>
  82. </w_gore>-->
  83. <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)"/>
  84. <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)"/>
  85. <detect_next_PE>
  86. <xsl:attribute name="Pos_found" select="$Pos_found"/>
  87. <!--<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)]-->
  88. <xsl:attribute name="Next_PE_Pos" select="$Next_PE_Pos"/>
  89. <xsl:attribute name="Prev_PE_Pos" select="$Prev_PE_Pos"/>
  90. <xsl:choose>
  91. <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 )">
  92. <xsl:attribute name="Going_to_next" select="$Next_PE_Pos"/>
  93. <xsl:variable name="Path_Point">
  94. <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 ]">
  95. <xsl:copy-of select="."/>
  96. </xsl:for-each>
  97. </xsl:variable>
  98. <xsl:copy-of select="$Path_Point"/>
  99. <xsl:call-template name="To_LINESTRING">
  100. <xsl:with-param name="Path_Point" select="$Path_Point"/>
  101. </xsl:call-template>
  102. </xsl:when>
  103. <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) )">
  104. <xsl:attribute name="Going_to_prev" select="$Prev_PE_Pos"/>
  105. <xsl:variable name="Path_Point">
  106. <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 ]">
  107. <xsl:copy-of select="."/>
  108. </xsl:for-each>
  109. </xsl:variable>
  110. <xsl:copy-of select="$Path_Point"/>
  111. <xsl:call-template name="To_LINESTRING">
  112. <xsl:with-param name="Path_Point" select="$Path_Point"/>
  113. </xsl:call-template>
  114. </xsl:when>
  115. <xsl:otherwise><xsl:message terminate="yes">#Error 111 - nie moze byc innego wyjatku
  116. Pos_found=<xsl:value-of select="$Pos_found"/>;
  117. $Next_PE_Pos=<xsl:value-of select="$Next_PE_Pos"/>;
  118. $Prev_PE_Pos=<xsl:value-of select="$Prev_PE_Pos"/>;
  119. abs($Pos_found - $Next_PE_Pos)=<xsl:value-of select="abs($Pos_found - $Next_PE_Pos)"/>
  120. abs($Pos_found - $Prev_PE_Pos)=<xsl:value-of select="abs($Pos_found - $Prev_PE_Pos)"/>
  121. </xsl:message></xsl:otherwise>
  122. </xsl:choose>
  123. </detect_next_PE>
  124. </xsl:template>
  125. <xsl:template name="To_LINESTRING">
  126. <xsl:param name="Path_Point" required="yes"/>
  127. <LINESTRING>
  128. <xsl:value-of select="'LINESTRING ('"/>
  129. <xsl:for-each select="$Path_Point/bp:Path_Point">
  130. <xsl:value-of select="concat(@X,' ',@Y)"/>
  131. <xsl:if test="position()!=last()"><xsl:value-of select="', '"/></xsl:if>
  132. </xsl:for-each>
  133. <xsl:value-of select="')'"/>
  134. </LINESTRING>
  135. </xsl:template>
  136. <xsl:template match="edge_joins_filled_paths" mode="edge_joins_filled_paths">
  137. <edge_joins_filled_paths>
  138. <xsl:apply-templates mode="edge_joins_filled_paths"/>
  139. </edge_joins_filled_paths>
  140. </xsl:template>
  141. <xsl:template match="item" mode="edge_joins_filled_paths">
  142. <item>
  143. <xsl:copy-of select="@*"/>
  144. <xsl:copy-of select="tried"/>
  145. <xsl:variable name="Path_Point">
  146. <xsl:apply-templates/>
  147. </xsl:variable>
  148. <xsl:copy-of select="$Path_Point/tried"/>
  149. <xsl:for-each select="$Path_Point/bp:Path_Point">
  150. <bp:Path_Point>
  151. <xsl:attribute name="Pos" select="position()"/>
  152. <xsl:copy-of select="@*"/>
  153. </bp:Path_Point>
  154. </xsl:for-each>
  155. </item>
  156. </xsl:template>
  157. <xsl:template match="joins_asText" mode="joins_asText">
  158. <joins_asText>
  159. <xsl:apply-templates mode="joins_asText"/>
  160. </joins_asText>
  161. </xsl:template>
  162. <xsl:template match="item" mode="joins_asText">
  163. <item>
  164. <xsl:copy-of select="@*"/>
  165. <xsl:call-template name="As_POINT_to_xml">
  166. <xsl:with-param name="As_POINT" select="text()"/>
  167. </xsl:call-template>
  168. </item>
  169. </xsl:template>
  170. <!-- todo do wypchniecia do funkcji ogolnych -->
  171. <xsl:template name="As_POINT_to_xml">
  172. <xsl:param name="As_POINT"/>
  173. <xsl:variable name="As_POINT_tok" select=" substring-before( substring-after(normalize-space(.),'POINT (') , ')') "/>
  174. <!--<test1><xsl:copy-of select="$LINESTRING"/></test1>-->
  175. <xsl:variable name="As_POINT_pos">
  176. <xsl:for-each select="tokenize($As_POINT_tok,' ')">
  177. <pos>
  178. <xsl:attribute name="pos" select="position()"/>
  179. <xsl:value-of select="."/>
  180. </pos>
  181. </xsl:for-each>
  182. </xsl:variable>
  183. <As_POINT_to_xml>
  184. <xsl:attribute name="X" select="$As_POINT_pos/pos[@pos=1]"/>
  185. <xsl:attribute name="Y" select="$As_POINT_pos/pos[@pos=2]"/>
  186. </As_POINT_to_xml>
  187. </xsl:template>
  188. <xsl:template match="*"/>
  189. </xsl:stylesheet>