cables_from_joins_to_PE.xsl 12 KB

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