Explorar o código

aktualna zoptyamlizowana wersja do wrzucania kabli

a.binder %!s(int64=9) %!d(string=hai) anos
pai
achega
1be4d2edbc

+ 13 - 3
SE/dev/php-cli/biale_put_Cables_to_PE.php

@@ -146,7 +146,17 @@ foreach($cables_from_joins_to_PE->xpath('cable_to_PE_to_be_calculated') as $chil
 		   $cables_from_joins_to_PE_arr[$id_j]['Joins']=$Joins;
 		   $cables_from_joins_to_PE_arr[$id_j]['ID_Way']=$ID_Way;
 		   $cables_from_joins_to_PE_arr[$id_j]['ID_Point']=$ID_Point;
-	   }
+		   
+		   $detect_next_PE=$Path_Point_xml->xpath('detect_next_PE');
+		   		foreach($detect_next_PE->attributes() as $a=>$b) {
+			   		if($a=='len') $len=$b[0];
+			   		if($a=='PE_ID_Join') $PE_ID_Join=$b[0];		   
+	   			}
+	   			settype($len, "integer");
+	   			settype($PE_ID_Join, "integer");
+	   	   $cables_from_joins_to_PE_arr[$id_j]['len']=$len;
+		   $cables_from_joins_to_PE_arr[$id_j]['PE_ID_Join']=$PE_ID_Join;
+		   
 }
 
 echo "\n<br>#150 cables_from_joins_to_PE_arr";
@@ -159,9 +169,9 @@ unset($ID_Way);
 
 foreach($cables_from_joins_to_PE_arr as $id_j=>$Path_Point_val) {
 		
-		$sql_Path_Point_val="insert into Rozdzielcza_test_bzyk_Cables_to_PE (the_geom,ID_Way,ID_Point)
+		$sql_Path_Point_val="insert into Rozdzielcza_test_bzyk_Cables_to_PE (the_geom,ID_Way,ID_Point,len,PE_ID_Join)
 		     values (ST_GeomFromText('".$Path_Point_val['LINESTRING']."'),'".$Path_Point_val['ID_Way']."',
-		     '".$Path_Point_val['ID_Point']."'   )   ";
+		     '".$Path_Point_val['ID_Point']."' ,'".$Path_Point_val['len']."','".$Path_Point_val['PE_ID_Join']."'  )   ";
 		    echo "#216Query path ins:: ".$sql_Path_Point_val."  ";
 		    //if(strlen($edge_joins_filled_paths[$ID_Way]['asText'])>2)
 		    if(strlen($Path_Point_val['LINESTRING'])>1) 

+ 49 - 18
SE/dev/php-cli/build.xml

@@ -1,14 +1,38 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project
     xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
-    basedir="." name="biale_plamy-generate_data" default="biale_plamy-generate_data">
-    
+    basedir="." name="biale_plamy-generate_data" default="default">
     
     
+    <tstamp><format property="TODAY_UK" pattern="yyyy-mm-dd"/></tstamp>
+   
    
     
     
+    <property name="build.log" value="build.log"/><property name="build.log.old" value="${build.log}.old"/>
+    
+    <target name="build_log_exists">
+        
+        <condition taskname="build.log.old_file"  property="build_log_exists" value="tak">
+            <!--<echo>sprawdzam czy jest ${build.log} </echo>-->
+            <available file="${build.log}" filepath="." />
+        </condition>
+    </target>
+    
+    <target name="build.log.old_file" depends="build_log_exists">
+        <!--<move file="${build.log}" tofile="${build.log}.old"/>-->
+        <echo append="true" file="${build.log}"> Archiwizacja loga w dniu  ${TODAY_UK} 
+        </echo>
+        <concat destfile="${build.log.old}" append="true">
+            <filelist dir="." files="${build.log}"/>
+        </concat>
+        <delete file="${build.log}"/>
+    </target>
     
+    <target name="default">
+        <antcall target="build.log.old_file"/>
+        <antcall target="biale_plamy-generate_data"/>
+    </target>
     
     <property name="PE_Price" value="2500"/>
     <property name="Cable_Price" value="3"/>
@@ -16,6 +40,8 @@
     <property name="logic" value="grouped"/>
     <!--<xsl:param name="logic" select="'sorted'"/>--> <!-- tutaj robi grupy ale analizyje w grupie tylko wazniejsze/bardziej oblozone wezly -->
     
+    <property name="mail_inform" value="a.binder@biall-net.pl"/> <!-- to inform about job complete -->
+    
     
     <property name="biale_plamy_class_regenerate.php" value="biale_plamy_class_regenerate.php"/>
     
@@ -35,6 +61,7 @@
         <property name="waysLengths.xmll" value="waysLengths.xml"/>
             <property name="joins2ways_z_ID_Way.xsl" value="joins2ways_z_ID_Way.xsl"/>
              <property name="joins2ways_z_ID_Way.xml" value="joins2ways_z_ID_Way.xml"/>
