cables_from_joins_to_PE.xsl 20 KB

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