Exemple #1
0
void printLasHeader(std::ostream& out, const liblas::Header& header)
{
    out << "[Filter] Header: ";
    out << "Offset=" << math::Vector3d(header.GetOffsetX(), header.GetOffsetY(), header.GetOffsetZ());
    out << "Min=" << math::Vector3d(header.GetMinX(), header.GetMinY(), header.GetMinZ());
    out << "Max=" << math::Vector3d(header.GetMaxX(), header.GetMaxY(), header.GetMaxZ());
    out << std::endl;
}
Exemple #2
0
void PrintVLRs(std::ostream& os, liblas::Header const& header)
{
    if (!header.GetRecordsCount())
        return ;
        
    os << "---------------------------------------------------------" << std::endl;
    os << "  VLR Summary" << std::endl;
    os << "---------------------------------------------------------" << std::endl;
    
    typedef std::vector<VariableRecord>::size_type size_type;
    for(size_type i = 0; i < header.GetRecordsCount(); i++) {
        liblas::VariableRecord const& v = header.GetVLR(i);
        os << v;
    }
    
}
Exemple #3
0
void WriterImpl::UpdateHeader(liblas::Header const& header)
{
    if (m_pointCount != header.GetPointRecordsCount())
    {
        // 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, m_pointCount , sizeof(m_pointCount));
    }
}
void LidarMetadata::setFromLasHeader(liblas::Header const& theHeader)
{
	mNumOfPoints = theHeader.GetPointRecordsCount();
	mMinX = theHeader.GetMinX();
	mMaxX = theHeader.GetMaxX();
	mMinY = theHeader.GetMinY();
	mMaxY = theHeader.GetMaxY();
	mMinZ = theHeader.GetMinZ();
	mMaxZ = theHeader.GetMaxZ();
	QString crsDesc = QString::fromStdString(theHeader.GetSRS().GetProj4());
	if (crsDesc != "")
		mCrs = new QgsCoordinateReferenceSystem();
	//The caller should check if CRS is valid and if it is not, call projection selector
}
Exemple #5
0
void test_laszip_vlr(liblas::Header const& header)
{
    bool found_vlr = false;

    std::vector<liblas::VariableRecord> const& vlrs = header.GetVLRs();
    std::vector<liblas::VariableRecord>::const_iterator it;
    for (it = vlrs.begin(); it != vlrs.end(); ++it)
    {
        liblas::VariableRecord const& vlr = *it;
        if (vlr.GetUserId(false).compare("laszip encoded") == 0)
        {
            ensure_equals(found_vlr, false); // make sure we only find one
            found_vlr = true;

            ensure_equals(vlr.GetRecordId(), 22204);
            ensure_equals(vlr.GetRecordLength(), 52);
        }
    }
    
    ensure_equals(found_vlr, true); // make sure we found exactly one

    return;
}
Exemple #6
0
void test_default_header(liblas::Header const& h)
{
    using liblas::Header;

    ensure_equals("wrong default file signature",
        h.GetFileSignature(), Header::FileSignature);

    ensure_equals("wrong default file source id",
        h.GetFileSourceId(), 0);
    ensure_equals("wrong default reserved value",
        h.GetReserved(), 0);

    boost::uuids::uuid g = boost::uuids::nil_uuid();
    ensure_equals("wrong default project guid",
        h.GetProjectId(), g);

    ensure_equals("wrong default major version",
        h.GetVersionMajor(), 1);
    ensure_equals("wrong default minor version",
        h.GetVersionMinor(), 2);

    ensure_equals("wrong default system id",
        h.GetSystemId(), Header::SystemIdentifier);
    ensure_equals("wrong default software id",
        h.GetSoftwareId(), Header::SoftwareIdentifier);

    // TODO: Fix me to use todays day # and year
    // ensure_equals("wrong default creation day-of-year",
    //     h.GetCreationDOY(), 0);
    // ensure_equals("wrong default creation year",
    //     h.GetCreationYear(), 0);
    ensure_equals("wrong default header size",
        h.GetHeaderSize(), boost::uint16_t(227));
    
    boost::uint32_t offset = 229;
    if (h.GetVersionMinor() == 1 || h.GetVersionMinor() == 2)
    {
        offset = 227;
    }
    ensure_equals("wrong default data offset",
        h.GetDataOffset(), offset);
    
    ensure_equals("wrong default records count",
        h.GetRecordsCount(), boost::uint32_t(0));
    ensure_equals("wrong default data format id",
        h.GetDataFormatId(), liblas::ePointFormat3);
    ensure_equals("wrong default data record length",
        h.GetDataRecordLength(), liblas::ePointSize3);
    ensure_equals("wrong default point records count",
        h.GetPointRecordsCount(), boost::uint32_t(0));

    ensure_equals("wrong default X scale", h.GetScaleX(), double(1.0));
    ensure_equals("wrong default Y scale", h.GetScaleY(), double(1.0));
    ensure_equals("wrong default Z scale", h.GetScaleZ(), double(1.0));

    ensure_equals("wrong default X offset", h.GetOffsetX(), double(0));
    ensure_equals("wrong default Y offset", h.GetOffsetY(), double(0));
    ensure_equals("wrong default Z offset", h.GetOffsetZ(), double(0));

    ensure_equals("wrong default min X", h.GetMinX(), double(0));
    ensure_equals("wrong default max X", h.GetMaxX(), double(0));
    ensure_equals("wrong default min Y", h.GetMinY(), double(0));
    ensure_equals("wrong default max Y", h.GetMaxY(), double(0));
    ensure_equals("wrong default min Z", h.GetMinZ(), double(0));
    ensure_equals("wrong default max Z", h.GetMaxZ(), double(0));
}
Exemple #7
0
void test_file10_header(liblas::Header const& h)
{
    ensure_equals(h.GetFileSignature(), liblas::Header::FileSignature);
    ensure_equals(h.GetFileSourceId(), 0);
    ensure_equals(h.GetReserved(), 0);

    boost::uuids::uuid g = boost::uuids::nil_uuid();
    ensure_equals(g, boost::uuids::nil_uuid());
    ensure_equals("wrong ProjectId", h.GetProjectId(), g);

    ensure_equals("wrong VersionMajor", h.GetVersionMajor(), 1);
    ensure_equals("wrong VersionMinor", h.GetVersionMinor(), 0);
    ensure_equals("wrong GetSystemId", h.GetSystemId(), std::string(""));
    ensure_equals("wrong GetSoftwareId", h.GetSoftwareId(), std::string("TerraScan"));
    ensure_equals("Wrong GetCreationDOY", h.GetCreationDOY(), 0);
    ensure_equals("Wrong GetCreationYear", h.GetCreationYear(), 0);
    ensure_equals("Wrong GetHeaderSize", h.GetHeaderSize(), boost::uint16_t(227));
    ensure_equals("Wrong GetDataOffset", h.GetDataOffset(), boost::uint32_t(229));
    ensure_equals("Wrong GetRecordsCount", h.GetRecordsCount(), boost::uint32_t(0));
    ensure_equals("Wrong GetDataFormatId", h.GetDataFormatId(), liblas::ePointFormat1);
    ensure_equals("Wrong GetDataRecordLength", h.GetDataRecordLength(), liblas::ePointSize1);
    ensure_equals("Wrong GetPointRecordsCount", h.GetPointRecordsCount(), boost::uint32_t(8));
    ensure_equals("Wrong GetScaleX", h.GetScaleX(), double(0.01));
    ensure_equals("Wrong GetScaleY", h.GetScaleY(), double(0.01));
    ensure_equals("Wrong GetScaleZ", h.GetScaleZ(), double(0.01));
    ensure_equals("Wrong GetOffsetX", h.GetOffsetX(),double(-0));
    ensure_equals("Wrong GetOffsetY", h.GetOffsetY(), double(-0));
    ensure_equals("Wrong GetOffsetZ", h.GetOffsetZ(), double(-0));
    ensure_equals("Wrong GetMinX", h.GetMinX(), double(630262.3));
    ensure_equals("Wrong GetMaxX", h.GetMaxX(), double(630346.83));
    ensure_equals("Wrong GetMinY", h.GetMinY(), double(4834500));
    ensure_equals("Wrong GetMaxY", h.GetMaxY(), double(4834500));
    ensure_equals("Wrong GetMinZ", h.GetMinZ(), double(50.9));
    ensure_equals("Wrong GetMaxZ", h.GetMaxZ(), double(55.26));
}
Exemple #8
0
bool process(   std::string const& input,
                std::string const& output,
                liblas::Header & header,
                std::vector<liblas::FilterPtr>& filters,
                std::vector<liblas::TransformPtr>& transforms,
                boost::uint32_t split_mb,
                boost::uint32_t split_pts,
                bool verbose,
                bool min_offset)
{

    std::ifstream ifs;
    if (!liblas::Open(ifs, input.c_str()))
    {
        std::cerr << "Cannot open " << input << "for read.  Exiting...";
        return false;
    }
    // set_ifstream_buffer(ifs, default_buffer_size);

    liblas::Reader reader(ifs);
    liblas::Summary* summary = new liblas::Summary;
    
    reader.SetFilters(filters);
    reader.SetTransforms(transforms);    
    
    if (min_offset) 
    {
        
        liblas::property_tree::ptree tree = reader.Summarize();
        try
        {
            header.SetOffset(tree.get<double>("summary.points.minimum.x"),
                             tree.get<double>("summary.points.minimum.y"),
                             tree.get<double>("summary.points.minimum.z"));
    
                              
        }
        catch (liblas::property_tree::ptree_bad_path const& e) 
        {
            std::cerr << "Unable to write minimum header info.  Does the outputted file have any points?";
            std::cerr << e.what() << std::endl;
            return false;
        }
        if (verbose) 
        {
            
    
            std::cout << "Using minimum offsets ";
            SetStreamPrecision(std::cout, header.GetScaleX());
            std::cout << header.GetOffsetX() << " ";
            SetStreamPrecision(std::cout, header.GetScaleY());
            std::cout << header.GetOffsetY() << " ";
            SetStreamPrecision(std::cout, header.GetScaleZ());
            std::cout << header.GetOffsetZ() << " ";
            std::cout << std::endl;
        }
        reader.Reset();
    }

    std::ofstream* ofs = new std::ofstream;
    std::string out = output;
    liblas::Writer* writer = 0;
    if (!split_mb && !split_pts) {
        writer = start_writer(ofs, output, header);
        
    } else {
        string::size_type dot_pos = output.find_first_of(".");
        out = output.substr(0, dot_pos);
        writer = start_writer(ofs, out+"-1"+".las", header);
    }

    if (verbose)
    std::cout << "Writing output:" 
        << "\n - : " << output
        << std::endl;

    //
    // Translation of points cloud to features set
    //
    boost::uint32_t i = 0;
    boost::uint32_t const size = header.GetPointRecordsCount();
    
    boost::int32_t split_bytes_count = 1024*1024*split_mb;
    boost::uint32_t split_points_count = 0;
    int fileno = 2;

    while (reader.ReadNextPoint())
    {
        
        liblas::Point const& p = reader.GetPoint();
        summary->AddPoint(p);
        writer->WritePoint(p);
        if (verbose)
            term_progress(std::cout, (i + 1) / static_cast<double>(size));
        i++;
        split_points_count++;

        split_bytes_count = split_bytes_count - header.GetSchema().GetByteSize();        
        if (split_bytes_count < 0 && split_mb > 0 && ! split_pts) {
            // The user specifies a split size in mb, and we keep counting 
            // down until we've written that many points into the file.  
            // After that point, we make a new file and start writing into 
            // that.  
            delete writer;
            delete ofs;
            
            ofs = new std::ofstream;
            ostringstream oss;
            oss << out << "-"<< fileno <<".las";

            writer = start_writer(ofs, oss.str(), header);

            ostringstream old_filename;
            old_filename << out << "-" << fileno - 1 << ".las";

            liblas::Header hnew = FetchHeader(old_filename.str());
            RepairHeader(*summary, hnew);
            RewriteHeader(hnew, old_filename.str());

            delete summary;
            summary =  new liblas::Summary; 
            fileno++;
            split_bytes_count = 1024*1024*split_mb;
        }

        if (split_pts > 0 && ! split_mb && split_points_count == split_pts) {
            // The user specifies a split size in pts, and we keep counting 
            // down until we've written that many points into the file.  
            // After that point, we make a new file and start writing into 
            // that.  

            delete writer;
            delete ofs;
            
            ofs = new std::ofstream;
            ostringstream oss;
            oss << out << "-"<< fileno <<".las";

            writer = start_writer(ofs, oss.str(), header);

            ostringstream old_filename;
            old_filename << out << "-" << fileno - 1 << ".las";
            
            liblas::Header hnew = FetchHeader(old_filename.str());
            RepairHeader(*summary, hnew);
            RewriteHeader(hnew, old_filename.str());
            delete summary;
            summary =  new liblas::Summary; 
            fileno++;
            split_points_count = 0;
        }

    }
    if (verbose)
        std::cout << std::endl;
    
    reader.Reset();
    // liblas::property_tree::ptree pts = summary->GetPTree();
    // liblas::property_tree::ptree top;
    // top.add_child("summary.header",reader.GetHeader().GetPTree());
    // top.add_child("summary.points",pts);
    // liblas::property_tree::write_xml("junk.xml", top);
    // liblas::property_tree::write_xml("schema.xml", reader.GetHeader().GetSchema().GetPTree());
    // 
    // std::cout <<  reader.GetHeader().GetSchema() << std::endl;
    delete writer;
    delete ofs;
    
    liblas::Header hnew = FetchHeader(output);
    RepairHeader(*summary, hnew);
    RewriteHeader(hnew, output);

    delete summary;
    
    return true;
}
Exemple #9
0
bool process(   std::istream& ifs,
                std::string const& output,
                liblas::Header & header,
                std::vector<liblas::FilterPtr>& filters,
                std::vector<liblas::TransformPtr>& transforms,
                boost::uint32_t split_mb,
                boost::uint32_t split_pts,
                bool verbose,
                bool min_offset)
{
    liblas::ReaderFactory f;
    liblas::Reader reader = f.CreateWithStream(ifs);
    SummaryPtr summary(new::liblas::CoordinateSummary);
    
    reader.SetFilters(filters);
    reader.SetTransforms(transforms);    
    
    if (min_offset) 
    {
        liblas::property_tree::ptree tree = SummarizeReader(reader);

        try
        {
            header.SetOffset(tree.get<double>("summary.points.minimum.x"),
                             tree.get<double>("summary.points.minimum.y"),
                             tree.get<double>("summary.points.minimum.z"));
    
                              
        }
        catch (liblas::property_tree::ptree_bad_path const& e) 
        {
            std::cerr << "Unable to write minimum header info.  Does the outputted file have any points?";
            std::cerr << e.what() << std::endl;
            return false;
        }
        if (verbose) 
        {
            std::cout << "Using minimum offsets ";
            SetStreamPrecision(std::cout, header.GetScaleX());
            std::cout << header.GetOffsetX() << " ";
            SetStreamPrecision(std::cout, header.GetScaleY());
            std::cout << header.GetOffsetY() << " ";
            SetStreamPrecision(std::cout, header.GetScaleZ());
            std::cout << header.GetOffsetZ() << " ";
            std::cout << std::endl;
        }
        reader.Reset();
        
        // If we have any reprojection going on, we have to reset the offsets 
        // of the HeaderPtr that is applied to the points as they are reprojected
        // or things will get screwed up when we go to re-assign the header
        // as we write the points with the min-offset
        std::vector<liblas::TransformPtr> transforms = reader.GetTransforms();
        std::vector<liblas::TransformPtr> new_transforms;
        for (std::size_t i = 0; i < transforms.size(); i++)
        {
            liblas::TransformPtr transform = transforms[i];
            
            if (dynamic_cast<liblas::ReprojectionTransform*>(transform.get()))
            {
                dynamic_cast<liblas::ReprojectionTransform*>(transform.get())->SetHeader(&header);
            }
            new_transforms.push_back(transform);
        }
        reader.SetTransforms(new_transforms);
    }

    std::ostream* ofs = NULL;
    std::string out = output;
    
    WriterPtr writer;

    if (!split_mb && !split_pts) {
        writer = start_writer(ofs, output, header);
        
    } else {
        string::size_type dot_pos = output.find_first_of(".");
        out = output.substr(0, dot_pos);
        writer = start_writer(ofs, out+"-1"+".las", header);
    }

    if (verbose)
    std::cout << "Writing output:" 
        << "\n - : " << output
        << std::endl;

    //
    // Translation of points cloud to features set
    //
    boost::uint32_t i = 0;
    boost::uint32_t const size = header.GetPointRecordsCount();
    
    boost::int32_t split_bytes_count = 1024*1024*split_mb;
    boost::uint32_t split_points_count = 0;
    int fileno = 2;
    
    
    while (reader.ReadNextPoint())
    {
        if (min_offset)
        {
            liblas::Point p = reader.GetPoint();
            summary->AddPoint(p);
            p.SetHeader(&header);
            writer->WritePoint(p);
        }
        else 
        {
            liblas::Point const& p = reader.GetPoint();
            summary->AddPoint(p);
            writer->WritePoint(p);            
        }
        if (verbose)
            term_progress(std::cout, (i + 1) / static_cast<double>(size));
        i++;
        split_points_count++;

        split_bytes_count = split_bytes_count - header.GetSchema().GetByteSize();        
        if (split_bytes_count < 0 && split_mb > 0 && ! split_pts) {
            // The user specifies a split size in mb, and we keep counting 
            // down until we've written that many points into the file.  
            // After that point, we make a new file and start writing into 
            // that.  

            // dereference the writer so it is deleted before the ofs
            writer = WriterPtr();
            
            delete ofs;
            ofs = NULL;

            ostringstream oss;
            oss << out << "-"<< fileno <<".las";

            writer = start_writer(ofs, oss.str(), header);

            ostringstream old_filename;
            old_filename << out << "-" << fileno - 1 << ".las";

            liblas::Header hnew = FetchHeader(old_filename.str());
            RepairHeader(*summary, hnew);
            RewriteHeader(hnew, old_filename.str());

            summary =  SummaryPtr(new liblas::CoordinateSummary); 
            fileno++;
            split_bytes_count = 1024*1024*split_mb;
        }

        if (split_pts > 0 && ! split_mb && split_points_count == split_pts) {
            // The user specifies a split size in pts, and we keep counting 
            // down until we've written that many points into the file.  
            // After that point, we make a new file and start writing into 
            // that.  

            // dereference the writer so it is deleted before the ofs
            writer = WriterPtr();
            
            delete ofs;
            ofs = NULL;

            ostringstream oss;
            oss << out << "-"<< fileno <<".las";

            writer = start_writer(ofs, oss.str(), header);

            ostringstream old_filename;
            old_filename << out << "-" << fileno - 1 << ".las";
            
            liblas::Header hnew = FetchHeader(old_filename.str());
            RepairHeader(*summary, hnew);
            RewriteHeader(hnew, old_filename.str());

            summary =  SummaryPtr(new liblas::CoordinateSummary); 
            fileno++;
            split_points_count = 0;
        }

    }
    if (verbose)
        std::cout << std::endl;

    // cheap hackery.  We need the Writer to disappear before the stream.  
    // Fix this up to not suck so bad.
    writer = WriterPtr();
    delete ofs;
    ofs = NULL;
        
    if (!split_mb && !split_pts) {
        reader.Reset();

        liblas::Header hnew = FetchHeader(output);
        RepairHeader(*summary, hnew);
        RewriteHeader(hnew, output);
    }

    return true;
}