+                <property name="joins2ways_z_ID_Way_tempdir" value="joins2ways_z_ID_Way"/><!-- do trzymania tempow - nie wiadomo czy potrzebne bo duzo plikow -->
             <property name="biale_plamy_joins2ways_do_paths.xsl" value="biale_plamy_joins2ways_do_paths.xsl"/>
         
             <property name="edge_joins_filled_paths_make.xsl" value="edge_joins_filled_paths_make.xsl"/>
@@ -130,7 +157,8 @@
     </target>
    
     
-    <target name="biale_plamy-generate_data">
+    <target name="biale_plamy-generate_data" description="regenerate data and make all to final">
+        <record name="${build.log}" loglevel="verbose" append="true"/>
         <!-- nowy sposob -->
         <antcall target="biale_plamy_class_regenerate.php"/>  
         
@@ -141,9 +169,7 @@
         
         <delete file="${edge_joins.xml}"/>
         <antcall target="edge_joins.xml"/>
-        
        
-     
         <!--<antcall target="biale_plamy_class_findWay.php"/>-->
         <antcall target="PE_and_Cables"/>
     </target>
@@ -270,8 +296,7 @@
             <classpath location="/opt/local/share/java/saxon9he.jar"/>
             <param name="points2joins.xml"  expression="${points2joins.xml}"/>
             <param name="ways2drogi.xml"  expression="${ways2drogi.xml}"/>
-            
-            
+            <param name="joins2ways_z_ID_Way_tempdir" expression="${joins2ways_z_ID_Way_tempdir}"/>
         </xslt>
     </target>
    
@@ -319,12 +344,7 @@
              <param name="ways2drogi.xml" expression="${ways2drogi.xml}"/>
              <param name="waysLengths.xml" expression="${waysLengths.xmll}"/>
              <!--<param name="ways2joins.xml"  expression="${ways2joins.xml}"/>-->
-             
          </xslt>
-        
-        
-        
-        
      </target>
     
     <target name="edge_joins_filled_paths_make" description="przygotowanie sciezek do parsowania przez ${edge_paths_with_PE_controll.xsl}, male sciezki do katalogu ${edge_joins_filled_paths} oraz zbudowanie zadania do build ">
@@ -406,7 +426,7 @@
                 <!--<attribute name="http://saxon.sf.net/feature/initialTemplate" value="asd"/>-->
             </factory>
             <classpath location="/opt/local/share/java/saxon9he.jar"/>
-            <!--<param name="dita_task_template_file_param" expression="main.dita"/>-->
+            <param name="joins2ways_z_ID_Way.xml" expression="${joins2ways_z_ID_Way.xml}"/>
         </xslt>
     </target>
     <!-- postawienie PE po trasach nowe-->
@@ -415,14 +435,11 @@
             z parametrami PE_Price=${PE_Price} , Cable_Price=${Cable_Price}, max_combinate_groups_elements=${max_combinate_groups_elements}, 
             logic=${logic}. 
             "/>
-        
         <delete file="${edge_paths_with_PE_controll.xml}"/>
-        
          <delete dir="${edge_paths_with_PE_controll_temp}"/>
          <delete dir="${edge_paths_with_PE_controll_temp.alias}"/>
          <mkdir dir="${edge_paths_with_PE_controll_temp}"/>
          <symlink link="${edge_paths_with_PE_controll_temp.alias}" resource="${edge_paths_with_PE_controll_temp}"/>
-        
                 <xslt basedir="./" style="${edge_paths_with_PE_controll.xsl}" in="${edge_joins_filled_paths.xml}"  destdir="./" out="${edge_paths_with_PE_controll.xml}" >
                    <factory name="net.sf.saxon.TransformerFactoryImpl">    
                        <attribute name="http://saxon.sf.net/feature/xinclude-aware" value="true"/>
@@ -433,10 +450,12 @@
                    <!--<param name="edge_paths_with_PE.xml" expression="${edge_paths_with_PE.xml}"/>-->
                    <param name="edge_paths_with_PE_controll_temp" expression="${edge_paths_with_PE_controll_temp}"/>
                    <param name="edge_paths_with_PE_controll_temp.alias" expression="${edge_paths_with_PE_controll_temp.alias}"/>
-                   <param name="PE_Price" expression="${PE_Price}"/>
+                    <param name="edge_joins_filled_paths" expression="${edge_joins_filled_paths}"/>
+                    <param name="PE_Price" expression="${PE_Price}"/>
                    <param name="Cable_Price" expression="${Cable_Price}"/>
                    <param name="max_combinate_groups_elements" expression="${max_combinate_groups_elements}"/> <!-- po ile wezlow mamy grupowac do wyliczania kombinacji kosztow -->
                    <param name="logic" expression="${logic}"/>
+                    
                    <!--<xsl:param name="logic" select="'sorted'"/>--> <!-- tutaj robi grupy ale analizyje w grupie tylko wazniejsze/bardziej oblozone wezly -->
                </xslt>
     </target>
@@ -455,7 +474,7 @@
    
    
     <target name="edge_paths_with_PE.xml">
