[Liblas-devel] Re:

Mateusz Loskot mateusz at loskot.net
Wed Aug 26 19:47:14 EDT 2009


Gary Robinson wrote:
> I attached my cpp file. I was trying first to write a file with a single
> point, then switch that line at the top that is commented out and recompile
> to read the file back in.

Greg,

Replace your version of the program with my version included below
and run as you did with yours. Observe if anything has changed.


/// mloskot version ////////////////////////////////////////////
#include <liblas/laspoint.hpp>
#include <liblas/lasreader.hpp>
#include <liblas/laswriter.hpp>
#include <exception>
#include <fstream>  // std::ifstream
#include <iostream> // std::cout

using namespace liblas;
int main()
{
    // First run with false, next run with true
    bool bRead = false;
    try
    {
        if(bRead)
        {
            std::ifstream ifs;
            ifs.open("test.las", std::ios::in | std::ios::binary);

            liblas::LASReader reader(ifs);
            liblas::LASHeader const& header = reader.GetHeader();

            std::cout << "Signature: " << header.GetFileSignature() << '\n';
            std::cout << "Points count: " <<
header.GetPointRecordsCount() << '\n';

            ifs.close();
        }
        else
        {
            std::ofstream ofs;
            ofs.open("test.las", std::ios::out | std::ios::binary);

            liblas::LASHeader header;
            header.SetDataFormatId(LASHeader::ePointFormat1);

            liblas::LASWriter writer(ofs, header);

            liblas::LASPoint point;
            point.SetCoordinates(10,20,30);
            writer.WritePoint(point);		
        }

    }
    catch (std::exception const& e)
    {
        std::cerr << e.what() << std::endl;
    }
    catch (...)
    {
        std::cerr << "unknown error" << std::endl;
    }

    return 0;
}
/// end of mloskot version /////////////////////////////////////////


Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org


More information about the Liblas-devel mailing list