I want to convert wgs84 to utm, and I already finish use some code,But I need to know how to write a las header. such as utm 49 zone
I know use txt2las.exe can make this use such command :txt2las -i "C:\Users\sa759\Documents\LAStools-master\LAStools-master\bin\utm.txt" -parse xyz -olas -utm 49north
Use this command can make it,but I need to use my code to finish this,So how to warite a header?
Thank you very much.
LASwriter* laswriter;
LASwriteOpener laswriteopener;
LASheader lasheader;
LASpoint laspoint;
lasheader.point_data_format = 1;
lasheader.point_data_record_length = 28;
// init point
laspoint.init(&lasheader, lasheader.point_data_format, lasheader.point_data_record_length, 0);
// create writer
laswriteopener.set_file_name(lasfile.c_str());
laswriter = laswriteopener.open(&lasheader);
while (fgets(line, sizeof(line), fp)){
// read txt data such as Longitude:113 Latitude:23 Height: 10
result = strtok(line, delims);
lon = atof(result);
result = strtok(NULL, delims);
lat = atof(result);
result = strtok(NULL, delims);
height = atof(result);
zone = static_cast<int>((lon + 180) / 6 + 1);
lat = lat / 180.0*pi;
lon = lon / 180.0*pi;
UTMCoor xy;
LatLonToUTMXY(lat, lon, zone, xy); // this can convert latitue longtitude to utm x y
double lx, ly, lz;
lx = xy.x; ly = xy.y; lz = height;
fprintf(utm, "%10f,%10f,%10f\n", xy.x, xy.y, height); //write utm x y height to a txt file
laspoint.coordinates[0] = lx;
laspoint.coordinates[1] = ly;
laspoint.coordinates[2] = lz;
laspoint.compute_XYZ();
laswriter->write_point(&laspoint);
laswriter->update_inventory(&laspoint);
}
laswriter->update_header(&lasheader, TRUE);