-        <echo message="Wyznaczenie PE na podstawie tras ${edge_paths_with_PE.xml} na podstawie ${edge_paths_with_PE_controll.xml} "/>
+        <echo message="OLD - edge_paths_with_PE.xml_from_collection!!! teraz uzywac Wyznaczenie PE na podstawie tras ${edge_paths_with_PE.xml} na podstawie ${edge_paths_with_PE_controll.xml} "/>
         <delete file="${edge_paths_with_PE.xml}"/>
         
         <xslt basedir="./" style="${edge_paths_with_PE_controll_to_PE.xsl}" in="${edge_paths_with_PE_controll.xml}"  destdir="./" out="${edge_paths_with_PE.xml}" >
@@ -504,6 +523,11 @@
                 <!--<attribute name="http://saxon.sf.net/feature/initialTemplate" value="asd"/>-->
             </factory>
             <classpath location="/opt/local/share/java/saxon9he.jar"/>
+            <param name="edge_paths_with_PE.xml" expression="${edge_paths_with_PE.xml}"/>
+            <param name="joins_asText_xml.xml" expression="${joins_asText_xml.xml}"/>
+            <param name="edge_joins_filled_paths.xml" expression="${edge_joins_filled_paths.xml}"/>
+            <param name="points2joins.xml" expression="${points2joins.xml}"/>
+            <param name="edge_joins_filled_paths" expression="${edge_joins_filled_paths}"/>
             <!--<param name="dita_task_template_file_param" expression="main.dita"/>-->
         </xslt>
     </target>
@@ -598,6 +622,13 @@
     
     <!--<property name="biale_plamy-prepare_sql_data.php" value="biale_plamy-prepare_sql_data.php"/>-->
     
+    <target name="mail_inform">
+        
+        <echo message="informujemy o kompletnej pracy"/>
+        <exec executable="mail" failonerror="true" dir=".">
+            <arg value="echo 'ant task done | mail ${mail_inform}'"/>
+        </exec>
+    </target>
     
    
    

+ 265 - 150
SE/dev/php-cli/cables_from_joins_to_PE.xsl

@@ -9,136 +9,251 @@
     
     <xsl:include href="asText.xsl"/>
     
-    <xsl:variable name="PE_candidates_dump" select="doc('edge_paths_with_PE.xml')"/>
-    <xsl:variable name="joins_asText" select="doc('joins_asText.xml')"/>
-    <xsl:variable name="edge_joins_filled_paths" select="doc('edge_joins_filled_paths.xml') "/>
-    <xsl:variable name="points2joins" select="doc('points2joins.xml')"/>
+    <xsl:param name="edge_paths_with_PE.xml" select="'edge_paths_with_PE.xml'"/>
+    <xsl:param name="joins_asText_xml.xml" select="'joins_asText_xml.xml'"/>
+    <!--<xsl:param name="edge_joins_filled_paths.xml" select="'edge_joins_filled_paths.xml'"/>-->
+    <xsl:param name="points2joins.xml" select="'points2joins.xml'"/>
+    <xsl:param name="edge_joins_filled_paths" select="'edge_joins_filled_paths'"/>
+    
+    <xsl:variable name="PE_candidates_dump" select="doc($edge_paths_with_PE.xml)"/>
+    <xsl:variable name="joins_asText_Path_Point" select="doc($joins_asText_xml.xml)"/>
+    <!--<xsl:variable name="edge_joins_filled_paths" select="doc($edge_joins_filled_paths.xml) "/>-->
+    <xsl:variable name="points2joins" select="doc($points2joins.xml)"/>
+    
     
     <!-- <joins_asText>
         <item id="0">POINT (18.7909 51.701067999083)</item>-->
     <xsl:template match="joins2ways_z_ID_Way">
         <cables_from_joins_to_PE>
-        <xsl:variable name="joins_asText_Path_Point">
+        <!--<xsl:variable name="joins_asText_Path_Point">
             <xsl:apply-templates select="$joins_asText" mode="joins_asText"/>
-        </xsl:variable>
-            
+        </xsl:variable>-->   
          <!--<xsl:copy-of select="$joins_asText_Path_Point"/>-->
-            
-        <xsl:variable name="edge_joins_filled_paths">
-            <xsl:apply-templates select="$edge_joins_filled_paths" mode="edge_joins_filled_paths"/>
-        </xsl:variable>
-            
                 <!--<xsl:copy-of select="$edge_joins_filled_paths"/>-->
-            
-            
         <!-- jedziemy po joins2ways_z_ID_Way, sprawdzamy czy jest dla niego PE_candidates_dump , jak tak, to szukamy jego PE i liczymy sciezke 
                lub probujemy rysowac zawsze od konca drogi-->
-            
           <xsl:for-each select="item">
             <xsl:variable name="ID_Way" select="@ID_Way"/>
