libLAS / libLAS

C++ library and programs for reading and writing ASPRS LAS format with LiDAR data

Home Page:http://liblas.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no floating values for coordinates

KirbX opened this issue · comments

commented

Hi!
I'm trying to create a LAS file "from scratch", but it seems that my points have no floating coordinates, only integer one (the result is a grid of points that are all separate with exactly 1meter).
When I try to add

liblas::SpatialReference srs;
srs.SetFromUserInput("EPSG:4326");
m_header.SetSRS(srs);

an error is throw from "spatialReference.cpp" line 680 :

boost::ignore_unused_variable_warning(v);
throw std::runtime_error("GDAL is not available, SpatialReference could not be set from WKT");

So I didn't put this code, is this mandatory?

I have another question.
Actually I'm trying to create the file by adding points without knowing at first how many points I will add. Does the header.pointsRecordCount update itself when I call for writer.WritePoint(...)?

Here is the part of my code that is used to create the file :

int SaveLAS::write(std::vector<mypt3d>& pts) {
	for (int i = 0; i < pts.size(); ++i) {
		liblas::Point point(&m_header);
		point.SetCoordinates(pts[i].x, pts[i].y, pts[i].z);
		point.SetIntensity(pts[i].intensity);
		point.SetColor(liblas::Color(pts[i].r, pts[i].g, pts[i].b));
		m_writer->WritePoint(point);
		m_numEffective++;
	}
}

int SaveLAS::writeHeader() {
	
	m_header.SetDataFormatId(liblas::ePointFormat3); // X Y Z I R G B
	m_header.SetFileSignature("LASF");
	m_header.SetCompressed(false);
	//liblas::SpatialReference srs;
	//srs.SetFromUserInput("EPSG:4326");
	//m_header.SetSRS(srs);
	m_writer = new liblas::Writer(m_stream, m_header);
	return 1;
}

int SaveLAS::writeFooter() {
	m_stream.close();
	delete m_writer;
	return 1;
}

where m_header is a header generated with default constructor.

Thanks!

R.Schim

If you don't call m_header.SetScale anywhere, then the default scale is 1.0. (raw coordinates are stored as 32-bit integers, as per the LAS spec).

The point count should be auto-updated as per the example comment (could really be comment for Header or SetPointRecordsCount itself)

hdr.SetPointRecordsCount(1000); // should be corrected automatically by writer

or the implementation itself

void WriterImpl::UpdatePointCount(boost::uint32_t count)
{
boost::uint32_t out = m_pointCount;
if ( count != 0 ) { out = count; }
m_header->SetPointRecordsCount(out);
if (!m_ofs.good() ) return;
// Skip to first byte of number of point records data member
std::streamsize const dataPos = 107;
m_ofs.seekp(dataPos, std::ios::beg);
detail::write_n(m_ofs, out , sizeof(out));
}

commented

Yes! Thanks a lot! It was it! the SetScale(0.001, 0.001, 0.001) made it!
I don't know if you are the author of liblas.org, buy maybe you should put an hint into the tutorial?
I didn't find any reference to setScale in the writing part.

Anyways! Thanks for your fast and good answer! It helped me a lot!
And that's an amazing work!

Thanks again!

Best Regards

I'm glad I was able to help.

I don't know if you are the author of liblas.org,

I'm a co-author

The libLAS development team are:
* `Howard Butler`_
* `Mateusz Loskot`_
* `Phil Vachon`_
* Martin Vales
* `Frank Warmerdam`_

buy maybe you should put an hint into the tutorial?

The documentation has been a bit neglected, so I'll be happy to accept any pull request that attempts to improve it. Opening an issue with suggestions would also be helpful as reminder what needs to be done when I run next round of libLAS maintenance tasks.

Meanwhile, since libLAS codebase is not huge, I'd suggest users literate in C/C++ to browse code of samples, tests and the library itself.