cables_from_joins_to_PE.xsl 12 KB

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