-            <xsl:variable name="Joins" select="@id"/>
-            <xsl:variable name="ID_Point" select="@ID_Point"/>
-            <xsl:choose> 
-                <!-- trzeba sprawdzic czy join jest klientem - czy tylko PE! -->
-                <xsl:when test="not(@ID_Point)">
-                    <not_candidate><xsl:attribute name="descr" select="'this is probably join from way'"/>
-                        <xsl:attribute name="Joins" select="@id"/></not_candidate>
-                </xsl:when>
-                <xsl:when test="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=current()/@ID_Way]">
-                    <cable_to_PE_to_be_calculated>
-                        <xsl:attribute name="ID_Way" select="@ID_Way"/>
-                        <xsl:attribute name="Joins" select="@id"/>
-                        <xsl:attribute name="ID_Point" select="@ID_Point"/>
-                         <!-- idziemy po drodze,  -->
-                        <xsl:variable name="Join_X" select="$joins_asText_Path_Point/joins_asText/item[@id=$Joins]/As_POINT_to_xml/@X"/>
-                        <xsl:variable name="Join_Y" select="$joins_asText_Path_Point/joins_asText/item[@id=$Joins]/As_POINT_to_xml/@Y"/>
-                        <xsl:attribute name="Join_X" select="$Join_X"/><xsl:attribute name="Join_Y" select="$Join_Y"/>
-                        <xsl:variable name="found_in_path_in_edge_joins_filled_path">
-                            <xsl:for-each select="$edge_joins_filled_paths/edge_joins_filled_paths/item[@id=$ID_Way]/bp:Path_Point">
-                                <xsl:variable name="diff_X" select=" number($Join_X)- number(@X)"/><xsl:variable name="diff_Y" select=" number($Join_Y)- number(@Y)"/>
-                                <xsl:variable name="bp:Path_Point" select="."/>
-                                 
-                                    <xsl:choose>
-                                        <xsl:when test="(abs($diff_X)&lt;0.0001 and abs($diff_X)&lt;0.0001) or ( @X=$Join_X and @Y=$Join_Y )">
-                                            <found_in_path_in_edge_joins_filled_path>
-                                                <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
-                                                <xsl:attribute name="position" select="position()"/>
-                                                <!--<bp:Path_Point_var><xsl:copy-of select="$bp:Path_Point"/></bp:Path_Point_var>-->
-                                                <xsl:copy-of select="."/>
+            <xsl:variable name="ID_Join" select="@id"/>
+            <!--<xsl:variable name="pos" select=" position()"/>--> <!-- tozsamosc ulozenia z waysow -->
+            <xsl:variable name="ID_Point_count"/>  
+            <xsl:for-each select="Points">
+                <xsl:message>#41 Calculating Cable for point:<xsl:value-of select=" text()"/>; ID_Join:<xsl:value-of select="$ID_Join"/></xsl:message>
+                    <xsl:variable name="ID_Point" select=" text()"/>
+                    <xsl:variable name="edge_joins_filled_paths_xml" select="doc(concat($edge_joins_filled_paths,'/edge_joins_filled_paths.',$ID_Way,'.xml'))"/>
+                        <!-- do ustalenia gdize sa najblizsze bp:Path_Point_Cable ID_Join="45" -> Target_ID_Join  --> 
+                        <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'))"/>
+                         <!-- nie tzeba - jest w foreach dla Points !- trzeba sprawdzic czy join jest klientem - czy tylko PE! -->
+                        <xsl:choose>
+                        <!--<xsl:when test="not(@ID_Point)">
+                              <not_candidate><xsl:attribute name="descr" select="'this is probably join from way'"/>
+                                  <xsl:attribute name="Joins" select="@id"/></not_candidate>
+                          </xsl:when>-->
+                            <xsl:when test="$PE_candidates_dump/PE_candidates_dump/LINESTRING/bp:Path_Point[@ID_Join=$ID_Join]">
+                                <not_candidate_is_pe><xsl:attribute name="descr" select="'this is PE '"/>
+                                    <xsl:attribute name="Joins" select="$ID_Join"/>
+                                    <xsl:copy-of select="$PE_candidates_dump/PE_candidates_dump/LINESTRING/bp:Path_Point[@ID_Join=$ID_Join]"/>
+                                </not_candidate_is_pe>
+                            </xsl:when>
+                        <xsl:otherwise>
+                            <cable_to_PE_to_be_calculated>
+                                <xsl:attribute name="ID_Way" select="$ID_Way"/>
+                                <xsl:attribute name="Joins" select="$ID_Join"/>
+                                <xsl:attribute name="ID_Point" select="$ID_Point"/>
+                                 <!-- idziemy po drodze,  -->
+                                <xsl:variable name="Join_X" select="$joins_asText_Path_Point/joins_asText_xml/item[@id=$ID_Join]/bp:Path_Point/@X"/>
+                                <xsl:variable name="Join_Y" select="$joins_asText_Path_Point/joins_asText_xml/item[@id=$ID_Join]/bp:Path_Point/@Y"/>
+                                
+                                <xsl:attribute name="Join_X" select="$Join_X"/><xsl:attribute name="Join_Y" select="$Join_Y"/>
+                                            <!--<xsl:variable name="found_in_path_in_edge_joins_filled_path">
+                                                <xsl:for-each select="$edge_joins_filled_paths_xml/edge_joins_filled_paths_xml/asText_XMl[@id=$ID_Way]/LineString">
+                                                    <xsl:variable name="diff_X" select=" number($Join_X)- number(@X)"/><xsl:variable name="diff_Y" select=" number($Join_Y)- number(@Y)"/>
+                                                    <xsl:variable name="bp:Path_Point" select="."/>
+                                                        <xsl:choose>
+                                                            <xsl:when test="(abs($diff_X)&lt;0.0001 and abs($diff_X)&lt;0.0001) or ( @X=$Join_X and @Y=$Join_Y )">
+                                                                <found_in_path_in_edge_joins_filled_path>
+                                                                    <xsl:variable name="Join_Y" select="$joins_asText_Path_Point/joins_asText_xml/item[@id=$Joins]/bp:Path_Point/@Y"/>
+                                                                    <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
+                                                                    <xsl:attribute name="position" select="position()"/>
+                                                                    <!-\-<bp:Path_Point_var><xsl:copy-of select="$bp:Path_Point"/></bp:Path_Point_var>-\->
+                                                                    <xsl:copy-of select="."/>
+                                                                    <xsl:call-template name="detect_next_PE">
+                                                                        <xsl:with-param name="bp:Path_Point" select="$bp:Path_Point"/>
+                                                                        <xsl:with-param name="ID_Way" select="$ID_Way"/>
+                                                                        <xsl:with-param name="Pos_found" select="position()"/>
+                                                                        <xsl:with-param name="edge_joins_filled_paths" select="$edge_joins_filled_paths_xml"/>
+                                                                        <xsl:with-param name="ID_Point" select="$ID_Point"/>
+                                                                    </xsl:call-template>
+                                                                </found_in_path_in_edge_joins_filled_path>
+                                                            </xsl:when>
+                                                            <xsl:otherwise>
+                                                                <not_found>
+                                                                    <xsl:attribute name="Pos" select="position()"/>
+                                                                    <xsl:attribute name="X" select="@X"/><xsl:attribute name="Y" select="@Y"/>
+                                                                    <xsl:attribute name="srch_X" select="$Join_X"/><xsl:attribute name="srch_Y" select="$Join_Y"/>
+                                                                    <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
+                                                                </not_found>
+                                                            </xsl:otherwise>
+                                                        </xsl:choose>
+                                                </xsl:for-each>
+                                            </xsl:variable>-->
+                                            <!--<xsl:choose>
+                                    <xsl:when test="$found_in_path_in_edge_joins_filled_path/found_in_path_in_edge_joins_filled_path">
+                                        <xsl:for-each select="$found_in_path_in_edge_joins_filled_path/found_in_path_in_edge_joins_filled_path[1]">
+                                            <xsl:sort select="count(detect_next_PE/bp:Path_Point)" order="descending"/>
+                                            <debug>
+                                                <xsl:attribute name="debug_pos" select="position()"/>
+                                                <xsl:attribute name="Path_Point_count" select="count(detect_next_PE/bp:Path_Point)"/>
+                                            </debug>
+                                            <!-\-<found_in_path_in_edge_joins_filled_path>
+                                                <xsl:attribute name="debug_pos" select="position()"/>
+                                                <xsl:copy-of select="@*"/>
                                                 <xsl:call-template name="detect_next_PE">
