convert wgs84 to utm use code

219 views
Skip to first unread message

谢国栋

unread,
Apr 17, 2018, 6:33:39 AM4/17/18
to LAStools - efficient tools for LiDAR processing
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.

This is my code:
        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);

Martin Isenburg

unread,
Apr 17, 2018, 8:11:08 AM4/17/18
to LAStools - efficient command line tools for LIDAR processing
Hello,

you can do this with the LASheader function set_geo_keys()


if you can already know the set of keys to use. Alternatively look into the code of geoprojectionconverter.cpp how to put a set of keys together simply by reading the source code of this function here:


and here you can see the two used together in action:


Regards,

Martin @rapidlasso


Reply all
Reply to author
Forward
0 new messages