cables_from_joins_to_PE.xsl 12 KB

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