-                                                    <xsl:with-param name="bp:Path_Point" select="$bp:Path_Point"/>
+                                                    <xsl:with-param name="bp:Path_Point" select="bp:Path_Point_var"/>
                                                     <xsl:with-param name="ID_Way" select="$ID_Way"/>
-                                                    <xsl:with-param name="Pos_found" select="position()"/>
+                                                    <xsl:with-param name="Pos_found" select="@position"/>
                                                     <xsl:with-param name="edge_joins_filled_paths" select="$edge_joins_filled_paths"/>
                                                     <xsl:with-param name="ID_Point" select="$ID_Point"/>
                                                 </xsl:call-template>
-                                            </found_in_path_in_edge_joins_filled_path>
-                                        </xsl:when>
-                                        <xsl:otherwise>
-                                            <not_found>
-                                                <xsl:attribute name="Pos" select="position()"/>
-                                                <xsl:attribute name="X" select="@X"/><xsl:attribute name="Y" select="@Y"/>
-                                                <xsl:attribute name="srch_X" select="$Join_X"/><xsl:attribute name="srch_Y" select="$Join_Y"/>
-                                                <xsl:attribute name="diff_X" select="$diff_X"/><xsl:attribute name="diff_Y" select="$diff_Y"/>
-                                            </not_found>
-                                        </xsl:otherwise>
-                                    </xsl:choose>
-                            </xsl:for-each>
-                        </xsl:variable>
-                        <xsl:choose>
-                            <xsl:when test="$found_in_path_in_edge_joins_filled_path/found_in_path_in_edge_joins_filled_path">
-                                <xsl:for-each select="$found_in_path_in_edge_joins_filled_path/found_in_path_in_edge_joins_filled_path[1]">
-                                    <xsl:sort select="count(detect_next_PE/bp:Path_Point)" order="descending"/>
-                                    <debug>
-                                        <xsl:attribute name="debug_pos" select="position()"/>
-                                        <xsl:attribute name="Path_Point_count" select="count(detect_next_PE/bp:Path_Point)"/>
-                                    </debug>
-                                    <!--<found_in_path_in_edge_joins_filled_path>
-                                        <xsl:attribute name="debug_pos" select="position()"/>
-                                        <xsl:copy-of select="@*"/>
-                                        <xsl:call-template name="detect_next_PE">
-                                            <xsl:with-param name="bp:Path_Point" select="bp:Path_Point_var"/>
-                                            <xsl:with-param name="ID_Way" select="$ID_Way"/>
-                                            <xsl:with-param name="Pos_found" select="@position"/>
-                                            <xsl:with-param name="edge_joins_filled_paths" select="$edge_joins_filled_paths"/>
-                                            <xsl:with-param name="ID_Point" select="$ID_Point"/>
-                                        </xsl:call-template>
-                                    </found_in_path_in_edge_joins_filled_path>-->
-                                    <xsl:copy-of select="."/>
-                                </xsl:for-each>
-                                <xsl:copy-of select="$found_in_path_in_edge_joins_filled_path/not_found"/>
-                            </xsl:when>
-                            <xsl:otherwise>
-                                <xsl:copy-of select="$found_in_path_in_edge_joins_filled_path"/>
-                            </xsl:otherwise>
-                        </xsl:choose>
-                    </cable_to_PE_to_be_calculated>
-                </xsl:when>
-            </xsl:choose>
+                                            </found_in_path_in_edge_joins_filled_path>-\->
+                                            <xsl:copy-of select="."/>
+                                        </xsl:for-each>
+                                        <xsl:copy-of select="$found_in_path_in_edge_joins_filled_path/not_found"/>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                        <xsl:copy-of select="$found_in_path_in_edge_joins_filled_path"/>
+                                    </xsl:otherwise>
+                                </xsl:choose>-->
+                                <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" />
+                                <xsl:choose>
+                                    <xsl:when test="$id_path">
+                                        <found_in_path_in_edge_joins_filled_path>
+                                            <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]">
+                                                <xsl:call-template name="detect_next_PE_adv">
+                                                    <xsl:with-param name="ID_Point" select="$ID_Point"/>
+                                                    <xsl:with-param name="id_path" select="@id_path"/>
+                                                    <xsl:with-param name="ID_Join" select="$ID_Join"/>
+                                                    <xsl:with-param name="ID_Way" select="$ID_Way"/>
+                                                    <xsl:with-param name="edge_joins_filled_paths_xml" select="$edge_joins_filled_paths_xml"/>
+                                                </xsl:call-template>
+                                            </xsl:for-each>
+                                        </found_in_path_in_edge_joins_filled_path>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                        <error>Not found $path
+                                            <xsl:message>Not found $path</xsl:message>
+                                        </error>
+                                    </xsl:otherwise>
+                                </xsl:choose>
+                                
+                            </cable_to_PE_to_be_calculated>
+                        </xsl:otherwise>
+                </xsl:choose>
+            </xsl:for-each>
         </xsl:for-each>
         </cables_from_joins_to_PE>
     </xsl:template>
     
