cables_from_joins_to_PE.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. xmlns:wfs="http://www.opengis.net/wfs"
  6. xmlns="http://www.opengis.net/wfs"
  7. exclude-result-prefixes="xs"
  8. version="2.0">
  9. <xsl:output indent="yes"/>
  10. <xsl:strip-space elements="*"/>
  11. <xsl:include href="asText.xsl"/>
  12. <xsl:param name="plamy_prefix" /> <!-- select="'test2'" -->
  13. <xsl:param name="edge_paths_with_PE_fixed.xml" select="concat('edge_paths_with_PE_fixed',$plamy_prefix,'.xml')"/>
  14. <xsl:param name="joins_asText_xml.xml" select="concat('joins_asText_xml',$plamy_prefix,'.xml')"/>
  15. <!--<xsl:param name="edge_joins_filled_paths.xml" select="'edge_joins_filled_paths.xml'"/>-->
  16. <xsl:param name="points2joins.xml" select="concat('points2joins',$plamy_prefix,'.xml')"/>
  17. <xsl:param name="edge_joins_filled_paths" select="concat('edge_joins_filled_paths',$plamy_prefix)"/>
  18. <xsl:variable name="PE_candidates_dump" select="doc($edge_paths_with_PE_fixed.xml)"/>
  19. <xsl:variable name="joins_asText_Path_Point" select="doc($joins_asText_xml.xml)"/>
  20. <!--<xsl:variable name="edge_joins_filled_paths" select="doc($edge_joins_filled_paths.xml) "/>-->
  21. <xsl:variable name="points2joins" select="doc($points2joins.xml)"/>
  22. <!-- <joins_asText>
  23. <item id="0">POINT (18.7909 51.701067999083)</item>-->
  24. <xsl:template match="joins2ways_z_ID_Way">
  25. <cables_from_joins_to_PE>
  26. <!--<xsl:variable name="joins_asText_Path_Point">
  27. <xsl:apply-templates select="$joins_asText" mode="joins_asText"/>
  28. </xsl:variable>-->
  29. <!--<xsl:copy-of select="$joins_asText_Path_Point"/>-->
  30. <!--<xsl:copy-of select="$edge_joins_filled_paths"/>-->
  31. <!-- jedziemy po joins2ways_z_ID_Way, sprawdzamy czy jest dla niego PE_candidates_dump , jak tak, to szukamy jego PE i liczymy sciezke
  32. lub probujemy rysowac zawsze od konca drogi-->
  33. <xsl:for-each-group select="item" group-by="@id">
  34. <xsl:for-each select="current-group()">
  35. <xsl:variable name="ID_Way" select="@ID_Way"/>
  36. <xsl:variable name="ID_Join" select="@id"/>
  37. <!--<xsl:variable name="pos" select=" position()"/>--> <!-- tozsamosc ulozenia z waysow -->
  38. <xsl:variable name="ID_Point_count"/>
  39. <xsl:for-each select="Points">
  40. <xsl:message>#41 Calculating Cable for point:<xsl:value-of select=" text()"/>; ID_Join:<xsl:value-of select="$ID_Join"/></xsl:message>
  41. <xsl:variable name="ID_Point" select=" text()"/>
  42. <xsl:message>#53 opening doc(<xsl:value-of select="concat($edge_joins_filled_paths,'/edge_joins_filled_paths.',$ID_Way,'.xml')"/>)</xsl:message>
  43. <xsl:variable name="edge_joins_filled_paths_xml" select="doc(concat($edge_joins_filled_paths,'/edge_joins_filled_paths.',$ID_Way,'.xml'))"/>
  44. <!-- do ustalenia gdize sa najblizsze bp:Path_Point_Cable ID_Join="45" -> Target_ID_Join -->
  45. <!--<debug56><xsl:copy-of select="$edge_joins_filled_paths_xml/edge_joins_filled_paths_xml/asText_XMl[1]"/></debug56>-->
  46. <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'))"/>
  47. <!-- nie tzeba - jest w foreach dla Points !- trzeba sprawdzic czy join jest klientem - czy tylko PE! -->
  48. <xsl:choose>
  49. <!--<xsl:when test="not(@ID_Point)">
  50. <not_candidate><xsl:attribute name="descr" select="'this is probably join from way'"/>
  51. <xsl:attribute name="Joins" select="parent::node()/@id"/></not_candidate>
  52. </xsl:when>-->
  53. <!-- uwzgledniam usuniete punkty PE w Fixings -->
  54. <xsl:when test="$PE_candidates_dump/PE_candidates_dump/LINESTRING/bp:Path_Point[@ID_Join=$ID_Join] ">
  55. <not_candidate_is_pe><xsl:attribute name="descr" select="'this is PE '"/>
  56. <xsl:attribute name="Joins" select="$ID_Join"/>
  57. <xsl:copy-of select="$PE_candidates_dump/PE_candidates_dump/LINESTRING/bp:Path_Point[@ID_Join=$ID_Join]"/>
  58. </not_candidate_is_pe>
  59. </xsl:when>
  60. <xsl:otherwise>
  61. <cable_to_PE_to_be_calculated>
  62. <xsl:attribute name="ID_Way" select="$ID_Way"/>
  63. <xsl:attribute name="Joins" select="$ID_Join"/>
  64. <xsl:attribute name="ID_Point" select="$ID_Point"/>
  65. <!-- idziemy po drodze, -->
  66. <xsl:variable name="Join_X" select="$joins_asText_Path_Point/joins_asText_xml/item[@id=$ID_Join]/bp:Path_Point/@X"/>
  67. <xsl:variable name="Join_Y" select="$joins_asText_Path_Point/joins_asText_xml/item[@id=$ID_Join]/bp:Path_Point/@Y"/>
  68. <xsl:attribute name="Join_X" select="$Join_X"/><xsl:attribute name="Join_Y" select="$Join_Y"/>
  69. <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" />
  70. <xsl:choose>
  71. <xsl:when test="$id_path">
  72. <found_in_path_in_edge_joins_filled_path>
  73. <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]">
  74. <xsl:call-template name="detect_next_PE_adv">
  75. <xsl:with-param name="ID_Point" select="$ID_Point"/>
  76. <xsl:with-param name="id_path" select="@id_path"/>
  77. <xsl:with-param name="ID_Join" select="$ID_Join"/>
  78. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  79. <xsl:with-param name="edge_joins_filled_paths_xml" select="$edge_joins_filled_paths_xml"/>
  80. </xsl:call-template>
  81. </xsl:for-each>
  82. </found_in_path_in_edge_joins_filled_path>
  83. </xsl:when>
  84. <xsl:otherwise>
  85. <error>Not found $path
  86. <xsl:message>Not found $path</xsl:message>
  87. </error>
  88. </xsl:otherwise>
  89. </xsl:choose>
  90. </cable_to_PE_to_be_calculated>
  91. </xsl:otherwise>
  92. </xsl:choose>
  93. </xsl:for-each>
  94. </xsl:for-each>
  95. </xsl:for-each-group>
  96. </cables_from_joins_to_PE>
  97. </xsl:template>
  98. <xsl:template name="detect_next_PE_adv">
  99. <xsl:param name="ID_Point" required="yes"/>
  100. <xsl:param name="id_path" required="yes"/>
  101. <xsl:param name="ID_Join" required="yes"/>
  102. <xsl:param name="ID_Way" required="yes"/>
  103. <xsl:param name="edge_joins_filled_paths_xml" required="yes"/>
  104. <detect_next_PE>
  105. <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) )"/>
  106. <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) )"/>
  107. <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))"/>
  108. <xsl:attribute name="id_path" select="$id_path"/>
  109. <xsl:attribute name="Next_PE_Pos" select="$Next_PE_Pos"/>
  110. <xsl:attribute name="Prev_PE_Pos" select="$Prev_PE_Pos"/>
  111. <xsl:attribute name="Same_PE_Pos" select="$Same_PE_Pos"/>
  112. <xsl:variable name="Next_PE_Pos_len">
  113. <xsl:choose>
  114. <xsl:when test="$Next_PE_Pos">
  115. <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)"/>
  116. </xsl:when><xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  117. </xsl:choose>
  118. </xsl:variable>
  119. <xsl:variable name="Prev_PE_Pos_len">
  120. <xsl:choose>
  121. <xsl:when test="$Prev_PE_Pos">
  122. <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)"/>
  123. </xsl:when>
  124. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  125. </xsl:choose>
  126. </xsl:variable>
  127. <xsl:attribute name="Next_PE_Pos_len" select="$Next_PE_Pos_len"/>
  128. <xsl:attribute name="Prev_PE_Pos_len" select="$Prev_PE_Pos_len"/>
  129. <!--<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"/>-->
  130. <xsl:variable name="Path_Point">
  131. <Path_Point>
  132. <xsl:choose>
  133. <xsl:when test="$Same_PE_Pos">
  134. <xsl:attribute name="len" select="0"/>
  135. <xsl:attribute name="debug" select="'going same'"/>
  136. <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>
  137. <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"/>
  138. </xsl:when>
  139. <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)) ">
  140. <xsl:attribute name="debug" select="'going next'"/>
  141. <xsl:attribute name="len" select="$Next_PE_Pos_len"/>
  142. <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"/>
  143. <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>
  144. <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) ]">
  145. <xsl:copy-of select="."/>
  146. </xsl:for-each>
  147. </xsl:when>
  148. <xsl:otherwise>
  149. <xsl:attribute name="len" select="$Prev_PE_Pos_len"/>
  150. <xsl:attribute name="debug" select="'going prev'"/>
  151. <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"/>
  152. <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>
  153. <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) ]">
  154. <xsl:sort select="number(@id_path)" order="descending"/>
  155. <xsl:copy-of select="."/>
  156. </xsl:for-each>
  157. </xsl:otherwise>
  158. </xsl:choose>
  159. </Path_Point>
  160. </xsl:variable>
  161. <xsl:copy-of select="$Path_Point/Path_Point/@*"/>
  162. <!--<debug_To_LINESTRING>
  163. <xsl:copy-of select="$Path_Point"/>
  164. </debug_To_LINESTRING>-->
  165. <xsl:choose>
  166. <xsl:when test="$Path_Point/Path_Point/(bp:Path_Point|LineString)">
  167. <xsl:call-template name="To_LINESTRING">
  168. <xsl:with-param name="Path_Point" select="$Path_Point/Path_Point"/>
  169. </xsl:call-template>
  170. </xsl:when>
  171. <xsl:otherwise>
  172. <ERORR>pewnie sasiedzkei sciezki Neighbour do obsluzenia i ich nie znaleziono
  173. 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]
  174. </ERORR>
  175. <xsl:message>ERROR nie znaleziono sciezki - moze sasiedzkie ? TODO $ID_Way<xsl:value-of select="$ID_Way"/>;</xsl:message>
  176. <!--<xsl:variable name=""/>-->
  177. </xsl:otherwise>
  178. </xsl:choose>
  179. </detect_next_PE>
  180. </xsl:template>
  181. <xsl:template name="To_LINESTRING">
  182. <xsl:param name="Path_Point" required="yes"/>
  183. <LINESTRING>
  184. <xsl:value-of select="'LINESTRING ('"/>
  185. <xsl:for-each select="$Path_Point/(bp:Path_Point|LineString)">
  186. <xsl:value-of select="concat(@X,' ',@Y)"/>
  187. <xsl:if test="position()!=last()"><xsl:value-of select="', '"/></xsl:if>
  188. </xsl:for-each>
  189. <xsl:value-of select="')'"/>
  190. </LINESTRING>
  191. </xsl:template>
  192. <xsl:template match="*"/>
  193. </xsl:stylesheet>