edge_joins_filled_paths_make.xsl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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:param name="ways_as_Text_z_ID_xml.xml" select="'ways_as_Text_z_ID_xml.xml'"/>
  8. <xsl:variable name="ways_asText_z_ID_xml" select="doc($ways_as_Text_z_ID_xml.xml)"/>
  9. <xsl:param name="joins_asText_xml.xml" select="'joins_asText_xml.xml'"/>
  10. <xsl:variable name="joins_asText_xml" select="doc($joins_asText_xml.xml)"/>
  11. <xsl:param name="ways2joins.xml" select="'ways2joins.xml'"/>
  12. <xsl:variable name="ways2joins" select="doc($ways2joins.xml)"/>
  13. <xsl:param name="joins2ways_z_ID_Way.xml" select="'joins2ways_z_ID_Way.xml'"/>
  14. <xsl:variable name="joins2ways_z_ID_Way" select="doc($joins2ways_z_ID_Way.xml)"/>
  15. <xsl:output indent="yes"/>
  16. <xsl:strip-space elements="*"/>
  17. <xsl:template match="EdgeWayJoins">
  18. <edge_joins_filled_paths>
  19. <xsl:attribute name="stylesheet" select="'edge_joins_filled_paths_make.xsl'"/>
  20. <xsl:apply-templates/>
  21. </edge_joins_filled_paths>
  22. </xsl:template>
  23. <xsl:template match="EdgeWayJoinsPair">
  24. <item>
  25. <xsl:attribute name="id" select="@ID_Way"/>
  26. <xsl:variable name="ID_Way" select="@ID_Way"/>
  27. <!--<xsl:attribute name="Count" select="$asText/asText/@Count"/>-->
  28. <asText>
  29. <xsl:variable name="bp:Joins">
  30. <xsl:for-each select="bp:Joins">
  31. <bp:Joins>
  32. <xsl:copy-of select="@*"/>
  33. <xsl:copy-of select="$joins_asText_xml/joins_asText_xml/item[@id= current()/@Joins]/bp:Path_Point/@X"/>
  34. <xsl:copy-of select="$joins_asText_xml/joins_asText_xml/item[@id= current()/@Joins]/bp:Path_Point/@Y"/>
  35. <xsl:attribute name="position" select="position()"/>
  36. <!--<xsl:copy-of select="$joins_asText_xml/joins_asText_xml/item[@id= current()/@id]/"/>-->
  37. </bp:Joins>
  38. </xsl:for-each>
  39. </xsl:variable>
  40. <!--<Joins>
  41. <xsl:copy-of select="$bp:Joins"/>
  42. </Joins>-->
  43. <xsl:variable name="Join_X1" select="$bp:Joins/bp:Joins[@position=1]/@X"/>
  44. <xsl:variable name="Join_Y1" select="$bp:Joins/bp:Joins[@position=1]/@Y"/>
  45. <xsl:variable name="Join_X2" select="$bp:Joins/bp:Joins[@position=2]/@X"/>
  46. <xsl:variable name="Join_Y2" select="$bp:Joins/bp:Joins[@position=2]/@Y"/>
  47. <!-- na podstawie joina ustalamy jego wspolrzedne -->
  48. <xsl:variable name="Ways">
  49. <Ways>
  50. <xsl:attribute name="Join_X1" select="$Join_X1"/>
  51. <xsl:attribute name="Join_Y1" select="$Join_Y1"/>
  52. <xsl:attribute name="Join_X2" select="$Join_X2"/>
  53. <xsl:attribute name="Join_Y2" select="$Join_Y2"/>
  54. <xsl:variable name="Ways">
  55. <xsl:for-each select="$ways_asText_z_ID_xml/ways_asText_z_ID_xml/item[@ID_Way=$ID_Way]">
  56. <Way>
  57. <xsl:attribute name="id" select="@id"/>
  58. <xsl:attribute name="len" select="@len"/>
  59. <xsl:variable name="bp:Path_Point">
  60. <xsl:for-each select="bp:Path_Point">
  61. <bp:Path_Point>
  62. <xsl:copy-of select="@*"/>
  63. <xsl:attribute name="position" select="position()"/>
  64. </bp:Path_Point>
  65. </xsl:for-each>
  66. </xsl:variable>
  67. <!-- <xsl:variable name="Way_X1" select="$bp:Path_Point/bp:Path_Point[@position=1]/@X"/>
  68. <xsl:variable name="Way_Y1" select="$bp:Path_Point/bp:Path_Point[@position=1]/@Y"/>
  69. <xsl:variable name="Way_X2" select="$bp:Path_Point/bp:Path_Point[@position=2]/@X"/>
  70. <xsl:variable name="Way_Y2" select="$bp:Path_Point/bp:Path_Point[@position=2]/@Y"/>-->
  71. <xsl:attribute name="Way_X1" select="$bp:Path_Point/bp:Path_Point[@position=1]/@X"/>
  72. <xsl:attribute name="Way_Y1" select="$bp:Path_Point/bp:Path_Point[@position=1]/@Y"/>
  73. <xsl:attribute name="Way_X2" select="$bp:Path_Point/bp:Path_Point[@position=2]/@X"/>
  74. <xsl:attribute name="Way_Y2" select="$bp:Path_Point/bp:Path_Point[@position=2]/@Y"/>
  75. </Way>
  76. </xsl:for-each>
  77. </xsl:variable>
  78. <xsl:copy-of select="$Ways"/>
  79. <!-- teraz trzeba wiedziec ktory punkt wziac z drogi - czy pierwszy czy drugi jaki pasuje do pary -->
  80. <xsl:variable name="Ways_J1_W1">
  81. <xsl:for-each select="$Ways/Way[@Way_X1=$Join_X1 and @Way_Y1=$Join_Y1]">
  82. <Way_next_cand>
  83. <xsl:copy-of select="@id"/>
  84. <xsl:copy-of select="@Way_X2"/>
  85. <xsl:copy-of select="@Way_Y2"/>
  86. </Way_next_cand>
  87. </xsl:for-each>
  88. </xsl:variable>
  89. <xsl:copy-of select="$Ways_J1_W1"/>
  90. <xsl:variable name="Ways_J2_W1">
  91. <xsl:for-each select="$Ways/Way[@Way_X1=$Join_X2 and @Way_Y1=$Join_Y2]">
  92. <Way_next_cand>
  93. <xsl:copy-of select="@id"/>
  94. <xsl:copy-of select="@Way_X2"/>
  95. <xsl:copy-of select="@Way_Y2"/>
  96. </Way_next_cand>
  97. </xsl:for-each>
  98. </xsl:variable>
  99. <xsl:copy-of select="$Ways_J2_W1"/>
  100. <xsl:variable name="Ways_J1_W2">
  101. <xsl:for-each select="$Ways/Way[@Way_X2=$Join_X1 and @Way_Y2=$Join_Y1]">
  102. <Way_next_cand>
  103. <xsl:copy-of select="@id"/>
  104. <xsl:copy-of select="@Way_X1"/>
  105. <xsl:copy-of select="@Way_Y1"/>
  106. </Way_next_cand>
  107. </xsl:for-each>
  108. </xsl:variable>
  109. <xsl:copy-of select="$Ways_J1_W2"/>
  110. <xsl:variable name="Ways_J2_W2">
  111. <xsl:for-each select="$Ways/Way[@Way_X2=$Join_X2 and @Way_Y2=$Join_Y2]">
  112. <Way_next_cand>
  113. <xsl:copy-of select="@id"/>
  114. <xsl:copy-of select="@Way_X1"/>
  115. <xsl:copy-of select="@Way_Y1"/>
  116. </Way_next_cand>
  117. </xsl:for-each>
  118. </xsl:variable>
  119. <xsl:copy-of select="$Ways_J2_W2"/>
  120. <!-- poszukamy czy Way_X2 wystepuje -->
  121. </Ways>
  122. </xsl:variable>
  123. <!--<xsl:copy-of select="$Ways"/>-->
  124. <!--<xsl:variable name="Way_1_or_2">
  125. <xsl:choose>
  126. <xsl:when test="$Ways/Ways/Way_next_cand[1]/@Way_X2">
  127. <xsl:value-of select="1"/>
  128. </xsl:when>
  129. <xsl:otherwise><xsl:value-of select="2"/></xsl:otherwise>
  130. </xsl:choose>
  131. </xsl:variable>-->
  132. <!--<Way_1_or_2><xsl:value-of select="$Way_1_or_2"/></Way_1_or_2>-->
  133. <xsl:variable name="LineString">
  134. <xsl:call-template name="PlaceWay">
  135. <xsl:with-param name="Ways" select="$Ways"/>
  136. <xsl:with-param name="Cur_X1" select="$Ways/Ways/@Join_X1"/>
  137. <xsl:with-param name="Cur_Y1" select="$Ways/Ways/@Join_Y1"/>
  138. <xsl:with-param name="Last_X2" select="$Ways/Ways/@Join_X2"/>
  139. <xsl:with-param name="Last_Y2" select="$Ways/Ways/@Join_Y2"/>
  140. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  141. <!--<xsl:with-param name="Way_1_or_2" select="$Way_1_or_2"/>-->
  142. <!--<xsl:with-param name="not_id" select="$Ways/Ways/Way_next_cand/@id"/>-->
  143. </xsl:call-template>
  144. </xsl:variable>
  145. <xsl:variable name="len" select="sum($LineString/LineString/@len)"/>
  146. <xsl:attribute name="len" select="$len"/>
  147. <xsl:attribute name="Points_cnt" select="count($LineString/LineString/Points)"/>
  148. <xsl:attribute name="Count" select=" count($LineString/LineString)"/>
  149. <!-- dodatkowo w xmlu aby bylo prosciej do przetwarzania -->
  150. <!--<asText_XMl>
  151. <xsl:copy-of select="$LineString"/>
  152. </asText_XMl>-->
  153. <xsl:result-document href="edge_joins_filled_paths/edge_joins_filled_paths.{$ID_Way}.xml">
  154. <edge_joins_filled_paths_xml>
  155. <xsl:attribute name="id" select="$ID_Way"/>
  156. <xsl:attribute name="Points_cnt" select="count($LineString/LineString/Points)"/>
  157. <asText_XMl>
  158. <xsl:attribute name="len" select="$len"/>
  159. <xsl:attribute name="id" select="$ID_Way"/>
  160. <xsl:attribute name="Points_cnt" select="count($LineString/LineString/Points)"/>
  161. <xsl:copy-of select="$LineString"/>
  162. </asText_XMl>
  163. </edge_joins_filled_paths_xml>
  164. </xsl:result-document>
  165. <xsl:call-template name="AsText">
  166. <xsl:with-param name="LineString" select="$LineString"/>
  167. </xsl:call-template>
  168. </asText>
  169. </item>
  170. </xsl:template>
  171. <xsl:template name="PlaceWay">
  172. <xsl:param name="Ways" required="yes"/>
  173. <xsl:param name="Cur_X1" required="yes"/>
  174. <xsl:param name="Cur_Y1" required="yes"/>
  175. <!--<xsl:param name="Way_1_or_2" required="yes"/>-->
  176. <xsl:param name="Last_X2" required="yes"/>
  177. <xsl:param name="Last_Y2" required="yes"/>
  178. <xsl:param name="loop" select="1"/>
  179. <xsl:param name="not_id" required="no"/>
  180. <xsl:param name="ID_Way" required="yes"/>
  181. <!--<LineString>
  182. <xsl:attribute name="X1" select="$Cur_X1"/>
  183. <xsl:attribute name="Y1" select="$Cur_Y1"/>
  184. </LineString>-->
  185. <!--<xsl:choose>
  186. <xsl:when test="$Way_1_or_2"></xsl:when>
  187. </xsl:choose>-->
  188. <!--<debug>
  189. <xsl:attribute name="Cur_X1" select="$Cur_X1"/>
  190. <xsl:attribute name="Cur_Y1" select="$Cur_Y1"/>
  191. <xsl:attribute name="not_id" select="$not_id"/>
  192. </debug>-->
  193. <xsl:variable name="Linestring">
  194. <xsl:for-each select="$Ways/Ways/Way[@Way_X1=$Cur_X1 and @Way_Y1=$Cur_Y1 and ( not($not_id) or not(@id=$not_id)) ]">
  195. <LineString>
  196. <xsl:attribute name="X" select="@Way_X2"/>
  197. <xsl:attribute name="Y" select="@Way_Y2"/>
  198. <xsl:attribute name="not_id" select="@id"/>
  199. <xsl:attribute name="len" select="@len"/>
  200. <xsl:variable name="X" select="@Way_X2"/>
  201. <xsl:variable name="Y" select="@Way_Y2"/>
  202. <xsl:for-each select="$ways2joins/ways2joins/item[@id= current()/@id]/item">
  203. <xsl:for-each select="$joins_asText_xml/joins_asText_xml/item[@id= current()/text()]/bp:Path_Point">
  204. <xsl:if test="@X=$X and @Y=$Y">
  205. <xsl:variable name="ID_Join" select="parent::node()/@id"/>
  206. <!-- punkty podpiete -->
  207. <xsl:copy-of select="$joins2ways_z_ID_Way/joins2ways_z_ID_Way/item[@id=$ID_Join]/Points"/>
  208. <!-- wyszukanie drog wychodzacych innych niz nasza z punktu -->
  209. <xsl:for-each select="$joins2ways_z_ID_Way/joins2ways_z_ID_Way/item[@id=$ID_Join]/item[not(@ID_WAY=$ID_Way)]">
  210. <Ways>
  211. <xsl:attribute name="ID_WAY" select="@ID_WAY"/>
  212. <xsl:attribute name="ways_id" select="text()"/>
  213. </Ways>
  214. </xsl:for-each>
  215. </xsl:if>
  216. </xsl:for-each>
  217. </xsl:for-each>
  218. </LineString>
  219. </xsl:for-each>
  220. <xsl:for-each select="$Ways/Ways/Way[@Way_X2=$Cur_X1 and @Way_Y2=$Cur_Y1 and ( not($not_id) or not(@id=$not_id)) ]">
  221. <LineString>
  222. <xsl:attribute name="X" select="@Way_X1"/>
  223. <xsl:attribute name="Y" select="@Way_Y1"/>
  224. <xsl:attribute name="not_id" select="@id"/>
  225. <xsl:attribute name="len" select="@len"/>
  226. <xsl:variable name="X" select="@Way_X1"/>
  227. <xsl:variable name="Y" select="@Way_Y1"/>
  228. <xsl:for-each select="$ways2joins/ways2joins/item[@id= current()/@id]/item">
  229. <xsl:for-each select="$joins_asText_xml/joins_asText_xml/item[@id= current()/text()]/bp:Path_Point">
  230. <xsl:if test="@X=$X and @Y=$Y">
  231. <xsl:variable name="ID_Join" select="parent::node()/@id"/>
  232. <!-- punkty podpiete -->
  233. <xsl:copy-of select="$joins2ways_z_ID_Way/joins2ways_z_ID_Way/item[@id=$ID_Join]/Points"/>
  234. <!-- wyszukanie drog wychodzacych innych niz nasza z punktu -->
  235. <xsl:for-each select="$joins2ways_z_ID_Way/joins2ways_z_ID_Way/item[@id=$ID_Join]/item[not(@ID_WAY=$ID_Way)]">
  236. <Ways>
  237. <xsl:attribute name="ID_WAY" select="@ID_WAY"/>
  238. <xsl:attribute name="ways_id" select="text()"/>
  239. </Ways>
  240. </xsl:for-each>
  241. </xsl:if>
  242. </xsl:for-each>
  243. </xsl:for-each>
  244. </LineString>
  245. </xsl:for-each>
  246. </xsl:variable>
  247. <xsl:copy-of select="$Linestring"/>
  248. <xsl:choose>
  249. <xsl:when test="$loop &gt; 100000">
  250. <loop_limit/>
  251. </xsl:when>
  252. <xsl:when test="$Linestring/LineString/@X = $Last_X2 and $Linestring/LineString/@Y = $Last_Y2 ">
  253. <ostatni/>
  254. </xsl:when>
  255. <xsl:otherwise>
  256. <xsl:call-template name="PlaceWay">
  257. <xsl:with-param name="Ways" select="$Ways"/>
  258. <xsl:with-param name="Cur_X1" select="$Linestring/LineString/@X"/>
  259. <xsl:with-param name="Cur_Y1" select="$Linestring/LineString/@Y"/>
  260. <xsl:with-param name="Last_X2" select="$Last_X2"/>
  261. <xsl:with-param name="Last_Y2" select="$Last_Y2"/>
  262. <xsl:with-param name="not_id" select="$Linestring/LineString/@not_id"/>
  263. <xsl:with-param name="loop" select="$loop+1"/>
  264. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  265. </xsl:call-template>
  266. </xsl:otherwise>
  267. </xsl:choose>
  268. </xsl:template>
  269. <!--<xsl:template name="AsText_XML">
  270. <xsl:param name="LineString" required="yes"/>
  271. <xsl:for-each select="$LineString/LineString">
  272. <PathPoint>
  273. <xsl:copy-of select="@*"/>
  274. </PathPoint>
  275. </xsl:for-each>
  276. </xsl:template>-->
  277. <xsl:template name="AsText">
  278. <xsl:param name="LineString" required="yes"/>
  279. <xsl:value-of select="'LINESTRING ('"/>
  280. <xsl:for-each select="$LineString/LineString">
  281. <xsl:value-of select="concat(@X,' ',@Y)"/>
  282. <xsl:if test="not(position()= last())">
  283. <xsl:value-of select="', '"/>
  284. </xsl:if>
  285. </xsl:for-each>
  286. <xsl:value-of select="')'"/>
  287. </xsl:template>
  288. </xsl:stylesheet>