+    
+    <xsl:template name="detect_next_PE_adv">
+        <xsl:param name="ID_Point" required="yes"/>
+        <xsl:param name="id_path" required="yes"/>
+        <xsl:param name="ID_Join" required="yes"/>
+        <xsl:param name="ID_Way" required="yes"/>
+        <xsl:param name="edge_joins_filled_paths_xml" required="yes"/>
+        
+        <detect_next_PE>
+            <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)]/@id_path)"/>
+            <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)]/@id_path)"/>
+            <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)]/@id_path)"/>
+            <xsl:attribute name="id_path" select="$id_path"/>
+            <xsl:attribute name="Next_PE_Pos" select="$Next_PE_Pos"/>
+            <xsl:attribute name="Prev_PE_Pos" select="$Prev_PE_Pos"/>
+            <xsl:attribute name="Same_PE_Pos" select="$Same_PE_Pos"/>
+            <xsl:variable name="Next_PE_Pos_len">
+                <xsl:choose>
+                    <xsl:when test="$Next_PE_Pos">
+                        <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)"/>
+                    </xsl:when><xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
+                </xsl:choose>
+            </xsl:variable>
+            <xsl:variable name="Prev_PE_Pos_len">
+                <xsl:choose>
+                    <xsl:when test="$Prev_PE_Pos">
+                        <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)"/>
+                    </xsl:when>
+                    <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
+                </xsl:choose>
+            </xsl:variable>
+            
+            <xsl:attribute name="Next_PE_Pos_len" select="$Next_PE_Pos_len"/>
+            <xsl:attribute name="Prev_PE_Pos_len" select="$Prev_PE_Pos_len"/>
+            <!--<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"/>-->
+                <xsl:variable name="Path_Point">
+                    <Path_Point>
+                    <xsl:choose>
+                        <xsl:when test="$Same_PE_Pos">
+                            <xsl:attribute name="len" select="0"/>
+                            <xsl:attribute name="debug" select="'going same'"/>
+                            <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>
+                            <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"/>
+                        </xsl:when>
+                        <xsl:when test="$Prev_PE_Pos_len = '-1' or $Next_PE_Pos_len &lt;= $Prev_PE_Pos_len ">
+                            <xsl:attribute name="debug" select="'going next'"/>
+                            <xsl:attribute name="len" select="$Next_PE_Pos_len"/>
+                            <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"/>
+                            <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>
+                            <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)  ]">
+                                <xsl:copy-of select="."/>
+                            </xsl:for-each>
+                        </xsl:when>
+                        <xsl:otherwise>
+                            <xsl:attribute name="len" select="$Prev_PE_Pos_len"/>
+                            <xsl:attribute name="debug" select="'going prev'"/>
+                            <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"/>
+                            <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>
+                            <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($Next_PE_Pos)  ]">
+                                <xsl:sort select="number(@id_path)" order="descending"/>
+                                <xsl:copy-of select="."/>
+                            </xsl:for-each>
+                        </xsl:otherwise>
+                    </xsl:choose>
+                    </Path_Point>
+                </xsl:variable>
+            <xsl:copy-of select="$Path_Point/Path_Point/@*"/>
+            <!--<debug_To_LINESTRING>
+                <xsl:copy-of select="$Path_Point"/>
+            </debug_To_LINESTRING>-->
+            <xsl:call-template name="To_LINESTRING">
+                <xsl:with-param name="Path_Point" select="$Path_Point/Path_Point"/>
+            </xsl:call-template>
+        </detect_next_PE>
+    </xsl:template>
+    
+    
+    
+    
+    
+    
         <!-- na podstawie Joins jade do PE raz z przodudrugi raz z tylu -->
