| 1045 | } |
| 1046 | |
| 1047 | int LocalSearch::updateRoads(const hadmap::txRoads& roads) { |
| 1048 | std::set<int> laneBoundaryid; |
| 1049 | for (auto it = roads.begin(); it != roads.end(); it++) { |
| 1050 | // update road |
| 1051 | tx_road_t roat_t = (*it)->getTxData(); |
| 1052 | roat_t.srs = 4326; |
| 1053 | roat_t.pkid = (*it)->getId(); |
| 1054 | roat_t.section_num = (*it)->getSections().size(); |
| 1055 | dbPtr->updateRoad(roat_t); |
| 1056 | hadmap::txRoadPtr roadPtr; |
| 1057 | getRoad(roat_t.pkid, true, roadPtr); |
| 1058 | |
| 1059 | int sectionNum = 0; |
| 1060 | // update lane and boundary |
| 1061 | if ((*it)->getSections().size() == roadPtr->getSections().size()) { |
| 1062 | for (auto itSection : (*it)->getSections()) { |
| 1063 | txLanes lanesNeedUpdate; |
| 1064 | txLanes lanesNeedDelete; |
| 1065 | txLanes lanesNeedInsert; |
| 1066 | int currentLaneSize = roadPtr->getSections().at(sectionNum)->getLanes().size(); |
| 1067 | int updateLaneSize = itSection->getLanes().size(); |
| 1068 | |
| 1069 | if (currentLaneSize > updateLaneSize) { |
| 1070 | lanesNeedUpdate.assign(itSection->getLanes().begin(), itSection->getLanes().end()); |
| 1071 | lanesNeedDelete.assign(roadPtr->getSections().at(sectionNum)->getLanes().begin() + updateLaneSize, |
| 1072 | roadPtr->getSections().at(sectionNum)->getLanes().end()); |
| 1073 | } else if (currentLaneSize < updateLaneSize) { |
| 1074 | lanesNeedUpdate.assign(itSection->getLanes().begin(), itSection->getLanes().begin() + currentLaneSize); |
| 1075 | lanesNeedInsert.assign(itSection->getLanes().begin() + currentLaneSize, itSection->getLanes().end()); |
| 1076 | } else { |
| 1077 | lanesNeedUpdate.assign(itSection->getLanes().begin(), itSection->getLanes().end()); |
| 1078 | } |
| 1079 | |
| 1080 | // need to update lane |
| 1081 | for (auto itlane : lanesNeedUpdate) { |
| 1082 | tx_lane_t tlane = (itlane)->getTxLaneData(); |
| 1083 | tlane.srs = 4326; |
| 1084 | if (laneBoundaryid.find(itlane->getLeftBoundaryId()) == laneBoundaryid.end()) { |
| 1085 | tx_laneboundary_t boundary = itlane->getLeftBoundary()->getTxData(); |
| 1086 | boundary.srs = 4326; |
| 1087 | laneBoundaryid.insert(itlane->getLeftBoundaryId()); |
| 1088 | dbPtr->updateLaneBoundary(boundary); |
| 1089 | } |
| 1090 | if (laneBoundaryid.find(itlane->getRightBoundaryId()) == laneBoundaryid.end()) { |
| 1091 | tx_laneboundary_t boundary = itlane->getRightBoundary()->getTxData(); |
| 1092 | boundary.srs = 4326; |
| 1093 | laneBoundaryid.insert(itlane->getRightBoundaryId()); |
| 1094 | dbPtr->updateLaneBoundary(boundary); |
| 1095 | } |
| 1096 | dbPtr->updateLane(tlane); |
| 1097 | } |
| 1098 | // need to delete lane |
| 1099 | for (auto itlane : lanesNeedDelete) { |
| 1100 | tx_lane_t tlane = (itlane)->getTxLaneData(); |
| 1101 | dbPtr->deleteLane(tlane.road_pkid, tlane.section_id, tlane.lane_id); |
| 1102 | if (laneBoundaryid.find(itlane->getLeftBoundaryId()) == laneBoundaryid.end()) { |
| 1103 | tx_laneboundary_t boundary = itlane->getLeftBoundary()->getTxData(); |
| 1104 | boundary.srs = 4326; |
nothing calls this directly
no test coverage detected