| 197 | | * Draws the result of the closest Edge algorithm in HTML format |
| 198 | | * |
| 199 | | * @param resultSet |
| 200 | | * result of the SQL query |
| 201 | | * @param point |
| 202 | | * the point provided input data |
| 203 | | * @return result this query's result in HTML format |
| 204 | | * @throws SQLException |
| 205 | | * Error to extract data from ResultSet object |
| 206 | | */ |
| 207 | | public String closestEdgeHTMLResult(ResultSet resultSet, Point point, String reqId) throws SQLException |
| 208 | | { |
| 209 | | String result = "<html><head>" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + configuration.getCss() + "\" />" |
| 210 | | + "</head><body><table class=\"table\"><tr>"; |
| 211 | | result += "<td colspan=\"2\">From the point (" + point.getX() + ";" + point.getY() + "), the closest edge is: </td></tr>"; |
| 212 | | if (resultSet != null && resultSet.next()) |
| 213 | | { |
| 214 | | result += "<tr class=\"line\"><td>Gid:</td><td>" + resultSet.getInt("gid") + "</td></tr>"; |
| 215 | | result += "<tr class=\"line\"><td>Name:</td><td>name_edge</td></tr>"; |
| 216 | | result += "<tr class=\"line\"><td>Source:</td><td>" + resultSet.getInt("source") + "</td></tr>"; |
| 217 | | result += "<tr class=\"line\"><td>Target:</td><td>" + resultSet.getInt("target") + "</td></tr>"; |
| 218 | | result += "<tr class=\"line\"><td>Geom:</td><td>" + resultSet.getString("wkt") + "</td></tr>"; |
| 219 | | } |
| 220 | | else |
| 221 | | { |
| 222 | | result += "<tr class=\"line\"><td>Gid:</td><td>0</td></tr>"; |
| 223 | | result += "<tr class=\"line\"><td>Name:</td><td>unkown_edge</td></tr>"; |
| 224 | | result += "<tr class=\"line\"><td>Source:</td><td>0</td></tr>"; |
| 225 | | result += "<tr class=\"line\"><td>Target:</td><td>0</td></tr>"; |
| 226 | | result += "<tr class=\"line\"><td>Geom:</td><td></td></tr>"; |
| 227 | | result += "<tr class=\"line\"><td>Distance:</td><td>0</td></tr>"; |
| 228 | | } |
| 229 | | result += "<tr class=\"line\"><td>Request ID:</td><td>"+reqId+"</td></tr>"; |
| 230 | | result += "</body></html>"; |
| 231 | | return result; |
| 232 | | } |
| 233 | | |
| 234 | | /** |
| 235 | | * Draws the result of the closest Edge algorithm in Geojson format |
| 236 | | * |
| 237 | | * @param resultSet |
| 238 | | * result of the SQL query |
| 239 | | * @return result this query's result in Geojson format |
| 240 | | * @throws SQLException |
| 241 | | * Error to extract data from ResultSet object |
| 242 | | * @throws JSONException |
| 243 | | * Error to make Geojson object |
| 244 | | */ |
| 245 | | public String closestEdgeGEOJSONResult(ResultSet resultSet, String reqId) throws SQLException, JSONException |
| 246 | | { |
| 247 | | String result = ""; |
| 248 | | JSONObject joRes = new JSONObject(); |
| 249 | | JSONObject joGeo = new JSONObject(); |
| 250 | | JSONObject joPro = new JSONObject(); |
| 251 | | JSONObject joCrs = new JSONObject(); |
| 252 | | JSONObject joPro2 = new JSONObject(); |
| 253 | | JSONArray joCor = new JSONArray(); |
| 254 | | |
| 255 | | if (resultSet != null && resultSet.next()) |
| 256 | | { |
| 257 | | joRes.put("type", "Feature"); |
| 258 | | |
| 259 | | joPro.put("gid", resultSet.getInt("gid")); |
| 260 | | joPro.put("name", "name_edge"); |
| 261 | | joRes.put("properties", joPro); |
| 262 | | |
| 263 | | joGeo.put("type", "MultiLineString"); |
| 264 | | String tmpSplit = resultSet.getString("wkt"); |
| 265 | | tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; |
| 266 | | String wkt[] = tmpSplit.split("\\)\\("); |
| 267 | | for (int i = 0; i < wkt.length; i++) |
| 268 | | { |
| 269 | | JSONArray tmp = new JSONArray(); |
| 270 | | String wkt2[] = wkt[i].split(","); |
| 271 | | |
| 272 | | for (int j = 0; j < wkt2.length; j++) |
| 273 | | { |
| 274 | | JSONArray tmp2 = new JSONArray(); |
| 275 | | tmp2.put(new BigDecimal(wkt2[j].split(" ")[0])); |
| 276 | | tmp2.put(new BigDecimal(wkt2[j].split(" ")[1])); |
| 277 | | tmp.put(tmp2); |
| 278 | | } |
| 279 | | joCor.put(tmp); |
| 280 | | } |
| 281 | | |
| 282 | | joGeo.put("coordinates", joCor); |
| 283 | | joRes.put("geometry", joGeo); |
| 284 | | |
| 285 | | joCrs.put("type", "EPSG"); |
| 286 | | joPro2.put("code", "900913"); |
| 287 | | joCrs.put("properties", joPro2); |
| 288 | | joRes.put("crs", joCrs); |
| 289 | | } |
| 290 | | else |
| 291 | | { |
| 292 | | joRes.put("type", "Feature"); |
| 293 | | |
| 294 | | joPro.put("gid", 0); |
| 295 | | joPro.put("name", "unkown_edge"); |
| 296 | | joRes.put("properties", joPro); |
| 297 | | |
| 298 | | joGeo.put("type", "MultiLineString"); |
| 299 | | JSONArray tmp = new JSONArray(); |
| 300 | | joCor.put(tmp); |
| 301 | | joGeo.put("coordinates", joCor); |
| 302 | | joRes.put("geometry", joGeo); |
| 303 | | |
| 304 | | joCrs.put("type", "EPSG"); |
| 305 | | joPro2.put("code", "900913"); |
| 306 | | joCrs.put("properties", joPro2); |
| 307 | | joRes.put("crs", joCrs); |
| 308 | | } |
| 309 | | joRes.put("requestId", reqId); |
| 310 | | result = joRes.toString(); |
| 311 | | return result; |
| 312 | | } |
| 313 | | |
| 314 | | /** |
| 531 | | } |
| 532 | | |
| 533 | | |
| 534 | | /** |
| 535 | | * <p> |
| 536 | | * Returns the "OpenLayers id" provided by OpenLayers interface. "OpenLayers |
| 537 | | * id" is required to use WebRouting Service with OpenLayers interface. |
| 538 | | * <br /> |
| 539 | | * Requirement: Geojson data |
| 540 | | * </p> |
| 541 | | * |
| 542 | | * @param data |
| 543 | | * data provided by the GET or POST request |
| 544 | | * @return if not null, returns OpenLayers id, otherwise 0 |
| 545 | | */ |
| 546 | | public String getOpenLayersIdFromGEOJSON(String data) |
| 547 | | { |
| 548 | | String openLayersId = "0"; |
| 549 | | try |
| 550 | | { |
| 551 | | JSONObject lePoint = new JsonRepresentation(data).toJsonObject(); |
| 552 | | openLayersId = (String) lePoint.getString("id"); |
| 553 | | } |
| 554 | | catch (JSONException e) |
| 555 | | { |
| 556 | | log.write("*ERROR* getOpenLayersIdFromGEOJSON()", 0); |
| 557 | | } |
| 558 | | |
| 559 | | return openLayersId; |
| 560 | | } |
| 561 | | |
| 562 | | /** |
| 563 | | * <p> |
| 564 | | * Returns the "OpenLayers id" provided by OpenLayers interface. "OpenLayers |
| 565 | | * id" is required to use WebRouting Service with OpenLayers interface. |
| 566 | | * <br /> |
| 567 | | * Requirement: GML data |
| 568 | | * </p> |
| 569 | | * |
| 570 | | * @param data |
| 571 | | * data provided by the GET or POST request |
| 572 | | * @return if not null, returns OpenLayers id, otherwise 0 |
| 573 | | */ |
| 574 | | public String getOpenLayersIdFromGML(String data) |
| 575 | | { |
| 576 | | String openLayersId = "0"; |
| 577 | | try |
| 578 | | { |
| 579 | | openLayersId = data.split("fid=\"")[1].split("\"><")[0]; |
| 580 | | } |
| 581 | | catch (Exception e) |
| 582 | | { |
| 583 | | log.write("*ERROR* getOpenLayersIdFromGML()", 0); |
| 584 | | } |
| 585 | | |
| 586 | | return openLayersId; |
| 587 | | } |
| 588 | | |
| 589 | | /** |
| 590 | | * <p> |
| 591 | | * Returns the "OpenLayers id" provided by OpenLayers interface. "OpenLayers |
| 592 | | * id" is required to use WebRouting Service with OpenLayers interface. |
| 593 | | * <br /> |
| 594 | | * Requirement: KML data |
| 595 | | * </p> |
| 596 | | * |
| 597 | | * @param data |
| 598 | | * data provided by the GET or POST request |
| 599 | | * @return if not null, returns OpenLayers id, otherwise 0 |
| 600 | | */ |
| 601 | | public String getOpenLayersIdFromKML(String data) |
| 602 | | { |
| 603 | | String openLayersId = ""; |
| 604 | | try |
| 605 | | { |
| 606 | | openLayersId = data.split("<Placemark><name>")[1].split("</name>")[0]; |
| 607 | | } |
| 608 | | catch (Exception e) |
| 609 | | { |
| 610 | | log.write("*ERROR* getOpenLayersIdFromKML()", 0); |
| 611 | | } |
| 612 | | |
| 613 | | return openLayersId; |