-       <xsl:template name="detect_next_PE">
+       <!--<xsl:template name="detect_next_PE">
            <xsl:param name="bp:Path_Point" required="yes"/>
            <xsl:param name="Pos_found" required="yes"/>
            <xsl:param name="ID_Way" required="yes"/>
            <xsl:param name="edge_joins_filled_paths" required="yes"/>
            <xsl:param name="ID_Point" required="yes"/>
-           <!--<w_gore><xsl:attribute name="Pos_found" select="$Pos_found"/>
+           <!-\-<w_gore><xsl:attribute name="Pos_found" select="$Pos_found"/>
                <xsl:for-each select="$edge_joins_filled_paths/edge_joins_filled_paths/item[@id=$ID_Way]/bp:Path_Point">
                     
                 </xsl:for-each>
-            </w_gore>-->
-           
+            </w_gore>-\->
            <xsl:variable name="Next_PE_Pos" select="min($PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@Pos)&gt;number($Pos_found)]/@Pos)"/>
            <xsl:variable name="Prev_PE_Pos" select="max($PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@Pos)&lt;=number($Pos_found)]/@Pos)"/>
            <xsl:variable name="Same_PE_Pos" select="max($PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@Pos)=number($Pos_found)]/@Pos)"/>
            <detect_next_PE>
                <xsl:attribute name="Pos_found" select="$Pos_found"/>
-               <!--debug-->
-               <xsl:copy-of select="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@Pos)&gt;number($Pos_found)]/@Pos"/> <!--[number(@Pos)&gt;number($Pos_found)]-->
+               <!-\-debug-\->
+               <xsl:copy-of select="$PE_candidates_dump/PE_candidates_dump/LINESTRING[@ID_Way=$ID_Way]/bp:Path_Point[number(@Pos)&gt;number($Pos_found)]/@Pos"/> <!-\-[number(@Pos)&gt;number($Pos_found)]-\->
                <xsl:attribute name="Next_PE_Pos" select="$Next_PE_Pos"/>
                <xsl:attribute name="Prev_PE_Pos" select="$Prev_PE_Pos"/>
                <xsl:choose>
@@ -179,7 +294,7 @@
                </xsl:choose>
            </detect_next_PE>
            
-       </xsl:template>
+       </xsl:template>-->
     
     
     
@@ -187,71 +302,71 @@
             <xsl:param name="Path_Point" required="yes"/>
             <LINESTRING>
                 <xsl:value-of select="'LINESTRING ('"/>
-            <xsl:for-each select="$Path_Point/bp:Path_Point">
-                <xsl:value-of select="concat(@X,' ',@Y)"/>
-                <xsl:if test="position()!=last()"><xsl:value-of select="', '"/></xsl:if>
-            </xsl:for-each>
+                <xsl:for-each select="$Path_Point/(bp:Path_Point|LineString)">
+                    <xsl:value-of select="concat(@X,' ',@Y)"/>
+                    <xsl:if test="position()!=last()"><xsl:value-of select="', '"/></xsl:if>
+                </xsl:for-each>
                 <xsl:value-of select="')'"/>
             </LINESTRING>
         </xsl:template>
