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