cables_from_joins_to_PE.xsl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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:param name="edge_paths_with_PE.xml" select="'edge_paths_with_PE.xml'"/>
  11. <xsl:param name="joins_asText_xml.xml" select="'joins_asText_xml.xml'"/>
  12. <!--<xsl:param name="edge_joins_filled_paths.xml" select="'edge_joins_filled_paths.xml'"/>-->
  13. <xsl:param name="points2joins.xml" select="'points2joins.xml'"/>
  14. <xsl:param name="edge_joins_filled_paths" select="'edge_joins_filled_paths'"/>
  15. <xsl:variable name="PE_candidates_dump" select="doc($edge_paths_with_PE.xml)"/>
  16. <xsl:variable name="joins_asText_Path_Point" select="doc($joins_asText_xml.xml)"/>
  17. <!--<xsl:variable name="edge_joins_filled_paths" select="doc($edge_joins_filled_paths.xml) "/>-->
  18. <xsl:variable name="points2joins" select="doc($points2joins.xml)"/>
  19. <!-- <joins_asText>
  20. <item id="0">POINT (18.7909 51.701067999083)</item>-->
  21. <xsl:template match="joins2ways_z_ID_Way">
  22. <cables_from_joins_to_PE>
  23. <!--<xsl:variable name="joins_asText_Path_Point">
  24. <xsl:apply-templates select="$joins_asText" mode="joins_asText"/>
  25. </xsl:variable>-->
  26. <!--<xsl:copy-of select="$joins_asText_Path_Point"/>-->
  27. <!--<xsl:copy-of select="$edge_joins_filled_paths"/>-->
  28. <!-- jedziemy po joins2ways_z_ID_Way, sprawdzamy czy jest dla niego PE_candidates_dump , jak tak, to szukamy jego PE i liczymy sciezke
  29. lub probujemy rysowac zawsze od konca drogi-->
  30. <xsl:for-each select="item">
  31. <xsl:variable name="ID_Way" select="@ID_Way"/>
  32. <xsl:variable name="ID_Join" select="@id"/>
  33. <!--<xsl:variable name="pos" select=" position()"/>--> <!-- tozsamosc ulozenia z waysow -->
  34. <xsl:variable name="ID_Point_count"/>
  35. <xsl:for-each select="Points">
  36. <xsl:message>#41 Calculating Cable for point:<xsl:value-of select=" text()"/>; ID_Join:<xsl:value-of select="$ID_Join"/></xsl:message>
  37. <xsl:variable name="ID_Point" select=" text()"/>
  38. <xsl:variable name="edge_joins_filled_paths_xml" select="doc(concat($edge_joins_filled_paths,'/edge_joins_filled_paths.',$ID_Way,'.xml'))"/>
  39. <!-- do ustalenia gdize sa najblizsze bp:Path_Point_Cable ID_Join="45" -> Target_ID_Join -->
  40. <xsl:variable name="edge_paths_with_PE_controll" select="doc(concat('edge_paths_with_PE_controll_paths_temp/edge_paths_with_PE_controll.xsl.',$ID_Way,'.xml'))"/>
  41. <!-- nie tzeba - jest w foreach dla Points !- trzeba sprawdzic czy join jest klientem - czy tylko PE! -->
  42. <xsl:choose>
  43. <!--<xsl:when test="not(@ID_Point)">
  44. <not_candidate><xsl:attribute name="descr" select="'this is probably join from way'"/>
  45. <xsl:attribute name="Joins" select="@id"/></not_candidate>
  46. </xsl:when>-->
  47. <xsl:when test="$PE_candidates_dump/PE_candidates_dump/LINESTRING/bp:Path_Point[@ID_Join=$ID_Join]">
  48. <not_candidate_is_pe><xsl:attribute name="descr" select="'this is PE '"/>
  49. <xsl:attribute name="Joins" select="$ID_Join"/>
  50. <xsl:copy-of select="$PE_candidates_dump/PE_candidates_dump/LINESTRING/bp:Path_Point[@ID_Join=$ID_Join]"/>
  51. </not_candidate_is_pe>
  52. </xsl:when>
  53. <xsl:otherwise>
  54. <cable_to_PE_to_be_calculated>
  55. <xsl:attribute name="ID_Way" select="$ID_Way"/>
  56. <xsl:attribute name="Joins" select="$ID_Join"/>
  57. <xsl:attribute name="ID_Point" select="$ID_Point"/>
  58. <!-- idziemy po drodze, -->
  59. <xsl:variable name="Join_X" select="$joins_asText_Path_Point/joins_asText_xml/item[@id=$ID_Join]/bp:Path_Point/@X"/>
  60. <xsl:variable name="Join_Y" select="$joins_asText_Path_Point/joins_asText_xml/item[@id=$ID_Join]/bp:Path_Point/@Y"/>
  61. <xsl:attribute name="Join_X" select="$Join_X"/><xsl:attribute name="Join_Y" select="$Join_Y"/>
  62. <!--<xsl:variable name="found_in_path_in_edge_joins_filled_path">
  63. <xsl:for-each select="$edge_joins_filled_paths_xml/edge_joins_filled_paths_xml/asText_XMl[@id=$ID_Way]/LineString">
  64. <xsl:variable name="diff_X" select=" number($Join_X)- number(@X)"/><xsl:variable name="diff_Y" select=" number($Join_Y)- number(@Y)"/>
  65. <xsl:variable name="bp:Path_Point" select="."/>
  66. <xsl:choose>
  67. <xsl:when test="(abs($diff_X)&lt;0.0001 and abs($diff_X)&lt;0.0001) or ( @X=$Join_X and @Y=$Join_Y )">
  68. <found_in_path_in_edge_joins_filled_path>
  69. <xsl:variable name="Join_Y" select="$joins_asText_Path_Point/joins_asText_xml/item[@id=$Joins]/bp:Path_Point/@Y"/>
  70. <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
  71. <xsl:attribute name="position" select="position()"/>
  72. <!-\-<bp:Path_Point_var><xsl:copy-of select="$bp:Path_Point"/></bp:Path_Point_var>-\->
  73. <xsl:copy-of select="."/>
  74. <xsl:call-template name="detect_next_PE">
  75. <xsl:with-param name="bp:Path_Point" select="$bp:Path_Point"/>
  76. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  77. <xsl:with-param name="Pos_found" select="position()"/>
  78. <xsl:with-param name="edge_joins_filled_paths" select="$edge_joins_filled_paths_xml"/>
  79. <xsl:with-param name="ID_Point" select="$ID_Point"/>
  80. </xsl:call-template>
  81. </found_in_path_in_edge_joins_filled_path>
  82. </xsl:when>
  83. <xsl:otherwise>
  84. <not_found>
  85. <xsl:attribute name="Pos" select="position()"/>
  86. <xsl:attribute name="X" select="@X"/><xsl:attribute name="Y" select="@Y"/>
  87. <xsl:attribute name="srch_X" select="$Join_X"/><xsl:attribute name="srch_Y" select="$Join_Y"/>
  88. <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
  89. </not_found>
  90. </xsl:otherwise>
  91. </xsl:choose>
  92. </xsl:for-each>
  93. </xsl:variable>-->
  94. <!--<xsl:choose>
  95. <xsl:when test="$found_in_path_in_edge_joins_filled_path/found_in_path_in_edge_joins_filled_path">
  96. <xsl:for-each select="$found_in_path_in_edge_joins_filled_path/found_in_path_in_edge_joins_filled_path[1]">
  97. <xsl:sort select="count(detect_next_PE/bp:Path_Point)" order="descending"/>
  98. <debug>
  99. <xsl:attribute name="debug_pos" select="position()"/>
  100. <xsl:attribute name="Path_Point_count" select="count(detect_next_PE/bp:Path_Point)"/>
  101. </debug>
  102. <!-\-<found_in_path_in_edge_joins_filled_path>
  103. <xsl:attribute name="debug_pos" select="position()"/>
  104. <xsl:copy-of select="@*"/>
  105. <xsl:call-template name="detect_next_PE">
  106. <xsl:with-param name="bp:Path_Point" select="bp:Path_Point_var"/>
  107. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  108. <xsl:with-param name="Pos_found" select="@position"/>
  109. <xsl:with-param name="edge_joins_filled_paths" select="$edge_joins_filled_paths"/>
  110. <xsl:with-param name="ID_Point" select="$ID_Point"/>
  111. </xsl:call-template>
  112. </found_in_path_in_edge_joins_filled_path>-\->
  113. <xsl:copy-of select="."/>
  114. </xsl:for-each>
  115. <xsl:copy-of select="$found_in_path_in_edge_joins_filled_path/not_found"/>
  116. </xsl:when>
  117. <xsl:otherwise>
  118. <xsl:copy-of select="$found_in_path_in_edge_joins_filled_path"/>
  119. </xsl:otherwise>
  120. </xsl:choose>-->
  121. <xsl:variable name="id_path" select="$edge_joins_filled_paths_xml/edge_joins_filled_paths_xml/asText_XMl/LineString[@ID_Join=$ID_Join and @Y=$Join_Y and @Y=$Join_Y]/@id_path" />
  122. <xsl:choose>
  123. <xsl:when test="$id_path">
  124. <found_in_path_in_edge_joins_filled_path>
  125. <xsl:for-each select="$edge_joins_filled_paths_xml/edge_joins_filled_paths_xml/asText_XMl/LineString[@ID_Join=$ID_Join and @Y=$Join_Y and @Y=$Join_Y]">
  126. <xsl:call-template name="detect_next_PE_adv">
  127. <xsl:with-param name="ID_Point" select="$ID_Point"/>
  128. <xsl:with-param name="id_path" select="@id_path"/>
  129. <xsl:with-param name="ID_Join" select="$ID_Join"/>
  130. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  131. <xsl:with-param name="edge_joins_filled_paths_xml" select="$edge_joins_filled_paths_xml"/>
  132. </xsl:call-template>
  133. </xsl:for-each>
  134. </found_in_path_in_edge_joins_filled_path>
  135. </xsl:when>
  136. <xsl:otherwise>
  137. <error>Not found $path
  138. <xsl:message>Not found $path</xsl:message>
  139. </error>
  140. </xsl:otherwise>
  141. </xsl:choose>
  142. </cable_to_PE_to_be_calculated>
  143. </xsl:otherwise>
  144. </xsl:choose>
  145. </xsl:for-each>
  146. </xsl:for-each>
  147. </cables_from_joins_to_PE>
  148. </xsl:template>
  149. <xsl:template name="detect_next_PE_adv">
  150. <xsl:param name="ID_Point" required="yes"/>
  151. <xsl:param name="id_path" required="yes"/>
  152. <xsl:param name="ID_Join" required="yes"/>
  153. <xsl:param name="ID_Way" required="yes"/>
  154. <xsl:param name="edge_joins_filled_paths_xml" required="yes"/>
  155. <detect_next_PE>
  156. <xsl:variable name="Next_PE_Pos" select="min($PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@id_path)&gt;number($id_path)]/@id_path)"/>
  157. <xsl:variable name="Prev_PE_Pos" select="max($PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@id_path)&lt;=number($id_path)]/@id_path)"/>
  158. <xsl:variable name="Same_PE_Pos" select="max($PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@id_path)=number($id_path)]/@id_path)"/>
  159. <xsl:attribute name="id_path" select="$id_path"/>
  160. <xsl:attribute name="Next_PE_Pos" select="$Next_PE_Pos"/>
  161. <xsl:attribute name="Prev_PE_Pos" select="$Prev_PE_Pos"/>
  162. <xsl:attribute name="Same_PE_Pos" select="$Same_PE_Pos"/>
  163. <xsl:variable name="Next_PE_Pos_len">
  164. <xsl:choose>
  165. <xsl:when test="$Next_PE_Pos">
  166. <xsl:value-of select="sum($edge_joins_filled_paths_xml/edge_joins_filled_paths_xml/asText_XMl/LineString[number(@id_path) &gt;= number($id_path) and number(@id_path) &lt; number($Next_PE_Pos) ]/@len)"/>
  167. </xsl:when><xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  168. </xsl:choose>
  169. </xsl:variable>
  170. <xsl:variable name="Prev_PE_Pos_len">
  171. <xsl:choose>
  172. <xsl:when test="$Prev_PE_Pos">
  173. <xsl:value-of select="sum($edge_joins_filled_paths_xml/edge_joins_filled_paths_xml/asText_XMl/LineString[number(@id_path) &lt; number($id_path) and number(@id_path) &gt;= number($Prev_PE_Pos) ]/@len)"/>
  174. </xsl:when>
  175. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  176. </xsl:choose>
  177. </xsl:variable>
  178. <xsl:attribute name="Next_PE_Pos_len" select="$Next_PE_Pos_len"/>
  179. <xsl:attribute name="Prev_PE_Pos_len" select="$Prev_PE_Pos_len"/>
  180. <!--<xsl:copy-of select="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@Pos)&gt;number($id_path)]/@Pos"/>-->
  181. <xsl:variable name="Path_Point">
  182. <Path_Point>
  183. <xsl:choose>
  184. <xsl:when test="$Same_PE_Pos">
  185. <xsl:attribute name="len" select="0"/>
  186. <xsl:attribute name="debug" select="'going same'"/>
  187. <xsl:message>...Calculating to Self as PE( $Next_PE_Pos_len=<xsl:value-of select="$Next_PE_Pos_len"/>) &lt;= $Prev_PE_Pos_len=<xsl:value-of select="$Prev_PE_Pos_len"/> </xsl:message>
  188. <xsl:attribute name="PE_ID_Join" select="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@id_path)=number($Same_PE_Pos)]/@ID_Join"/>
  189. </xsl:when>
  190. <xsl:when test="not($Next_PE_Pos_len = '-1') and ($Prev_PE_Pos_len = '-1' or $Next_PE_Pos_len &lt;= $Prev_PE_Pos_len) ">
  191. <xsl:attribute name="debug" select="'going next'"/>
  192. <xsl:attribute name="len" select="$Next_PE_Pos_len"/>
  193. <xsl:attribute name="PE_ID_Join" select="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@id_path)=number($Next_PE_Pos)]/@ID_Join"/>
  194. <xsl:message>...Calculating to Next ( $Next_PE_Pos_len=<xsl:value-of select="$Next_PE_Pos_len"/>) &lt;= $Prev_PE_Pos_len=<xsl:value-of select="$Prev_PE_Pos_len"/> </xsl:message>
  195. <xsl:for-each select="$edge_joins_filled_paths_xml/edge_joins_filled_paths_xml/asText_XMl/LineString[number(@id_path) &gt; number($id_path) and number(@id_path) &lt;= number($Next_PE_Pos) ]">
  196. <xsl:copy-of select="."/>
  197. </xsl:for-each>
  198. </xsl:when>
  199. <xsl:otherwise>
  200. <xsl:attribute name="len" select="$Prev_PE_Pos_len"/>
  201. <xsl:attribute name="debug" select="'going prev'"/>
  202. <xsl:attribute name="PE_ID_Join" select="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@id_path)=number($Prev_PE_Pos)]/@ID_Join"/>
  203. <xsl:message>...Calculating to Prev ( $Next_PE_Pos_len=<xsl:value-of select="$Next_PE_Pos_len"/>) &lt;= $Prev_PE_Pos_len=<xsl:value-of select="$Prev_PE_Pos_len"/> </xsl:message>
  204. <xsl:for-each select="$edge_joins_filled_paths_xml/edge_joins_filled_paths_xml/asText_XMl/LineString[number(@id_path) &lt; number($id_path) and number(@id_path) &gt;= number($Prev_PE_Pos) ]">
  205. <xsl:sort select="number(@id_path)" order="descending"/>
  206. <xsl:copy-of select="."/>
  207. </xsl:for-each>
  208. </xsl:otherwise>
  209. </xsl:choose>
  210. </Path_Point>
  211. </xsl:variable>
  212. <xsl:copy-of select="$Path_Point/Path_Point/@*"/>
  213. <!--<debug_To_LINESTRING>
  214. <xsl:copy-of select="$Path_Point"/>
  215. </debug_To_LINESTRING>-->
  216. <xsl:choose>
  217. <xsl:when test="$Path_Point/Path_Point/(bp:Path_Point|LineString)">
  218. <xsl:call-template name="To_LINESTRING">
  219. <xsl:with-param name="Path_Point" select="$Path_Point/Path_Point"/>
  220. </xsl:call-template>
  221. </xsl:when>
  222. <xsl:otherwise>
  223. <ERORR>pewnie sasiedzkei sciezki Neighbour do obsluzenia i ich nie znaleziono
  224. jest info w /edge_paths_with_PE_controll/Path[1]/PointMatrixGroupPE[1]/PointMatrixGroup[1]/odpalam_liczenie[1]/koniec_wariantow[1]/bp:Path_Point_Cable[3]
  225. </ERORR>
  226. <xsl:message>ERROR nie znaleziono sciezki - moze sasiedzkie ? TODO</xsl:message>
  227. </xsl:otherwise>
  228. </xsl:choose>
  229. </detect_next_PE>
  230. </xsl:template>
  231. <xsl:template name="To_LINESTRING">
  232. <xsl:param name="Path_Point" required="yes"/>
  233. <LINESTRING>
  234. <xsl:value-of select="'LINESTRING ('"/>
  235. <xsl:for-each select="$Path_Point/(bp:Path_Point|LineString)">
  236. <xsl:value-of select="concat(@X,' ',@Y)"/>
  237. <xsl:if test="position()!=last()"><xsl:value-of select="', '"/></xsl:if>
  238. </xsl:for-each>
  239. <xsl:value-of select="')'"/>
  240. </LINESTRING>
  241. </xsl:template>
  242. <xsl:template match="*"/>
  243. </xsl:stylesheet>