Changeset 199
- Timestamp:
- 07/30/08 15:22:35 (4 months ago)
- Files:
-
- tools/routingservice/trunk/configuration.xml (modified) (27 diffs)
- tools/routingservice/trunk/configuration.xsd (modified) (1 diff)
- tools/routingservice/trunk/src/jp/co/orkney/restlet/geo/ShortestPath.java (modified) (5 diffs)
- tools/routingservice/trunk/src/jp/co/orkney/restlet/util/DatabaseConnection.java (modified) (3 diffs)
- tools/routingservice/trunk/src/jp/co/orkney/restlet/WebRouting.java (modified) (1 diff)
- tools/routingservice/trunk/templates/multilinestring_kml.st (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tools/routingservice/trunk/configuration.xml
r195 r199 7 7 8 8 <providers> 9 9 10 <!--GEOBASE--> 10 11 <provider name="geobase" title="Geobase"> 11 <description> </description>12 <description>no description</description> 12 13 <services> 13 14 <service name="closest_edge" title="Closest Edge" enable="true"> 14 <description> </description>15 <description>no description</description> 15 16 <connection driver="org.postgresql.Driver"> 16 17 <url>jdbc:postgresql://192.168.20.177:5432/geobase</url> … … 45 46 46 47 <service name="shortest_path" title="Shortest Path" enable="true"> 47 <description> </description>48 <description>blabla</description> 48 49 <connection driver="org.postgresql.Driver"> 49 50 <url>jdbc:postgresql://192.168.20.177:5432/geobase</url> … … 51 52 <password></password> 52 53 </connection> 53 <projection srid="900913"></projection> 54 <projection srid="900913" units="meter" /> 55 <limit distance="5000.0" /> 54 56 <sql> 55 57 <query transformProjectionIn="false" transformProjectionOut="false">SELECT gid, AsText(the_geom) AS wkt FROM shootingstar_sp_smart('nrn_bc', $sonStartX$, $sonStartY$, $sonEndX$, $sonEndY$, $saBoxSize$,'length',true,true)</query> … … 67 69 </parameters> 68 70 <formats> 69 <format name="gml" input="true" output="true" />70 <format name="xml" input="false" output="true" />71 <format name="html" input="false" output="true" />72 <format name="geojson" input="true" output="true" />>73 <format name="lonlat" input="true" output="false" /> 74 <format name="wkt" input="true" output="true" />75 <format name="kml" input="true" output="true" srid="4326" />71 <format name="gml" input="true" output="true" template="multilinestring_gml" /> 72 <format name="xml" input="false" output="true" template="multilinestring_xml" /> 73 <format name="html" input="false" output="true" template="multilinestring_html" /> 74 <format name="geojson" input="true" output="true" template="multilinestring_geojson" /> 75 <format name="lonlat" input="true" output="false" /> 76 <format name="wkt" input="true" output="true" template="multilinestring_wkt" /> 77 <format name="kml" input="true" output="true" srid="4326" template="multilinestring_kml" /> 76 78 </formats> 77 79 </service> 78 80 79 81 <service name="driving_distance" title="Driving Distance" enable="true"> 80 <description> </description>82 <description>blabla</description> 81 83 <connection driver="org.postgresql.Driver"> 82 84 <url>jdbc:postgresql://192.168.20.177:5432/geobase</url> … … 94 96 <parameter name="point" type="text" codename="data" required="true" /> 95 97 <parameter name="time" type="integer" codename="time" required="false" /> 96 <parameter name="length" type="integer" codename=" distance" required="false" />98 <parameter name="length" type="integer" codename="length" required="false" /> 97 99 <parameter name="speed" type="integer" codename="speed" required="false" default="80" /> 98 100 <parameter name="sridInput" type="integer" codename="sridIn" required="false" /> … … 113 115 114 116 <service name="traveling_sales_person" title="Traveling Sales Person" enable="true"> 115 <description> </description>117 <description>blabla</description> 116 118 <connection driver="org.postgresql.Driver"> 117 119 <url>jdbc:postgresql://192.168.20.177:5432/geobase</url> … … 152 154 <!--IPC--> 153 155 <provider name="ipc" title="IPC"> 154 <description> </description>156 <description>blabla</description> 155 157 <services> 156 158 <service name="closest_edge" title="Closest Edge" enable="true"> … … 188 190 189 191 <service name="shortest_path" title="Shortest Path" enable="true"> 190 <description> </description>192 <description>blabla</description> 191 193 <connection driver="org.postgresql.Driver"> 192 194 <url>jdbc:postgresql://192.168.20.177:5432/ipc</url> … … 222 224 223 225 <service name="driving_distance" title="Driving Distance" enable="true"> 224 <description> </description>226 <description>blabla</description> 225 227 <connection driver="org.postgresql.Driver"> 226 228 <url>jdbc:postgresql://192.168.20.177:5432/ipc</url> … … 238 240 <parameter name="point" type="text" codename="data" required="true" /> 239 241 <parameter name="time" type="integer" codename="time" required="false" /> 240 <parameter name="length" type="integer" codename=" distance" required="false" />242 <parameter name="length" type="integer" codename="length" required="false" /> 241 243 <parameter name="speed" type="integer" codename="speed" required="false" default="80" /> 242 244 <parameter name="sridInput" type="integer" codename="sridIn" required="false" /> … … 279 281 280 282 281 <!--SUUCHI-->283 <!--SUUCHI--> 282 284 <provider name="suuchi" title="Suuchi"> 283 <description> </description>285 <description>no description</description> 284 286 <services> 285 287 <service name="closest_edge" title="Closest Edge" enable="true"> … … 317 319 318 320 <service name="shortest_path" title="Shortest Path" enable="true"> 319 <description> </description>321 <description>blabla</description> 320 322 <connection driver="org.postgresql.Driver"> 321 323 <url>jdbc:postgresql://192.168.20.177:5432/suuchi</url> … … 323 325 <password></password> 324 326 </connection> 325 <projection srid=" 54004"></projection>327 <projection srid="4612"></projection> 326 328 <sql> 327 329 <query transformProjectionIn="false" transformProjectionOut="false">SELECT gid, AsText(the_geom) AS wkt FROM shootingstar_sp_smart('kanagawa', $sonStartX$, $sonStartY$, $sonEndX$, $sonEndY$, $saBoxSize$,'length',true,true)</query> … … 350 352 351 353 <service name="driving_distance" title="Driving Distance" enable="true"> 352 <description> </description>354 <description>blabla</description> 353 355 <connection driver="org.postgresql.Driver"> 354 356 <url>jdbc:postgresql://192.168.20.177:5432/suuchi</url> … … 366 368 <parameter name="point" type="text" codename="data" required="true" /> 367 369 <parameter name="time" type="integer" codename="time" required="false" /> 368 <parameter name="length" type="integer" codename=" distance" required="false" />370 <parameter name="length" type="integer" codename="length" required="false" /> 369 371 <parameter name="speed" type="integer" codename="speed" required="false" default="80" /> 370 372 <parameter name="sridInput" type="integer" codename="sridIn" required="false" /> … … 388 390 <!--PGROUTING--> 389 391 <provider name="pgrouting" title="pgRouting"> 390 <description> </description>392 <description>no description</description> 391 393 <services> 392 394 <service name="closest_edge" title="Closest Edge" enable="true"> … … 424 426 425 427 <service name="shortest_path" title="Shortest Path" enable="true"> 426 <description> </description>428 <description>blabla</description> 427 429 <connection driver="org.postgresql.Driver"> 428 430 <url>jdbc:postgresql://192.168.20.177:5432/pgrouting</url> … … 457 459 458 460 <service name="driving_distance" title="Driving Distance" enable="true"> 459 <description> </description>461 <description>blabla</description> 460 462 <connection driver="org.postgresql.Driver"> 461 463 <url>jdbc:postgresql://192.168.20.177:5432/pgrouting</url> … … 473 475 <parameter name="point" type="text" codename="data" required="true" /> 474 476 <parameter name="time" type="integer" codename="time" required="false" /> 475 <parameter name="length" type="integer" codename=" distance" required="false" />477 <parameter name="length" type="integer" codename="length" required="false" /> 476 478 <parameter name="speed" type="integer" codename="speed" required="false" default="80" /> 477 479 <parameter name="sridInput" type="integer" codename="sridIn" required="false" /> … … 496 498 <!--HCC--> 497 499 <provider name="hcc" title="hcc"> 498 <description> </description>500 <description>no description</description> 499 501 <services> 500 502 <service name="closest_edge" title="Closest Edge" enable="true"> 501 <description>> </description>503 <description>>no description</description> 502 504 <connection driver="org.postgresql.Driver"> 503 505 <url>jdbc:postgresql://192.168.20.177:5432/hcc</url> … … 532 534 533 535 <service name="shortest_path" title="Shortest Path" enable="true"> 534 <description> </description>536 <description>blabla</description> 535 537 <connection driver="org.postgresql.Driver"> 536 538 <url>jdbc:postgresql://192.168.20.177:5432/hcc</url> … … 565 567 566 568 <service name="driving_distance" title="Driving Distance" enable="true"> 567 <description> </description>569 <description>blabla</description> 568 570 <connection driver="org.postgresql.Driver"> 569 571 <url>jdbc:postgresql://192.168.20.177:5432/hcc</url> … … 581 583 <parameter name="point" type="text" codename="data" required="true" /> 582 584 <parameter name="time" type="integer" codename="time" required="false" /> 583 <parameter name="length" type="integer" codename=" distance" required="false" />585 <parameter name="length" type="integer" codename="length" required="false" /> 584 586 <parameter name="speed" type="integer" codename="speed" required="false" default="80" /> 585 587 <parameter name="sridInput" type="integer" codename="sridIn" required="false" /> … … 600 602 </services> 601 603 </provider> 602 604 605 603 606 <!--SUUCHI2--> 604 607 <provider name="suuchi2" title="Suuchi2"> 605 <description> </description>608 <description>no description</description> 606 609 <services> 607 610 <service name="closest_edge" title="Closest Edge" enable="true"> 608 <description> </description>611 <description>>no description</description> 609 612 <connection driver="org.postgresql.Driver"> 610 613 <url>jdbc:postgresql://192.168.20.177:5432/suuchi</url> … … 639 642 640 643 <service name="shortest_path" title="Shortest Path" enable="true"> 641 <description> </description>644 <description>blabla</description> 642 645 <connection driver="org.postgresql.Driver"> 643 646 <url>jdbc:postgresql://192.168.20.177:5432/suuchi</url> … … 672 675 673 676 <service name="driving_distance" title="Driving Distance" enable="true"> 674 <description> </description>677 <description>blabla</description> 675 678 <connection driver="org.postgresql.Driver"> 676 679 <url>jdbc:postgresql://192.168.20.177:5432/suuchi</url> … … 688 691 <parameter name="point" type="text" codename="data" required="true" /> 689 692 <parameter name="time" type="integer" codename="time" required="false" /> 690 <parameter name="length" type="integer" codename=" distance" required="false" />693 <parameter name="length" type="integer" codename="length" required="false" /> 691 694 <parameter name="speed" type="integer" codename="speed" required="false" default="80" /> 692 695 <parameter name="sridInput" type="integer" codename="sridIn" required="false" /> tools/routingservice/trunk/configuration.xsd
r195 r199 111 111 <xs:attribute name="output" type="xs:boolean"/> 112 112 <xs:attribute name="srid" type="xs:integer"/> 113 <xs:attribute name="template" type="xs:string"/> 113 114 </xs:complexType> 114 115 </xs:element> tools/routingservice/trunk/src/jp/co/orkney/restlet/geo/ShortestPath.java
r172 r199 59 59 60 60 /** 61 * Constructor ShortestPath62 * <p>63 * Creates a new ShortestPath object using the specified Configuration64 * object and extracts X and Y from the data provides by GET or POST65 * request into a new point (for start and end point).66 * </p>67 *68 * @param configuration69 * the current configuration70 */61 * Constructor ShortestPath 62 * <p> 63 * Creates a new ShortestPath object using the specified Configuration 64 * object and extracts X and Y from the data provides by GET or POST 65 * request into a new point (for start and end point). 66 * </p> 67 * 68 * @param configuration 69 * the current configuration 70 */ 71 71 public ShortestPath(Configuration configuration, 72 72 DatabaseConnection databaseConnection, IOHelper ioHelper, Log log) … … 119 119 120 120 /** 121 * Gets the result of the shortest path algorithm122 *123 * @return this shortest path's result124 */121 * Gets the result of the shortest path algorithm 122 * 123 * @return this shortest path's result 124 */ 125 125 public String get() 126 126 { … … 129 129 130 130 /** 131 * Starts the "shortest path" algorithm132 *133 * @throws SQLException134 * error to send the query to the database135 * @throws JSONException136 * Error to transform the result in Geojson format137 */131 * Starts the "shortest path" algorithm 132 * 133 * @throws SQLException 134 * error to send the query to the database 135 * @throws JSONException 136 * Error to transform the result in Geojson format 137 */ 138 138 public void start() throws SQLException, JSONException 139 139 { … … 144 144 .getParameter("bbox").getValue()); 145 145 146 if (LimitsHelper.isDistanceAllowed(startPoint, endPoint, configuration 146 // We need to define the input projection and reproject the data. 147 // This place is not beautiful yet and needs to be reconsidered. 148 Point sPoint = startPoint; 149 Point ePoint = endPoint; 150 151 if (configuration.getService().getParameter("sridInput").getValue() != null) 152 { 153 sPoint = databaseConnection.transform(configuration.getService(), 154 startPoint, configuration.getService().getParameter( 155 "sridInput").getValue(), configuration.getService() 156 .getDataProjection()); 157 ePoint = databaseConnection.transform(configuration.getService(), 158 endPoint, configuration.getService().getParameter( 159 "sridInput").getValue(), configuration.getService() 160 .getDataProjection()); 161 } 162 163 if (LimitsHelper.isDistanceAllowed(sPoint, ePoint, configuration 147 164 .getService().getLimit().getDistance())) 148 165 { … … 166 183 .toString()); 167 184 168 } else 185 } 186 else 169 187 { 170 188 this.log.write("Distance exceedes limits", 1); 189 //There should be an exception in this case 190 return; 171 191 } 172 192 173 193 String reqId = configuration.getService().getParameter("request_id") 174 194 .getValue(); 175 176 StringTemplate template = this.configuration.getFormatOut().getTemplate(); 177 178 result = this.ioHelper.fillMultilinestringTemplate(rs, this.configuration.getFormatOut().getName(), 179 template, reqId); 180 195 196 StringTemplate template = this.configuration.getFormatOut() 197 .getTemplate(); 198 199 result = this.ioHelper.fillMultilinestringTemplate(rs, 200 this.configuration.getFormatOut().getName(), template, reqId); 201 181 202 /* 182 183 // Converts the SQL Result in Geojson 184 if (this.configuration.getFormatOut().getName().equals("geojson")) 185 { 186 result = this.ioHelper.shortestPathGEOJSONResult(rs, reqId); 187 } 188 // Converts the SQL Result in HTML 189 else if (this.configuration.getFormatOut().getName().equals("html")) 190 { 191 result = this.ioHelper.shortestPathHTMLResult(rs, startPoint, 192 endPoint, reqId); 193 } 194 // Converts the SQL Result in XML 195 else if (this.configuration.getFormatOut().getName().equals("xml")) 196 { 197 result = this.ioHelper.shortestPathXMLResult(rs, reqId); 198 } 199 // Converts the SQL Result in GML 200 else if (this.configuration.getFormatOut().getName().equals("gml")) 201 { 202 result = this.ioHelper.shortestPathGMLResult(rs, reqId); 203 } 204 // Converts the SQL Result in WKT 205 else if (this.configuration.getFormatOut().getName().equals("wkt")) 206 { 207 result = this.ioHelper.shortestPathWKTResult(rs); 208 } 209 // Converts the SQL Result in KML 210 else if (this.configuration.getFormatOut().getName().equals("kml")) 211 { 212 result = this.ioHelper.shortestPathKMLResult(rs); 213 } 214 */ 203 * // Converts the SQL Result in Geojson if 204 * (this.configuration.getFormatOut().getName().equals("geojson")) { 205 * result = this.ioHelper.shortestPathGEOJSONResult(rs, reqId); } // 206 * Converts the SQL Result in HTML else if 207 * (this.configuration.getFormatOut().getName().equals("html")) { result = 208 * this.ioHelper.shortestPathHTMLResult(rs, startPoint, endPoint, 209 * reqId); } // Converts the SQL Result in XML else if 210 * (this.configuration.getFormatOut().getName().equals("xml")) { result = 211 * this.ioHelper.shortestPathXMLResult(rs, reqId); } // Converts the SQL 212 * Result in GML else if 213 * (this.configuration.getFormatOut().getName().equals("gml")) { result = 214 * this.ioHelper.shortestPathGMLResult(rs, reqId); } // Converts the SQL 215 * Result in WKT else if 216 * (this.configuration.getFormatOut().getName().equals("wkt")) { result = 217 * this.ioHelper.shortestPathWKTResult(rs); } // Converts the SQL Result 218 * in KML else if 219 * (this.configuration.getFormatOut().getName().equals("kml")) { result = 220 * this.ioHelper.shortestPathKMLResult(rs); } 221 */ 215 222 216 223 } tools/routingservice/trunk/src/jp/co/orkney/restlet/util/DatabaseConnection.java
r164 r199 1 1 package jp.co.orkney.restlet.util; 2 3 2 4 3 /** … … 19 18 */ 20 19 21 22 20 import java.io.File; 21 import java.math.BigDecimal; 23 22 import java.sql.Connection; 24 23 import java.sql.ResultSet; … … 65 64 public class DatabaseConnection 66 65 { 67 private IOHelper ioHelper; 68 private Log log; 69 private DatabaseConfiguration databaseConfiguration; 70 private Configuration configuration; 66 private IOHelper ioHelper; 71 67 72 /** 73 * Constructor DatabaseConnection 74 * <p> 75 * Creates a new DatabaseConnection object with the specified Configuration 76 * object 77 * </p> 78 * 79 * @param configuration 80 * The current WebRouting Service's configuration 81 */ 82 public DatabaseConnection(Configuration configuration) 68 private Log log; 69 70 private DatabaseConfiguration databaseConfiguration; 71 72 private Configuration configuration; 73 74 /** 75 * Constructor DatabaseConnection 76 * <p> 77 * Creates a new DatabaseConnection object with the specified 78 * Configuration object 79 * </p> 80 * 81 * @param configuration 82 * The current WebRouting Service's configuration 83 */ 84 public DatabaseConnection(Configuration configuration) 85 { 86 this.configuration = configuration; 87 log = configuration.createLog(); 88 // databaseConfiguration = 89 // configuration.getService().getDatabaseConfiguration(); 90 ioHelper = new IOHelper(configuration); 91 } 92 93 /** 94 * Creates and sends the query using pool connection 95 * 96 * @param query 97 * theSQL query 98 * @return the result of the request 99 */ 100 public ResultSet getResult(Service service, String query) 101 { 102 StringTemplate queryTemplate = new StringTemplate(ioHelper 103 .loadFile(new File(configuration.getUrlXMLTemplateQuery()))); 104 105 databaseConfiguration = service.getDatabaseConfiguration(); 106 107 // Makes the SQL query 108 queryTemplate.setAttribute("user", databaseConfiguration.getUser()); 109 queryTemplate.setAttribute("password", databaseConfiguration 110 .getPassword()); 111 queryTemplate.setAttribute("query", query); 112 113 ResultSet result = null; 114 115 Client client = new Client(Protocol.JDBC); 116 JdbcClientHelper helper = new JdbcClientHelper(client); 117 try 83 118 { 84 this.configuration = configuration; 85 log = configuration.createLog(); 86 //databaseConfiguration = configuration.getService().getDatabaseConfiguration(); 87 ioHelper = new IOHelper(configuration); 119 Class.forName(databaseConfiguration.getDriver()); 88 120 } 121 catch (ClassNotFoundException e) 122 { 123 log.write("--ERROR: Can not find the driver", 0); 124 } 125 Representation req = new StringRepresentation(queryTemplate.toString() 126 .replace("&", "&"), MediaType.TEXT_XML); 127 Request request = JdbcClientHelper.create(databaseConfiguration 128 .getURL(), req); 129 Response response = new Response(request); 130 helper.handle(request, response); 89 131 132 WebRowSet rowSet = ((RowSetRepresentation) response.getEntity()) 133 .getWebRowSet(); 134 135 try 136 { 137 result = rowSet; 138 } 139 catch (Exception ex) 140 { 141 log 142 .write( 143 "--ERROR: Can not cast the result from WebRowSet to ResultSet", 144 0); 145 } 146 return result; 147 } 148 149 public void fillKeysTable(Service service, Hashtable keys) 150 throws SQLException 151 { 152 ResultSet rs = getResult(service, "SELECT client_id, key FROM keys"); 153 while (rs != null && rs.next()) 154 keys.put(rs.getString("client_id").toUpperCase(), rs 155 .getString("key")); 156 } 157 158 public Point transform(Service service, Point point, String sridIn, String sridOut) 159 throws SQLException 160 { 161 Point res = point; 162 163 double x = point.getX().doubleValue(); 164 double y = point.getY().doubleValue(); 90 165 91 /** 92 * Creates and sends the query using pool connection 93 * @param query theSQL query 94 * @return the result of the request 95 */ 96 public ResultSet getResult(Service service, String query) 97 { 98 StringTemplate queryTemplate = new StringTemplate(ioHelper.loadFile(new File(configuration.getUrlXMLTemplateQuery()))); 99 100 databaseConfiguration = service.getDatabaseConfiguration(); 166 String query = "select x(a.g), y(a.g) from (select transform(geometryfromtext('POINT(" 167 + x + " " + y + ")', " + sridIn + "), " + sridOut 168 + ") as g) as a"; 169 170 this.log.write(query, 2); 101 171 102 // Makes the SQL query 103 queryTemplate.setAttribute("user",databaseConfiguration.getUser()); 104 queryTemplate.setAttribute("password", databaseConfiguration.getPassword()); 105 queryTemplate.setAttribute("query", query); 106 107 ResultSet result = null; 108 109 Client client = new Client(Protocol.JDBC); 110 JdbcClientHelper helper = new JdbcClientHelper(client); 111 try 112 { 113 Class.forName(databaseConfiguration.getDriver()); 114 } 115 catch (ClassNotFoundException e) 116 { 117 log.write("--ERROR: Can not find the driver", 0); 118 } 119 Representation req = new StringRepresentation(queryTemplate.toString().replace("&", "&"),MediaType.TEXT_XML) ; 120 Request request = JdbcClientHelper.create(databaseConfiguration.getURL(),req); 121 Response response = new Response(request); 122 helper.handle(request, response); 123 124 WebRowSet rowSet = ((RowSetRepresentation)response.getEntity()).getWebRowSet(); 125 126 try { 127 result = rowSet; 128 } catch (Exception ex) { 129 log.write("--ERROR: Can not cast the result from WebRowSet to ResultSet", 0); 130 } 131 return result; 132 } 133 134 public void fillKeysTable(Service service, Hashtable keys) throws SQLException 135 { 136 ResultSet rs = getResult(service, "SELECT client_id, key FROM keys"); 137 while (rs != null && rs.next()) 138 keys.put(rs.getString("client_id").toUpperCase(), rs.getString("key")); 139 } 172 ResultSet rs = getResult(service, query); 173 174 while (rs != null && rs.next()) 175 res = new Point(BigDecimal.valueOf(rs.getDouble("x")), 176 BigDecimal.valueOf(rs.getDouble("y"))); 177 178 return res; 179 } 140 180 } tools/routingservice/trunk/src/jp/co/orkney/restlet/WebRouting.java
r167 r199 267 267 result = action.getResult(); 268 268 //log.write(action.getResult() + " finished", 1); 269 269 270 if(result=="") 271 { 272 response.setStatus(Status.CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE); 273 error = true; 274 } 270 275 // OUTPUT FORMAT --> 271 276 if (configuration.getFormatOut().getName().equals("html")) tools/routingservice/trunk/templates/multilinestring_kml.st
r171 r199 1 <?xml version=1.0 encoding=UTF-8?> 1 2 <kml> 2 3 <Document>

