Commit e638e71e authored by xueyimeng's avatar xueyimeng

处理坐标转换的bug

parent 130f0b45
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
using namespace std; using namespace std;
namespace jf { namespace jf {
Track& Track::operator=(const jf::Track& track) { Track &Track::operator=(const jf::Track &track) {
this->start_time = track.start_time; this->start_time = track.start_time;
this->end_time = track.end_time; this->end_time = track.end_time;
this->coord_list = track.coord_list; this->coord_list = track.coord_list;
...@@ -23,7 +23,7 @@ namespace jf { ...@@ -23,7 +23,7 @@ namespace jf {
return *this; return *this;
} }
Track::Track(const Track& track) { Track::Track(const Track &track) {
this->start_time = track.start_time; this->start_time = track.start_time;
this->end_time = track.end_time; this->end_time = track.end_time;
this->coord_list = track.coord_list; this->coord_list = track.coord_list;
...@@ -34,9 +34,9 @@ namespace jf { ...@@ -34,9 +34,9 @@ namespace jf {
} }
bool Track::init(const std::string& track_file) { bool Track::init(const std::string &track_file) {
ifstream ifs(track_file); ifstream ifs(track_file);
if(!ifs) { if (!ifs) {
cout << "can not init track from file!" << endl; cout << "can not init track from file!" << endl;
return false; return false;
} }
...@@ -44,18 +44,18 @@ bool Track::init(const std::string& track_file) { ...@@ -44,18 +44,18 @@ bool Track::init(const std::string& track_file) {
string line; string line;
double lat = 0, lng = 0, h = 0; double lat = 0, lng = 0, h = 0;
while(getline(ifs, line)) { while (getline(ifs, line)) {
if(line.find("latitude") != string::npos) { if (line.find("latitude") != string::npos) {
istringstream iss(line); istringstream iss(line);
string tmp_str; string tmp_str;
iss >> tmp_str >> lat; iss >> tmp_str >> lat;
} }
if(line.find("longitude") != string::npos) { if (line.find("longitude") != string::npos) {
istringstream iss(line); istringstream iss(line);
string tmp_str; string tmp_str;
iss >> tmp_str >> lng; iss >> tmp_str >> lng;
} }
if(line.find("height:") != string::npos) { if (line.find("height:") != string::npos) {
istringstream iss(line); istringstream iss(line);
string tmp_str; string tmp_str;
iss >> tmp_str >> h; iss >> tmp_str >> h;
...@@ -64,27 +64,27 @@ bool Track::init(const std::string& track_file) { ...@@ -64,27 +64,27 @@ bool Track::init(const std::string& track_file) {
} }
if(line.find("track_points") != string::npos) { if (line.find("track_points") != string::npos) {
ret = true; ret = true;
point_list.clear(); point_list.clear();
std::string fields = line; std::string fields = line;
std::vector<std::string> vec_fields; std::vector<std::string> vec_fields;
Utility::SplitString(fields, vec_fields, " "); Utility::SplitString(fields, vec_fields, " ");
if(vec_fields.size() != 8) { if (vec_fields.size() != 8) {
LOG(ERROR) << "track file has unsupported field structure..."; LOG(ERROR) << "track file has unsupported field structure...";
return false; return false;
} }
if(vec_fields[1] == "lat" && vec_fields[2] == "lon" && vec_fields[3] == "height") { if (vec_fields[1] == "lat" && vec_fields[2] == "lon" && vec_fields[3] == "height") {
is_track_latlon = true; is_track_latlon = true;
} else if(vec_fields[1] == "x" && vec_fields[2] == "y" && vec_fields[3] == "z") { } else if (vec_fields[1] == "x" && vec_fields[2] == "y" && vec_fields[3] == "z") {
is_track_latlon = false; is_track_latlon = false;
} else { } else {
LOG(WARNING) << "track file has unsupported field structure..."; LOG(WARNING) << "track file has unsupported field structure...";
is_track_latlon = false; is_track_latlon = false;
} }
while(getline(ifs, line)) { while (getline(ifs, line)) {
if(line.length() < 10) if (line.length() < 10)
continue; continue;
TrackPoint track_point; TrackPoint track_point;
std::string str = line; std::string str = line;
...@@ -92,7 +92,7 @@ bool Track::init(const std::string& track_file) { ...@@ -92,7 +92,7 @@ bool Track::init(const std::string& track_file) {
//istringstream iss(line); //istringstream iss(line);
std::vector<std::string> vec_fields; std::vector<std::string> vec_fields;
Utility::SplitString(str, vec_fields, " "); Utility::SplitString(str, vec_fields, " ");
if(vec_fields.size() != 7) if (vec_fields.size() != 7)
continue; continue;
track_point.lat = std::atof(vec_fields[0].c_str()); track_point.lat = std::atof(vec_fields[0].c_str());
...@@ -104,19 +104,19 @@ bool Track::init(const std::string& track_file) { ...@@ -104,19 +104,19 @@ bool Track::init(const std::string& track_file) {
track_point.loc_time = std::atol(vec_fields[6].c_str()); track_point.loc_time = std::atol(vec_fields[6].c_str());
point_list.emplace_back(std::move(track_point)); point_list.emplace_back(std::move(track_point));
} }
if(!point_list.empty()) { if (!point_list.empty()) {
start_time = point_list.front().loc_time/1000.0; start_time = point_list.front().loc_time / 1000.0;
end_time = point_list.front().loc_time/1000.0; end_time = point_list.front().loc_time / 1000.0;
} }
} }
} }
return ret; return ret;
} }
bool Track::generateCartesian() { bool Track::generateCartesian() {
for(const auto& track_point : point_list) { for (const auto &track_point : point_list) {
if(is_track_latlon) { if (is_track_latlon) {
double e = track_point.lat, n=track_point.lng, u=track_point.height; double e = track_point.lat, n = track_point.lng, u = track_point.height;
station->TransFromEpsg4326(&n, &e, &u); station->TransFromEpsg4326(&n, &e, &u);
coord_list.emplace_back(std::move( coord_list.emplace_back(std::move(
LocalCoordinate(e, n, u) LocalCoordinate(e, n, u)
...@@ -127,23 +127,22 @@ bool Track::generateCartesian() { ...@@ -127,23 +127,22 @@ bool Track::generateCartesian() {
} }
return true; return true;
} }
void Track::getSegCoordLists() { void Track::getSegCoordLists() {
seg_coord_lists.clear(); seg_coord_lists.clear();
if(coord_list.empty()) return; if (coord_list.empty()) return;
LocalCoordinate last_lc = coord_list[0]; LocalCoordinate last_lc = coord_list[0];
std::vector<LocalCoordinate> seg_lc_list; std::vector<LocalCoordinate> seg_lc_list;
for(size_t i=0; i<coord_list.size(); ++i) { for (size_t i = 0; i < coord_list.size(); ++i) {
Eigen::Vector3d coor_now(coord_list[i].x, coord_list[i].y, coord_list[i].z); Eigen::Vector3d coor_now(coord_list[i].x, coord_list[i].y, coord_list[i].z);
Eigen::Vector3d coor_last(last_lc.x, last_lc.y, last_lc.z); Eigen::Vector3d coor_last(last_lc.x, last_lc.y, last_lc.z);
double dis = (coor_now-coor_last).norm(); double dis = (coor_now - coor_last).norm();
if(dis < TRACK_SEG_DISTANCE) { if (dis < TRACK_SEG_DISTANCE) {
seg_lc_list.push_back(coord_list[i]); seg_lc_list.push_back(coord_list[i]);
} } else if (!seg_lc_list.empty()) {
else if(!seg_lc_list.empty()){
seg_coord_lists.push_back(seg_lc_list); seg_coord_lists.push_back(seg_lc_list);
seg_lc_list.clear(); seg_lc_list.clear();
seg_lc_list.push_back(coord_list[i]); seg_lc_list.push_back(coord_list[i]);
...@@ -151,44 +150,61 @@ void Track::getSegCoordLists() { ...@@ -151,44 +150,61 @@ void Track::getSegCoordLists() {
last_lc = coord_list[i]; last_lc = coord_list[i];
} }
if(!seg_lc_list.empty()){ if (!seg_lc_list.empty()) {
seg_coord_lists.push_back(seg_lc_list); seg_coord_lists.push_back(seg_lc_list);
seg_lc_list.clear(); seg_lc_list.clear();
} }
} }
bool Track::LocalXYZ2latlon(LocalCoordinate local_xyz, double& lat, double& lng, double& height) { bool Track::LocalXYZ2latlon(LocalCoordinate local_xyz, double &lat, double &lng, double &height) {
if(nullptr == station) { if (nullptr == station) {
LOG(ERROR) << "station is not set..."; LOG(ERROR) << "station is not set...";
return false; return false;
} }
station->TransToEpsg4326(&local_xyz.x, &local_xyz.y, &local_xyz.z); station->TransToEpsg4326(&local_xyz.x, &local_xyz.y, &local_xyz.z);
lng = local_xyz.x;
lat = local_xyz.y;
height = local_xyz.z;
return true; return true;
} }
bool Track::Latlon2LocalXYZ(double lat, double lon, double height, LocalCoordinate& local_xyz) {
if (nullptr == station) {
LOG(ERROR) << "station is not set...";
return false;
}
local_xyz.x = lon;
local_xyz.y = lat;
local_xyz.z = height;
station->TransFromEpsg4326(&local_xyz.x, &local_xyz.y, &local_xyz.z);
return true;
}
bool Track::LocalXYZ2UTM(StationInfo stationInfo) { bool Track::LocalXYZ2UTM(StationInfo stationInfo) {
OGRSpatialReference* resutm51 = new OGRSpatialReference(); OGRSpatialReference *resutm51 = new OGRSpatialReference();
OGRErr err = resutm51->SetUTM(stationInfo.srid, 1); OGRErr err = resutm51->SetUTM(stationInfo.srid, 1);
if(err != OGRERR_NONE) { if (err != OGRERR_NONE) {
LOG(ERROR) << CPLGetLastErrorMsg(); LOG(ERROR) << CPLGetLastErrorMsg();
} }
OGRCoordinateTransformation* trans2UTM = nullptr; OGRCoordinateTransformation *trans2UTM = nullptr;
OGRSpatialReference* dst_wgs84 = OGRSpatialReference::GetWGS84SRS(); OGRSpatialReference *dst_wgs84 = OGRSpatialReference::GetWGS84SRS();
trans2UTM = OGRCreateCoordinateTransformation(dst_wgs84, resutm51); trans2UTM = OGRCreateCoordinateTransformation(dst_wgs84, resutm51);
if(nullptr == trans2UTM) { if (nullptr == trans2UTM) {
LOG(ERROR) << "create coordinate transformation object failed!"; LOG(ERROR) << "create coordinate transformation object failed!";
return false; return false;
} }
for(int i=0; i<coord_list.size(); i++) { for (int i = 0; i < coord_list.size(); i++) {
LocalCoordinate local_coord = coord_list[i]; LocalCoordinate local_coord = coord_list[i];
double lat, lon, height; double lat, lon, height;
LocalXYZ2latlon(local_coord, lat, lon, height); LocalXYZ2latlon(local_coord, lat, lon, height);
double utm_x=lon, utm_y=lat, utm_z=height; double utm_x = lon, utm_y = lat, utm_z = height;
trans2UTM->Transform(1, &utm_x, &utm_y, &utm_z); trans2UTM->Transform(1, &utm_x, &utm_y, &utm_z);
utm_x -= stationInfo.utm_offset_x; utm_x -= stationInfo.utm_offset_x;
utm_y -= stationInfo.utm_offset_y; utm_y -= stationInfo.utm_offset_y;
......
...@@ -49,6 +49,8 @@ public: ...@@ -49,6 +49,8 @@ public:
bool LocalXYZ2latlon(LocalCoordinate local_xyz, double& lat, double& lon, double& height); bool LocalXYZ2latlon(LocalCoordinate local_xyz, double& lat, double& lon, double& height);
bool Latlon2LocalXYZ(double lat, double lon, double height, LocalCoordinate& local_xyz);
bool LocalXYZ2UTM(StationInfo stationInfo); bool LocalXYZ2UTM(StationInfo stationInfo);
public: public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment