liblas學習筆記二——構建格網索引,liblas學習筆記

來源:互聯網
上載者:User

liblas學習筆記二——構建格網索引,liblas學習筆記

主要代碼檔案為index.hpp index.cpp

index.hpp中定義了幾個宏

//最大記憶體限制,預設為10M

#define LIBLAS_INDEX_MAXMEMDEFAULT 10000000  // 10 megs default

//最小記憶體,預設為1M

#define LIBLAS_INDEX_MINMEMDEFAULT 1000000   // 1 meg at least has to be allowed

//最大格網數量,不超過25萬個

#define LIBLAS_INDEX_MAXCELLS   250000

//平均每個格網中的點個數,預設值100

#define LIBLAS_INDEX_OPTPTSPERCELL 100

//平均每個格網中最大點數,整個cpp中未找到它的引用,沒用過,沒啥意義

#define LIBLAS_INDEX_MAXPTSPERCELL 1000

 

索引部分主要有兩個類,IndexData、Index。IndexData為Index提供索引的相關參數,構建索引前必須構建IndexData對象。IndexData對象參數值的設定直接關係到Index對象索引的構建情況。

 

(1)構建IndexData 對象

IndexData類提供了三個建構函式,無參、拷貝建構函式、Index對象初始化函數。由於Index和IndexData對象中有相同屬性:m_reader等,所以可以相互初始化這些屬性。

(2)設定索引構建參數

liblas提供了多個參數設定函數。SetInitialValues可以設定所有參數,函數原型

bool SetInitialValues(std::istream *ifs = 0, Reader*reader = 0, std::ostream *ofs = 0, Reader *idxreader = 0,

       const char *tmpfilenme = 0, constchar *indexauthor = 0,

       const char *indexcomment = 0, constchar *indexdate = 0,doublezbinht = 0.0,

       boost::uint32_t maxmem =LIBLAS_INDEX_MAXMEMDEFAULT, intdebugoutputlevel = 0, bool readonly = 0,

       boolwritestandaloneindex = 0,bool forcenewindex =0, FILE *debugger = 0);

ifs:輸入的las檔案;reader:輸入檔案對應的Reader對象;ofs:輸出檔案,如果設定索引為單獨檔案則此為輸出的索引檔案,如果設定索引包含在源las檔案中,則會建立一個新檔案,該檔案包含索引+源las檔案。tmpfilenme:新檔案的名字;indexauthor、indexcomment、indexdate:索引檔案的一些基本資料;

zbinht:Z方向的格網大小;maxmen:記憶體限制;debugoutputlevel:調試資訊輸出層級;writestandaloneindex:為1,則會將索引檔案單獨作為一個檔案,為0則索引檔案跟源las檔案為一個檔案;forcenewindex:如果為1,則不管是否存在索引檔案,均會建立索引,若為0,則已存在索引時不會重建;

(3)構建Index對象

liblas::IndexindexPt(indexData);

(4)設定查詢器

indexData.SetFilterValues(dftXMin,dftXMax,dftYMin,dftYMax,dftZMin,dftZMax,indexPt);

(5)執行查詢

constvector<boost::uint32_t> resultPtsIDVec = indexPt.Filter(indexData);

代碼

        const char *pSrcFileName = "D:\\pipeline_5G.las";const char *pIndexTempFilePath = "D:\\temp_index";const char *pTempFileName = "IndexTemp";//const char *pDesFileName = "D:\\dem.tif";std::ifstream ifs;ifs.open(pSrcFileName, std::ios::in | std::ios::binary);if (ifs == NULL){cout<<"null"<<endl;}std::ofstream ofs;ofs.open(pIndexTempFilePath, std::ios::out | std ::ios ::binary);//std::ifstream ifsIndex;//ifsIndex.open(pIndexFilePath, std::ios::in | std::ios::binary);liblas::ReaderFactory f ;liblas::Reader reader = f.CreateWithStream(ifs);//liblas::Reader readerID = f.CreateWithStream(ifsIndex);liblas::Header const& header = reader.GetHeader();printf("Points count: %d\n",header.GetPointRecordsCount());//計算最大最小值   double  dXMin = header.GetMinX();  double  dXMax = header.GetMaxX();  double  dYMin = header.GetMinY();  double  dYMax = header.GetMaxY();  double  dZMin = header.GetMinZ();  double  dZMax = header.GetMaxZ();  const char *pIndexAut = "ryb";const char *pIndexComm = "test1";const char *pIndexDate = "20140923"; liblas::IndexData indexData;indexData.SetInitialValues(&ifs,&reader,&ofs,NULL,pTempFileName,pIndexAut,pIndexComm,pIndexDate,0,1000000000U,2,false,false,false,0);indexData.SetBuildEmbedValues(&reader,&ofs,pTempFileName,pIndexAut,pIndexComm,pIndexDate,0,100000000U,2,0);//設定索引檔案包含於las檔案中liblas::Index indexPt(indexData);cout<<"Cell size is X:"<<indexPt.GetCellsX()<<" Y "<<indexPt.GetCellsY()<<" Z "<<indexPt.GetCellsZ()<<endl;double dftXMin = dXMin;double dftXMax = dXMax;double dftYMin = dYMin + 500;double dftYMax = dYMax - 220;double dftZMax = dZMax - 100;double dftZMin = dZMin + 20;indexData.SetFilterValues(dftXMin,dftXMax,dftYMin,dftYMax,dftZMin,dftZMax,indexPt);const vector<boost::uint32_t> resultPtsIDVec = indexPt.Filter(indexData);double tt21 = MPI_Wtime();cout<<resultPtsIDVec.size()<<endl;





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.