-    
+    <!--
         <xsl:template match="edge_joins_filled_paths" mode="edge_joins_filled_paths">
             <edge_joins_filled_paths>
                 <xsl:apply-templates mode="edge_joins_filled_paths"/>
             </edge_joins_filled_paths>
         </xsl:template>
     
-    <xsl:template match="item" mode="edge_joins_filled_paths">
-        <item>
-            <xsl:copy-of select="@*"/>
-            <xsl:copy-of select="tried"/>
-                <xsl:variable name="Path_Point">
-                <xsl:apply-templates/>
-                </xsl:variable>
-            <xsl:copy-of select="$Path_Point/tried"/>
-            <xsl:for-each select="$Path_Point/bp:Path_Point">
-                <bp:Path_Point>
-                    <xsl:attribute name="Pos" select="position()"/>
-                    <xsl:copy-of select="@*"/>
-                </bp:Path_Point>
-            </xsl:for-each>
-        </item>
-    </xsl:template>
-    
-    <xsl:template match="joins_asText" mode="joins_asText">
-        <joins_asText>
-            <xsl:apply-templates mode="joins_asText"/>
-        </joins_asText>
-    </xsl:template>
+        <xsl:template match="item" mode="edge_joins_filled_paths">
+            <item>
+                <xsl:copy-of select="@*"/>
+                <xsl:copy-of select="tried"/>
+                    <xsl:variable name="Path_Point">
+                    <xsl:apply-templates/>
+                    </xsl:variable>
+                <xsl:copy-of select="$Path_Point/tried"/>
+                <xsl:for-each select="$Path_Point/bp:Path_Point">
+                    <bp:Path_Point>
+                        <xsl:attribute name="Pos" select="position()"/>
+                        <xsl:copy-of select="@*"/>
+                    </bp:Path_Point>
+                </xsl:for-each>
+            </item>
+        </xsl:template>
     
-    <xsl:template match="item" mode="joins_asText">
-        <item>
-            <xsl:copy-of select="@*"/>
-            <xsl:call-template name="As_POINT_to_xml">
-                <xsl:with-param name="As_POINT" select="text()"/>
-            </xsl:call-template>
-        </item>
-    </xsl:template>
+        <xsl:template match="joins_asText" mode="joins_asText">
+            <joins_asText>
+                <xsl:apply-templates mode="joins_asText"/>
+            </joins_asText>
+        </xsl:template>
     
-    <!-- todo do wypchniecia do funkcji ogolnych -->
-    <xsl:template name="As_POINT_to_xml">
-        <xsl:param name="As_POINT"/>
-        <xsl:variable name="As_POINT_tok" select=" substring-before( substring-after(normalize-space(.),'POINT (') , ')')  "/>
-        <!--<test1><xsl:copy-of select="$LINESTRING"/></test1>-->
-        <xsl:variable name="As_POINT_pos">
-            <xsl:for-each select="tokenize($As_POINT_tok,' ')">
-                    <pos>
-                        <xsl:attribute name="pos" select="position()"/>
-                        <xsl:value-of select="."/>
-                    </pos>
-                </xsl:for-each>
-        </xsl:variable>
-        <As_POINT_to_xml>
-            <xsl:attribute name="X" select="$As_POINT_pos/pos[@pos=1]"/>
-            <xsl:attribute name="Y" select="$As_POINT_pos/pos[@pos=2]"/>
-        </As_POINT_to_xml>
-    </xsl:template>
-    <xsl:template match="*"/>
+        <xsl:template match="item" mode="joins_asText">
+            <item>
+                <xsl:copy-of select="@*"/>
+                <xsl:call-template name="As_POINT_to_xml">
+                    <xsl:with-param name="As_POINT" select="text()"/>
+                </xsl:call-template>
+            </item>
+        </xsl:template>
+    -->
+        <!-- todo do wypchniecia do funkcji ogolnych -->
+        <<!--xsl:template name="As_POINT_to_xml">
+            <xsl:param name="As_POINT"/>
+            <xsl:variable name="As_POINT_tok" select=" substring-before( substring-after(normalize-space(.),'POINT (') , ')')  "/>
+            <!-\-<test1><xsl:copy-of select="$LINESTRING"/></test1>-\->
+            <xsl:variable name="As_POINT_pos">
+                <xsl:for-each select="tokenize($As_POINT_tok,' ')">
+                        <pos>
+                            <xsl:attribute name="pos" select="position()"/>
+                            <xsl:value-of select="."/>
+                        </pos>
+                    </xsl:for-each>
+            </xsl:variable>
+            <As_POINT_to_xml>
+                <xsl:attribute name="X" select="$As_POINT_pos/pos[@pos=1]"/>
+                <xsl:attribute name="Y" select="$As_POINT_pos/pos[@pos=2]"/>
+            </As_POINT_to_xml>
+        </xsl:template>-->
+        <xsl:template match="*"/>
     
     
 </xsl:stylesheet>