Commit ea3359c76584dbe774d5b57577625c3e53f41df1
1 parent
6d293f6b
1.
Showing
3 changed files
with
112 additions
and
2 deletions
src/main/java/com/bsth/controller/LsStationRouteController.java
| @@ -201,4 +201,19 @@ public class LsStationRouteController extends BaseController<LsStationRoute, Int | @@ -201,4 +201,19 @@ public class LsStationRouteController extends BaseController<LsStationRoute, Int | ||
| 201 | 201 | ||
| 202 | return result; | 202 | return result; |
| 203 | } | 203 | } |
| 204 | + | ||
| 205 | + @RequestMapping(value = "/analyzeRoutes") | ||
| 206 | + public Map<String, Object> analyzeRoutes(Integer lineId, Integer version, Integer direction) { | ||
| 207 | + Map<String, Object> result = new HashMap<>(); | ||
| 208 | + try { | ||
| 209 | + result.putAll(lsStationRouteService.analyzeRoutes(lineId, version, direction)); | ||
| 210 | + result.put("status", ResponseCode.SUCCESS); | ||
| 211 | + } catch (Exception e) { | ||
| 212 | + result.put("status", ResponseCode.ERROR); | ||
| 213 | + result.put("msg", e.getMessage()); | ||
| 214 | + log.error("", e); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + return result; | ||
| 218 | + } | ||
| 204 | } | 219 | } |
src/main/java/com/bsth/service/LsStationRouteService.java
| @@ -79,4 +79,12 @@ public interface LsStationRouteService extends BaseService<LsStationRoute, Integ | @@ -79,4 +79,12 @@ public interface LsStationRouteService extends BaseService<LsStationRoute, Integ | ||
| 79 | * @return | 79 | * @return |
| 80 | */ | 80 | */ |
| 81 | Map<String, Object> circularRouteHandle(Integer lineId, Integer version); | 81 | Map<String, Object> circularRouteHandle(Integer lineId, Integer version); |
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 分析路由 | ||
| 85 | + * @param lineId | ||
| 86 | + * @param version | ||
| 87 | + * @param direction | ||
| 88 | + */ | ||
| 89 | + Map<String, Object> analyzeRoutes(Integer lineId, Integer version, Integer direction); | ||
| 82 | } | 90 | } |
src/main/java/com/bsth/service/impl/LsStationRouteServiceImpl.java
| @@ -5,12 +5,15 @@ import com.bsth.entity.*; | @@ -5,12 +5,15 @@ import com.bsth.entity.*; | ||
| 5 | import com.bsth.entity.search.CustomerSpecs; | 5 | import com.bsth.entity.search.CustomerSpecs; |
| 6 | import com.bsth.repository.*; | 6 | import com.bsth.repository.*; |
| 7 | import com.bsth.service.LsStationRouteService; | 7 | import com.bsth.service.LsStationRouteService; |
| 8 | -import com.bsth.util.CoordinateConverter; | ||
| 9 | import com.bsth.util.CustomBeanUtils; | 8 | import com.bsth.util.CustomBeanUtils; |
| 9 | +import com.bsth.util.Geo.GeoUtils; | ||
| 10 | +import com.bsth.util.Geo.Point; | ||
| 10 | import com.bsth.util.GeoConverter; | 11 | import com.bsth.util.GeoConverter; |
| 12 | +import com.fasterxml.jackson.core.JsonProcessingException; | ||
| 13 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 11 | import org.geolatte.geom.LineString; | 14 | import org.geolatte.geom.LineString; |
| 12 | -import org.geolatte.geom.Point; | ||
| 13 | import org.geolatte.geom.Polygon; | 15 | import org.geolatte.geom.Polygon; |
| 16 | +import org.geolatte.geom.Position; | ||
| 14 | import org.geolatte.geom.codec.Wkt; | 17 | import org.geolatte.geom.codec.Wkt; |
| 15 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | import org.springframework.data.domain.Sort; | 19 | import org.springframework.data.domain.Sort; |
| @@ -327,6 +330,90 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl<LsStationRoute, I | @@ -327,6 +330,90 @@ public class LsStationRouteServiceImpl extends BaseServiceImpl<LsStationRoute, I | ||
| 327 | return new HashMap<>(); | 330 | return new HashMap<>(); |
| 328 | } | 331 | } |
| 329 | 332 | ||
| 333 | + @Override | ||
| 334 | + public Map<String, Object> analyzeRoutes(Integer lineId, Integer version, Integer direction) { | ||
| 335 | + Map<String, Object> result = new HashMap<>(), params = new HashMap<>(); | ||
| 336 | + params.put("line.id_eq", lineId); | ||
| 337 | + params.put("versions_eq", version); | ||
| 338 | + params.put("directions_eq", direction); | ||
| 339 | + List<Sort.Order> orders1 = new ArrayList<>(), orders2 = new ArrayList<>(); | ||
| 340 | + orders1.add(new Sort.Order(Sort.Direction.ASC, "directions")); | ||
| 341 | + orders1.add(new Sort.Order(Sort.Direction.ASC, "stationRouteCode")); | ||
| 342 | + orders2.add(new Sort.Order(Sort.Direction.ASC, "directions")); | ||
| 343 | + orders2.add(new Sort.Order(Sort.Direction.ASC, "sectionrouteCode")); | ||
| 344 | + | ||
| 345 | + boolean isCircularRoute = false; | ||
| 346 | + List<LsStationRoute> stationRoutes = lsStationRouteRepository.findAll(new CustomerSpecs<>(params), Sort.by(orders1)); | ||
| 347 | + List<LsSectionRoute> sectionRoutes = lsSectionRouteRepository.findAll(new CustomerSpecs<>(params), Sort.by(orders2)); | ||
| 348 | + List<String> indexes = new ArrayList<>(); | ||
| 349 | + if (stationRoutes.get(0).getStationCode().equals(stationRoutes.get(stationRoutes.size() - 1).getStationCode())) { | ||
| 350 | + isCircularRoute = true; | ||
| 351 | + } | ||
| 352 | + for (LsSectionRoute sectionRoute : sectionRoutes) { | ||
| 353 | + LineString lineString = sectionRoute.getSection().getGsectionVector(); | ||
| 354 | + for (int i = 0;i < lineString.getNumPositions() - 1;i++) { | ||
| 355 | + List<Point> points = new ArrayList<>(); | ||
| 356 | + Position start = lineString.getPositionN(i), end = lineString.getPositionN(i + 1); | ||
| 357 | + Point point1 = new Point(start.getCoordinate(0), start.getCoordinate(1)); | ||
| 358 | + Point point2 = new Point(end.getCoordinate(0), end.getCoordinate(1)); | ||
| 359 | + int size = (int) (GeoUtils.getDistance(point1, point2) / 5) + 1; | ||
| 360 | + points.add(point1); | ||
| 361 | + if (size > 1) { | ||
| 362 | + double offsetLon = (point2.getLon() - point1.getLon()) / size; | ||
| 363 | + double offsetLat = (point2.getLat() - point1.getLat()) / size; | ||
| 364 | + for (int j = 1;j < size;j++) { | ||
| 365 | + Point mid = new Point(point1.getLon() + offsetLon * j, point1.getLat() + offsetLat * j); | ||
| 366 | + points.add(mid); | ||
| 367 | + } | ||
| 368 | + } | ||
| 369 | + points.add(point2); | ||
| 370 | + for (Point p : points) { | ||
| 371 | + for (int j = 0;j < stationRoutes.size();j++) { | ||
| 372 | + LsStationRoute stationRoute = stationRoutes.get(j); | ||
| 373 | + if ("r".equals(stationRoute.getShapedType())) { | ||
| 374 | + org.geolatte.geom.Point center = stationRoute.getStation().getCenterPointWgs(); | ||
| 375 | + if (GeoUtils.getDistance(p, new Point(center.getPositionN(0).getCoordinate(0), center.getPositionN(0).getCoordinate(1))) <= stationRoute.getRadius()) { | ||
| 376 | + if (indexes.size() == 0 || !indexes.get(indexes.size() - 1).endsWith("-" + j)) { | ||
| 377 | + indexes.add(stationRoute.getStationCode() + "-" + j); | ||
| 378 | + } | ||
| 379 | + break; | ||
| 380 | + } | ||
| 381 | + } else { | ||
| 382 | + Polygon polygon = stationRoute.getBufferPolygonWgs(); | ||
| 383 | + List<com.bsth.util.Geo.Point> polygonPoint = new ArrayList<>(); | ||
| 384 | + for (int k = 0;k < polygon.getNumPositions();k++) { | ||
| 385 | + polygonPoint.add(new Point(polygon.getPositionN(k).getCoordinate(0), polygon.getPositionN(k).getCoordinate(1))); | ||
| 386 | + } | ||
| 387 | + com.bsth.util.Geo.Polygon polygon1 = new com.bsth.util.Geo.Polygon(polygonPoint); | ||
| 388 | + if (GeoUtils.isPointInPolygon(p, polygon1)) { | ||
| 389 | + if (indexes.size() == 0 || !indexes.get(indexes.size() - 1).endsWith("-" + j)) { | ||
| 390 | + indexes.add(stationRoute.getStationCode() + "-" + j); | ||
| 391 | + } | ||
| 392 | + break; | ||
| 393 | + } | ||
| 394 | + } | ||
| 395 | + } | ||
| 396 | + } | ||
| 397 | + } | ||
| 398 | + } | ||
| 399 | + List<String> specialStations = new ArrayList<>(); | ||
| 400 | + result.put("data", specialStations); | ||
| 401 | + for (int i = 0;i < stationRoutes.size();) { | ||
| 402 | + String lastMatch = null; | ||
| 403 | + for (int j = 0;j < indexes.size();j++) { | ||
| 404 | + String index = indexes.get(j), suffix = String.format("-%d", i); | ||
| 405 | + if (index.endsWith(suffix) || isCircularRoute && i == stationRoutes.size() - 1 && index.endsWith("-0")) { | ||
| 406 | + lastMatch = index; | ||
| 407 | + i++; | ||
| 408 | + } else { | ||
| 409 | + specialStations.add(String.format("%s, %s", index, lastMatch)); | ||
| 410 | + } | ||
| 411 | + } | ||
| 412 | + } | ||
| 413 | + | ||
| 414 | + return result; | ||
| 415 | + } | ||
| 416 | + | ||
| 330 | protected void centerPoint(Station station) { | 417 | protected void centerPoint(Station station) { |
| 331 | // 中心点坐标信息 | 418 | // 中心点坐标信息 |
| 332 | String wkt = station.getCenterPointWkt(); | 419 | String wkt = station.getCenterPointWkt(); |