edge_joins_filled_paths_make.xsl 18 KB

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