利用LasTools(LASLib)库获取las数据中的坐标系

    读取机载激光雷达得las文件,并做数据处理,就需要知道文件中点云坐标对应得坐标系(地理坐标系,GCS;或者投影坐标系,PCS;),但是具体得坐标信息如何获取就需要了解las文件结构和las文件中地理信息存储方式(同GeoTIff),参考这篇论文,才知道各个GeoKey是数组存储的,可以用指针进行遍历:

利用LasTools(LASLib)库获取las数据中的坐标系_第1张图片

    按照上面的讲解,于是有了如下的测试代码:

		//打开las文件
		LASreadOpener lasreadopener;
		lasreadopener.set_file_name(lasFile.c_str());
		LASreader* lasreader = lasreadopener.open();
		size_t count = lasreader->header.number_of_point_records;
		pcl::PointCloud::Ptr pointCloudPtr(new pcl::PointCloud);
		pointCloudPtr->resize(count);
		pointCloudPtr->width = 1;
		pointCloudPtr->height = count;
		pointCloudPtr->is_dense = false;
		//////////////////////////读取.las文件的版本号
		unsigned char Vmajor = lasreader->header.version_major;
		unsigned char Vminor = lasreader->header.version_minor;
		printf("LasVersion: %d.%d\n" , Vmajor,Vminor);
		///////////////////////////变长记录区vlrs描述
		char* ds = (char*)lasreader->header.vlrs->description;
		printf("vlrs description: %s\n", ds);
		//////////////////////////变长记录区id
		U16 Nofkeys2 = lasreader->header.vlrs->record_id;
		printf("vlrs_id: %d\n", Nofkeys2);
		//////////////////////////geokeys个数
		U16 Nofkeys = lasreader->header.vlr_geo_keys->number_of_keys;//
		printf("number_of_keys: %d\n", Nofkeys);
		//////////////////////////试着读取wkt失败,因该las文件版本为:1.2,只有最新得1.4版本才加入了wkt		
		/*char* WKT = lasreader->header.vlr_geo_ogc_wkt;
		printf(" %c\n", WKT);*/
		//////////////////////////顺序读取Geokeys
		int numof_keys = lasreader->header.vlr_geo_keys->number_of_keys;
		for (int i = 0; i < numof_keys; i++)
		{
			//顺序读取GeoKey内容
			U16 id = (lasreader->header.vlr_geo_key_entries + i)->key_id;
			U16 Location = (lasreader->header.vlr_geo_key_entries + i)->tiff_tag_location;
			U16 count = (lasreader->header.vlr_geo_key_entries + i)->count;
			U16 value_offset = (lasreader->header.vlr_geo_key_entries + i)->value_offset;
			//vlr_geo_double_params
			F64 value;
			if (Location == 34736)
			{
				value = lasreader->header.vlr_geo_double_params[value_offset];
				printf("keysID:%d ,Location:%d,Count: %d ,Value_offset:%d ,Value:%f \n", id, Location, count, value_offset, value);
			}
			//vlr_geo_ascii_params
			else if (Location == 34737)
			{
				CHAR value_char[32];
				for (int j = 0; j < count; j++)
				{
					value_char[j] = lasreader->header.vlr_geo_ascii_params[value_offset + j];
				}
				printf("keysID:%d ,Location:%d,Count: %d ,Value_offset:%d ,ValueChar:%s \n", id, Location, count, value_offset, value_char);
			}
			else 
				printf("keysID:%d ,Location:%d,Count: %d ,Value_offset:%d\n", id, Location, count, value_offset);
		}

    输出结果如下图所示:

利用LasTools(LASLib)库获取las数据中的坐标系_第2张图片

    从上图中我们可以看到共有13个keysID,每一个ID值对应的含义可以参照这里。上图中ID = 3072 对应的值是 32650;这个值就是EPSG Code,根据EPSG code对照表可知坐标系正是WGS84UTM50N

利用LasTools(LASLib)库获取las数据中的坐标系_第3张图片

    有了EPSG Code就能够利用GDAL生成各种格式的坐标系统描述了(例如:WKT)(详情:https://mp.csdn.net/postedit/80988850)





你可能感兴趣的:(基础概念,三维点云数据处理学习笔记)