pgRouting

Changeset 172

Show
Ignore:
Timestamp:
05/26/08 16:43:04 (6 months ago)
Author:
anton
Message:

Output templates introduced

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/routingservice/src/jp/co/orkney/restlet/geo/ClosestEdge.java

    r167 r172  
    118118                 
    119119                String reqId = configuration.getService().getParameter("request_id").getValue(); 
     120         
     121                StringTemplate template = this.configuration.getFormatOut().getTemplate(); 
     122         
     123                result = this.ioHelper.fillMultilinestringTemplate(rs, this.configuration.getFormatOut().getName(), 
     124                        template, reqId);                
    120125 
     126                /* 
    121127                // Converts the SQL Result in Geojson 
    122128                if (configuration.getFormatOut().getName().equals("geojson")) 
     
    155161                        result = this.ioHelper.closestEdgeKMLResult(rs); 
    156162                } 
     163                */ 
    157164 
    158165                /* 
  • branches/routingservice/src/jp/co/orkney/restlet/geo/ShortestPath.java

    r167 r172  
    173173        String reqId = configuration.getService().getParameter("request_id") 
    174174                .getValue(); 
    175  
     175         
     176        StringTemplate template = this.configuration.getFormatOut().getTemplate(); 
     177         
     178        result = this.ioHelper.fillMultilinestringTemplate(rs, this.configuration.getFormatOut().getName(), 
     179                template, reqId); 
     180         
     181        /* 
     182         
    176183        // Converts the SQL Result in Geojson 
    177184        if (this.configuration.getFormatOut().getName().equals("geojson")) 
     
    205212            result = this.ioHelper.shortestPathKMLResult(rs); 
    206213        } 
     214        */ 
    207215 
    208216    } 
  • branches/routingservice/src/jp/co/orkney/restlet/geo/TravelingSalesPerson.java

    r128 r172  
    142142 
    143143                String reqId = configuration.getService().getParameter("request_id").getValue(); 
     144         
     145                StringTemplate template = this.configuration.getFormatOut().getTemplate(); 
     146         
     147                result = this.ioHelper.fillMultilinestringTemplate(rs, this.configuration.getFormatOut().getName(), 
     148                        template, reqId); 
    144149                 
     150                /* 
    145151                // Converts the SQL Result in Geojson 
    146152                if (configuration.getFormatOut().getName().equals("geojson")) 
     
    173179                        result = ioHelper.travelingSalesPersonKMLResult(rs); 
    174180                } 
     181                */ 
    175182        } 
    176183 
  • branches/routingservice/src/jp/co/orkney/restlet/util/Configuration.java

    r170 r172  
    261261 
    262262                } 
    263  
     263                 
    264264                List<Element> listParameters = currentService.getChild( 
    265265                        "parameters").getChildren("parameter"); 
     
    269269                while (itParametre.hasNext()) 
    270270                { 
    271                     Parameter parameter = new Parameter(); 
    272271                    Element currentParameter = itParametre.next(); 
     272                    /* 
    273273                    parameter.setName(currentParameter 
    274274                            .getAttributeValue("name")); 
     
    283283                    parameter.setValue(currentParameter 
    284284                            .getAttributeValue("default")); 
     285                     */ 
     286                    Parameter parameter = new Parameter(currentParameter);           
    285287                    parameters.add(parameter); 
    286288                } 
     289                 
    287290                service.setParameters(parameters); 
    288  
     291                 
     292 
     293                 
    289294                List<Element> listFormat = currentService.getChild("formats") 
    290295                        .getChildren("format"); 
     
    294299                while (itFormat.hasNext()) 
    295300                { 
    296                     Format format = new Format(); 
    297301                    Element currentFormat = itFormat.next(); 
     302                    /* 
    298303                    format.setName(currentFormat.getAttributeValue("name")); 
    299304                    format.setSrid(currentFormat.getAttributeValue("srid")); 
     
    302307                    format.setEnableOutput(new Boolean(currentFormat 
    303308                            .getAttributeValue("output"))); 
     309                    format.setTemplate(currentFormat.getAttributeValue("template")); 
     310                    */ 
     311                    Format format = new Format(currentFormat); 
    304312                    formats.add(format); 
    305313                } 
    306  
     314                                 
    307315                if (service.getName().equals("security")) 
    308316                    provider.setAuthService(service); 
     
    368376        if ((iFormat = isInput(urlSplit[2])) != -1) 
    369377        { 
     378            /* 
    370379            Format tmpFormat = providers.get(iProvider).getServices().get( 
    371380                    iService).getFormats().get(iFormat); 
    372381            formatIn = new Format(tmpFormat.getName(), tmpFormat.getSrid(), 
    373382                    tmpFormat.isEnableInput(), tmpFormat.isEnableOutput()); 
     383                */ 
     384            formatIn = providers.get(iProvider).getServices().get( 
     385                    iService).getFormats().get(iFormat); 
    374386        } 
    375387        else 
     
    378390        if ((iFormat = isOutput(urlSplit[3].split("\\.")[1].split("\\?")[0])) != -1) 
    379391        { 
     392            /* 
    380393            Format tmpFormat = providers.get(iProvider).getServices().get( 
    381394                    iService).getFormats().get(iFormat); 
     
    387400                        .setValue(formatOut.getSrid()); 
    388401            } 
     402            */ 
     403            formatOut = providers.get(iProvider).getServices().get( 
     404                    iService).getFormats().get(iFormat); 
    389405        } 
    390406        else 
  • branches/routingservice/src/jp/co/orkney/restlet/util/Format.java

    r164 r172  
    11package jp.co.orkney.restlet.util; 
     2 
     3import org.antlr.stringtemplate.StringTemplate; 
     4import org.antlr.stringtemplate.StringTemplateGroup; 
     5import org.jdom.Element; 
    26 
    37/** 
     
    4044        private boolean enableInput; 
    4145        private boolean enableOutput; 
     46        private StringTemplate template; 
    4247 
    4348        /** 
     
    8186        } 
    8287 
     88        public Format(String name, String srid, boolean enableInput, boolean enableOutput, String template) 
     89        { 
     90            this.name = name; 
     91            this.srid = srid; 
     92            this.enableInput = enableInput; 
     93            this.enableOutput = enableOutput; 
     94 
     95            StringTemplateGroup group = new StringTemplateGroup("formatGroup", "templates"); 
     96            this.template = group.getInstanceOf(template); 
     97        } 
     98         
     99        public Format(Element format) 
     100        { 
     101            this.name = format.getAttributeValue("name"); 
     102            this.srid = format.getAttributeValue("srid"); 
     103            this.enableInput = new Boolean(format.getAttributeValue("input")); 
     104            this.enableOutput = new Boolean(format.getAttributeValue("output")); 
     105 
     106            try 
     107            { 
     108                StringTemplateGroup group = new StringTemplateGroup("formatGroup", "templates"); 
     109                this.template = group.getInstanceOf(format.getAttributeValue("template")); 
     110            } 
     111            catch (NullPointerException e) 
     112            { 
     113                //Format has no template. 
     114                //Do nothing 
     115            } 
     116 
     117        }        
     118 
    83119        /** 
    84120         * Gets the name of the format 
     
    170206                this.enableOutput = enableOutput; 
    171207        } 
     208         
     209        public StringTemplate getTemplate() 
     210        { 
     211            return template; 
     212        }        
    172213} 
  • branches/routingservice/src/jp/co/orkney/restlet/util/IOHelper.java

    r164 r172  
    2626import java.sql.ResultSet; 
    2727import java.sql.SQLException; 
     28import java.util.ArrayList; 
    2829 
    2930import org.antlr.stringtemplate.StringTemplate; 
     31import org.antlr.stringtemplate.StringTemplateGroup; 
    3032import org.json.JSONArray; 
    3133import org.json.JSONException; 
     
    311313 
    312314        /** 
    313          * Draws the result of the closest Edge algorithm in XML format 
    314          *  
    315          * @param resultSet 
    316          *            result of the SQL query 
    317          * @return result this query's result in XML format 
    318          * @throws SQLException 
    319          *             Error to extract data from ResultSet object 
    320          */ 
    321         public String closestEdgeXMLResult(ResultSet resultSet, String reqId) throws SQLException 
    322         { 
    323                 String result = ""; 
    324                 result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"; 
    325                 result += "<edge>\n"; 
    326                 if (resultSet != null && resultSet.next()) 
    327                 { 
    328                         result += "\t<gid>" + resultSet.getInt("gid") + "</gid>\n"; 
    329                         result += "\t<name>name_edge</name>\n"; 
    330  
    331                         String wkt = resultSet.getString("wkt"); 
    332                         wkt = wkt.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    333                         result += "\t<wkt>" + wkt + "</wkt>\n"; 
    334                 } 
    335                 else 
    336                 { 
    337                         result += "\t<gid>0</gid>\n"; 
    338                         result += "\t<name>unkown_edge</name>\n"; 
    339                 } 
    340                 result += "\t<requestid>"+reqId+"</requestid>\n"; 
    341                 result += "</edge>\n"; 
    342                  
    343                 return result; 
    344         } 
    345  
    346         /** 
    347          * Returns only the closest edge's Id 
    348          *  
    349          * @param resultSet 
    350          *            result of the SQL query 
    351          * @return the closest edge's Id 
    352          * @throws SQLException 
    353          *             Error to extract data from ResultSet object 
    354          */ 
    355         public String closestEdgeIDResult(ResultSet resultSet) throws SQLException 
    356         { 
    357                 String result = ""; 
    358                 if (resultSet != null && resultSet.next()) 
    359                 { 
    360                         result = Integer.toString(resultSet.getInt("gid")); 
    361                 } 
    362                 else 
    363                 { 
    364                         result = "0"; 
    365                 } 
    366                 return result; 
    367         } 
    368  
    369         /** 
    370          * Draws the result of the closest Edge algorithm in GML format 
    371          *  
    372          * @param resultSet 
    373          *            result of the SQL query 
    374          * @return result this query's result in GML format 
    375          * @throws SQLException 
    376          *             Error to extract data from ResultSet object 
    377          */ 
    378         public String closestEdgeGMLResult(ResultSet resultSet, String reqId) throws SQLException 
    379         { 
    380                 String result = "<wfs:FeatureCollection xmlns:wfs=\"http://www.opengis.net/wfs\">" 
    381                                 + "<gml:featureMember xmlns:gml=\"http://www.opengis.net/gml\">" 
    382                                 + "<feature:features xmlns:feature=\"http://mapserver.gis.umn.edu/mapserver\"><feature:geometry><gml:MultiLineString>"; 
    383                 if (resultSet != null && resultSet.next()) 
    384                 { 
    385                         String tmpSplit = resultSet.getString("wkt"); 
    386                         tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    387                         String wkt[] = tmpSplit.split("\\)\\("); 
    388                         for (int i = 0; i < wkt.length; i++) 
    389                         { 
    390                                 result += "<gml:lineStringMember>" + "<gml:LineString>" + "<gml:coordinates decimal=\".\" cs=\",\" ts=\"+\">"; 
    391                                 String wkt2[] = wkt[i].split(","); 
    392                                 for (int j = 0; j < wkt2.length; j++) 
    393                                 { 
    394                                         result += new BigDecimal(wkt2[j].split(" ")[0]) + "," + new BigDecimal(wkt2[j].split(" ")[1]) + " "; 
    395                                 } 
    396                                 result += "</gml:coordinates>" + "</gml:LineString>" + "</gml:lineStringMember>"; 
    397                         } 
    398                 } 
    399                 result += "</gml:MultiLineString></feature:geometry></feature:features>" + "</gml:featureMember></wfs:FeatureCollection>"; 
    400                 return result; 
    401         } 
    402  
    403         /** 
    404          * Draws the result of the closest Edge algorithm in WKT format 
    405          *  
    406          * @param resultSet 
    407          *            result of the SQL query 
    408          * @return result this query's result in WKT format 
    409          * @throws SQLException 
    410          *             Error to extract data from ResultSet object 
    411          */ 
    412         public String closestEdgeWKTResult(ResultSet resultSet) throws SQLException 
    413         { 
    414                 String result = ""; 
    415                 if (resultSet != null && resultSet.next()) 
    416                 { 
    417                         result = resultSet.getString("wkt"); 
    418                 } 
    419                 else 
    420                 { 
    421                         result = ""; 
    422                 } 
    423                 return result; 
    424         } 
    425  
    426         /** 
    427          * Draws the result of the closest Edge algorithm in KML format 
    428          *  
    429          * @param resultSet 
    430          *            result of the SQL query 
    431          * @return result this query's result in KML format 
    432          * @throws SQLException 
    433          *             Error to extract data from ResultSet object 
    434          */ 
    435         public String closestEdgeKMLResult(ResultSet resultSet) throws SQLException 
    436         { 
    437                 String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<kml xmlns=\"http://earth.google.com/kml/2.1\">" 
    438                                 + "<Document><name>WebRouting Service</name><Style id=\"LineStyle\"><LineStyle>" 
    439                                 + "<color>7f00ff00</color><width>4</width></LineStyle></Style>" + "<Placemark>" 
    440                                 + "<description>No+description+available</description>" + "<name>Closest Edge</name><styleUrl>#LineStyle</styleUrl><MultiGeometry>"; 
    441  
    442                 if (resultSet != null && resultSet.next()) 
    443                 { 
    444                         String tmpSplit = resultSet.getString("wkt"); 
    445                         tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    446                         String wkt[] = tmpSplit.split("\\)\\("); 
    447                         for (int i = 0; i < wkt.length; i++) 
    448                         { 
    449                                 result += "<LineString>" + "<coordinates>"; 
    450                                 String wkt2[] = wkt[i].split(","); 
    451                                 for (int j = 0; j < wkt2.length; j++) 
    452                                 { 
    453                                         result += new BigDecimal(wkt2[j].split(" ")[0]) + "," + new BigDecimal(wkt2[j].split(" ")[1]) + ",0 "; 
    454                                 } 
    455                                 result += "</coordinates>" + "</LineString>"; 
    456                         } 
    457                 } 
    458                 result += "</MultiGeometry></Placemark></Document></kml>"; 
    459                 return result; 
    460         } 
    461  
    462         /** 
    463          * Draws the result of the shortest path algorithm in HTML format 
    464          *  
    465          * @param resultSet 
    466          *            result of the SQL query 
    467          * @param startPoint 
    468          *            start point 
    469          * @param endPoint 
    470          *            end point 
    471          * @return result this query's result in HTML format 
    472          * @throws SQLException 
    473          *             Error to extract data from ResultSet object 
    474          */ 
    475         public String shortestPathHTMLResult(ResultSet resultSet, Point startPoint, Point endPoint, String reqId) throws SQLException 
    476         { 
    477                 int i = 0; 
    478                 String result = "<html><head>" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + configuration.getCss() + "\" />" 
    479                                 + "</head><body><table class=\"table\"><tr>"; 
    480  
    481                 result += "<td colspan=\"3\">The road between the point(" + startPoint.getX() + ";" + startPoint.getY() + ") and the point(" 
    482                                 + endPoint.getX() + ";" + endPoint.getY() + ")  is: </td></tr>"; 
    483                 while (resultSet != null && resultSet.next()) 
    484                 { 
    485                         result += "<tr class=\"line\"><td rowspan=\"2\" class=\"case_id\">" + i + "</td><td>Gid:</td><td>" + +resultSet.getInt("gid") 
    486                                         + "</td></tr>"; 
    487                         result += "<tr class=\"line\"><td>Geom:</td><td class=\"case_desc\">" + resultSet.getString("wkt") + "</td></tr>"; 
    488                         i++; 
    489                 } 
    490                 if (resultSet == null) 
    491                 { 
    492                         result += "<tr class=\"line\"><td rowspan=\"2\" class=\"case_id\">" + i + "</td><td>Gid:</td><td>0</td></tr>"; 
    493                         result += "<tr class=\"line\"><td>Geom:</td><td class=\"case_desc\">unkown_road</td></tr>"; 
    494                 } 
    495                 result += "<tr class=\"line\"><td>Request ID:</td><td>"+reqId+"</td></tr>"; 
    496                 result += "</body></html>"; 
    497                 return result; 
    498         } 
    499  
    500         /** 
    501          * Draws the result of the shortest path algorithm in Geojson format 
     315         * Draws the result of the driving distance algorithm in Geojson format 
    502316         *  
    503317         * @param resultSet 
     
    509323         *             Error to make Geojson object 
    510324         */ 
    511         public String shortestPathGEOJSONResult(ResultSet resultSet, String reqId) throws SQLException, JSONException 
    512         { 
    513                 String result = ""; 
    514                 JSONObject joRes = new JSONObject(); 
    515                 JSONObject joCrs = new JSONObject(); 
    516                 JSONObject joPro2 = new JSONObject(); 
    517                 JSONArray joFea2 = new JSONArray(); 
    518  
    519                 joRes.put("type", "FeatureCollection"); 
    520                 int k = 0; 
    521                 while (resultSet != null && resultSet.next()) 
    522                 { 
    523                         JSONObject joFea = new JSONObject(); 
    524                         JSONObject joPro = new JSONObject(); 
    525                         JSONArray joCor = new JSONArray(); 
    526                         JSONObject joGeo = new JSONObject(); 
    527  
    528                         joFea.put("properties", joPro); 
    529                         joGeo.put("type", "MultiLineString"); 
    530                         String tmpSplit = resultSet.getString("wkt"); 
    531                         tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    532                         String wkt[] = tmpSplit.split("\\)\\("); 
    533                         for (int i = 0; i < wkt.length; i++) 
    534                         { 
    535                                 JSONArray tmp = new JSONArray(); 
    536                                 String wkt2[] = wkt[i].split(","); 
    537  
    538                                 for (int j = 0; j < wkt2.length; j++) 
    539                                 { 
    540                                         JSONArray tmp2 = new JSONArray(); 
    541                                         tmp2.put(new BigDecimal(wkt2[j].split(" ")[0])); 
    542                                         tmp2.put(new BigDecimal(wkt2[j].split(" ")[1])); 
    543                                         tmp.put(tmp2); 
    544                                 } 
    545                                 joCor.put(tmp); 
    546                         } 
    547  
    548                         joGeo.put("coordinates", joCor); 
    549                         joFea.put("geometry", joGeo); 
    550                         joFea.put("id", "id" + k); 
    551                         k++; 
    552                         joFea.put("type", "Feature"); 
    553                         joFea2.put(joFea); 
    554                 } 
    555                 joRes.put("features", joFea2); 
    556  
    557                 joCrs.put("type", "EPSG"); 
    558                 joPro2.put("code", "900913"); 
    559                 joCrs.put("properties", joPro2); 
    560                 joRes.put("crs", joCrs); 
    561                  
    562                 joRes.put("requestId", reqId); 
    563  
    564                 result = joRes.toString(); 
    565                 return result; 
    566         } 
    567  
    568         /** 
    569          * Draws the result of the shortest path algorithm in XML format 
    570          *  
    571          * @param resultSet 
    572          *            result of the SQL query 
    573          * @return result this query's result in XML format 
    574          * @throws SQLException 
    575          *             Error to extract data from ResultSet object 
    576          */ 
    577         public String shortestPathXMLResult(ResultSet resultSet, String reqId) throws SQLException 
    578         { 
    579                 String result = ""; 
    580                 int i = 0; 
    581                 result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"; 
    582                 result += "<route>\n"; 
    583                 while (resultSet != null && resultSet.next()) 
    584                 { 
    585                         result += "<edge id=\"" + i + "\">\n"; 
    586                         result += "\t<gid>" + resultSet.getInt("gid") + "</gid>\n"; 
    587                         result += "\t<name>" + null + "</name>\n"; 
    588                          
    589                         //TODO Get data type from the service configuration 
    590                         String wkt = resultSet.getString("wkt"); 
    591                         wkt = wkt.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    592                         result += "\t<wkt>" + wkt + "</wkt>\n"; 
    593                         result += "</edge>\n"; 
    594                         i++; 
    595                 } 
    596                 result += "<requestid>"+reqId+"</requestid>\n"; 
    597                 result += "</route>\n"; 
    598  
    599                 return result; 
    600         } 
    601  
    602         /** 
    603          * Draws the result of the shortest path algorithm in GML format 
    604          *  
    605          * @param resultSet 
    606          *            result of the SQL query 
    607          * @return result this query's result in GML format 
    608          * @throws SQLException 
    609          *             Error to extract data from ResultSet object 
    610          */ 
    611         public String shortestPathGMLResult(ResultSet resultSet, String reqId) throws SQLException 
    612         { 
    613                 String result = "<wfs:FeatureCollection xmlns:wfs=\"http://www.opengis.net/wfs\">"; 
    614                 int k = 0; 
    615  
    616                 while (resultSet != null && resultSet.next()) 
    617                 { 
    618                         result += "<gml:featureMember xmlns:gml=\"http://www.opengis.net/gml\">" 
    619                                         + "<feature:features xmlns:feature=\"http://mapserver.gis.umn.edu/mapserver\" " + "fid=\"id" + k + "\">" + "<feature:geometry>" 
    620                                         + "<gml:MultiLineString>"; 
    621  
    622                         String tmpSplit = resultSet.getString("wkt"); 
    623                         tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    624                         String wkt[] = tmpSplit.split("\\)\\("); 
    625                         for (int i = 0; i < wkt.length; i++) 
    626                         { 
    627                                 result += "<gml:lineStringMember>" + "<gml:LineString>" + "<gml:coordinates decimal=\".\" cs=\",\" ts=\"+\">"; 
    628                                 String wkt2[] = wkt[i].split(","); 
    629                                 for (int j = 0; j < wkt2.length; j++) 
    630                                 { 
    631                                         result += new BigDecimal(wkt2[j].split(" ")[0]) + "," + new BigDecimal(wkt2[j].split(" ")[1]) + " "; 
    632                                 } 
    633                                 result += "</gml:coordinates>" + "</gml:LineString>" + "</gml:lineStringMember>"; 
    634                         } 
    635                         k++; 
    636                         result += "</gml:MultiLineString>" + "</feature:geometry></feature:features>" + "</gml:featureMember>"; 
    637                 } 
    638                 result += "</wfs:FeatureCollection>"; 
    639  
    640                 return result; 
    641         } 
    642  
    643         /** 
    644          * Draws the result of the shortest path algorithm in WKT format 
    645          *  
    646          * @param resultSet 
    647          *            result of the SQL query 
    648          * @return result this query's result in WKT format 
    649          * @throws SQLException 
    650          *             Error to extract data from ResultSet object 
    651          */ 
    652         public String shortestPathWKTResult(ResultSet resultSet) throws SQLException 
    653         { 
    654                 double length = 0; 
    655                 String result = "MULTILINESTRING("; 
    656  
    657                 while (resultSet != null && resultSet.next()) 
    658                 { 
    659                          
    660                         String tmpSplit = resultSet.getString("wkt"); 
    661                         tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    662                         result += "(" + tmpSplit + "),"; 
    663                 } 
    664                 result += result.substring(0, result.length() - 1) + ")"; 
    665                 return result; 
    666         } 
    667          
    668         /** 
    669          * Draws the result of the shortest path algorithm in WKT format 
    670          *  
    671          * @param resultSet 
    672          *            result of the SQL query 
    673          * @return result this query's result in WKT format 
    674          * @throws SQLException 
    675          *             Error to extract data from ResultSet object 
    676          */ 
    677         public String shortestPathLengthResult(ResultSet resultSet) throws SQLException 
    678         { 
    679                 String result = "MULTILINESTRING("; 
    680  
    681                 while (resultSet != null && resultSet.next()) 
    682                 { 
    683                         String tmpSplit = resultSet.getString("wkt"); 
    684                         tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    685                         result += "(" + tmpSplit + "),"; 
    686                 } 
    687                 result += result.substring(0, result.length() - 1) + ")"; 
    688                 return result; 
    689         }        
    690  
    691         /** 
    692          * Draws the result of the shortest path algorithm in KML format 
    693          *  
    694          * @param resultSet 
    695          *            result of the SQL query 
    696          * @return result this query's result in KML format 
    697          * @throws SQLException 
    698          *             Error to extract data from ResultSet object 
    699          */ 
    700         public String shortestPathKMLResult(ResultSet resultSet) throws SQLException 
    701         { 
    702                 String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<kml xmlns=\"http://earth.google.com/kml/2.1\">" 
    703                                 + "<Document><name>WebRouting Service</name><Style id=\"LineStyle\"><LineStyle>" 
    704                                 + "<color>7f0000ff</color><width>4</width></LineStyle></Style>" + "<Placemark>" 
    705                                 + "<description>No+description+available</description>" + "<name>Shortest Path</name><styleUrl>#LineStyle</styleUrl><MultiGeometry>"; 
    706  
    707                 while (resultSet != null && resultSet.next()) 
    708                 { 
    709  
    710                         String tmpSplit = resultSet.getString("wkt"); 
    711                         tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    712                         String wkt[] = tmpSplit.split("\\)\\("); 
    713                         for (int i = 0; i < wkt.length; i++) 
    714                         { 
    715                                 result += "<LineString>" + "<coordinates>"; 
    716                                 String wkt2[] = wkt[i].split(","); 
    717                                 for (int j = 0; j < wkt2.length; j++) 
    718                                 { 
    719                                         result += new BigDecimal(wkt2[j].split(" ")[0]) + "," + new BigDecimal(wkt2[j].split(" ")[1]) + ",0 "; 
    720                                 } 
    721                                 result += "</coordinates>" + "</LineString>"; 
    722  
    723                         } 
    724                 } 
    725                 result += "</MultiGeometry></Placemark></Document></kml>"; 
    726                 return result; 
    727         } 
    728  
    729         /** 
    730          * Draws the result of the driving distance algorithm in Geojson format 
    731          *  
    732          * @param resultSet 
    733          *            result of the SQL query 
    734          * @return result this query's result in Geojson format 
    735          * @throws SQLException 
    736          *             Error to extract data from ResultSet object * 
    737          * @throws JSONException 
    738          *             Error to make Geojson object 
    739          */ 
    740325        public String drivingDistanceGEOJSONResult(ResultSet resultSet, String reqId) throws SQLException, JSONException 
    741326        { 
     
    947532 
    948533         
    949         public String travelingSalesPersonHTMLResult(ResultSet resultSet, Point point, String reqId) throws SQLException 
    950         { 
    951                 int i = 0; 
    952                 String result = "<html><head>" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + configuration.getCss() + "\" />" 
    953                                 + "</head><body><table class=\"table\"><tr>"; 
    954  
    955                 result += "<td colspan=\"3\">The travel sale person result is: </td></tr>"; 
    956                 while (resultSet != null && resultSet.next()) 
    957                 { 
    958                         result += "<tr class=\"line\"><td rowspan=\"2\" class=\"case_id\">" + i + "</td><td>Gid:</td><td>" + +resultSet.getInt("gid") 
    959                                         + "</td></tr>"; 
    960                         result += "<tr class=\"line\"><td>Geom:</td><td class=\"case_desc\">" + resultSet.getString("wkt") + "</td></tr>"; 
    961                         i++; 
    962                 } 
    963                 if (resultSet == null) 
    964                 { 
    965                         result += "<tr class=\"line\"><td rowspan=\"2\" class=\"case_id\">" + i + "</td><td>Gid:</td><td>0</td></tr>"; 
    966                         result += "<tr class=\"line\"><td>Geom:</td><td class=\"case_desc\">unkown_road</td></tr>"; 
    967                 } 
    968                 result += "</body></html>"; 
    969                 return result; 
    970         } 
    971          
    972         public String travelingSalesPersonXMLResult(ResultSet resultSet, String reqId) throws SQLException 
    973         { 
    974                 String result = ""; 
    975                 int i = 0; 
    976                 result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"; 
    977                 result += "<route>\n"; 
    978                 while (resultSet != null && resultSet.next()) 
    979                 { 
    980                         result += "<edge id=\"" + i + "\">\n"; 
    981                         result += "\t<gid>" + resultSet.getInt("gid") + "</gid>\n"; 
    982                         result += "\t<name>" + null + "</name>\n"; 
    983  
    984                         String wkt = resultSet.getString("wkt"); 
    985                         wkt = wkt.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    986                         result += "\t<wkt>" + wkt + "</wkt>\n"; 
    987                         result += "</edge>\n"; 
    988                         i++; 
    989                 } 
    990                 result += "<requestid>"+reqId+"</requestid>\n"; 
    991                 result += "</route>\n"; 
    992  
    993                 return result; 
    994         } 
    995          
    996         public String travelingSalesPersonGEOJSONResult(ResultSet resultSet, String reqId) throws SQLException, JSONException 
    997         { 
    998                 String result = ""; 
    999                 JSONObject joRes = new JSONObject(); 
    1000                 JSONObject joCrs = new JSONObject(); 
    1001                 JSONObject joPro2 = new JSONObject(); 
    1002                 JSONArray joFea2 = new JSONArray(); 
    1003  
    1004                 joRes.put("type", "FeatureCollection"); 
    1005                 int k = 0; 
    1006                 while (resultSet != null && resultSet.next()) 
    1007                 { 
    1008                         JSONObject joFea = new JSONObject(); 
    1009                         JSONObject joPro = new JSONObject(); 
    1010                         JSONArray joCor = new JSONArray(); 
    1011                         JSONObject joGeo = new JSONObject(); 
    1012  
    1013                         joFea.put("properties", joPro); 
    1014                         joGeo.put("type", "MultiLineString"); 
    1015                         String tmpSplit = resultSet.getString("wkt"); 
    1016                         tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    1017                         String wkt[] = tmpSplit.split("\\)\\("); 
    1018                         for (int i = 0; i < wkt.length; i++) 
    1019                         { 
    1020                                 JSONArray tmp = new JSONArray(); 
    1021                                 String wkt2[] = wkt[i].split(","); 
    1022  
    1023                                 for (int j = 0; j < wkt2.length; j++) 
    1024                                 { 
    1025                                         JSONArray tmp2 = new JSONArray(); 
    1026                                         tmp2.put(new BigDecimal(wkt2[j].split(" ")[0])); 
    1027                                         tmp2.put(new BigDecimal(wkt2[j].split(" ")[1])); 
    1028                                         tmp.put(tmp2); 
    1029                                 } 
    1030                                 joCor.put(tmp); 
    1031                         } 
    1032  
    1033                         joGeo.put("coordinates", joCor); 
    1034                         joFea.put("geometry", joGeo); 
    1035                         joFea.put("id", "id" + k); 
    1036                         k++; 
    1037                         joFea.put("type", "Feature"); 
    1038                         joFea2.put(joFea); 
    1039                 } 
    1040                 joRes.put("features", joFea2); 
    1041  
    1042                 joCrs.put("type", "EPSG"); 
    1043                 joPro2.put("code", configuration.getService().getDataProjection()); 
    1044                 joCrs.put("properties", joPro2); 
    1045                 joRes.put("crs", joCrs); 
    1046                  
    1047                 joRes.put("requestId", reqId); 
    1048  
    1049                 result = joRes.toString(); 
    1050                 return result; 
    1051         } 
    1052          
    1053         public String travelingSalesPersonGMLResult(ResultSet resultSet, String reqId) throws SQLException 
    1054         { 
    1055                 String result = "<wfs:FeatureCollection xmlns:wfs=\"http://www.opengis.net/wfs\">"; 
    1056                 int k = 0; 
    1057  
    1058                 while (resultSet != null && resultSet.next()) 
    1059                 { 
    1060                         result += "<gml:featureMember xmlns:gml=\"http://www.opengis.net/gml\">" 
    1061                                         + "<feature:features xmlns:feature=\"http://mapserver.gis.umn.edu/mapserver\" " + "fid=\"id" + k + "\">" + "<feature:geometry>" 
    1062                                         + "<gml:MultiLineString>"; 
    1063  
    1064                         String tmpSplit = resultSet.getString("wkt"); 
    1065                         tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 
    1066                         String wkt[] = tmpSplit.split("\\)\\("); 
    1067                         for (int i = 0; i < wkt.length; i++) 
    1068                         { 
    1069                                 result += "<gml:lineStringMember>" + "<gml:LineString>" + "<gml:coordinates decimal=\".\" cs=\",\" ts=\"+\">"; 
    1070