Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void generate( GDALDataset *ds)
- {
- int tcount = (1 + abs(tmaxx - tminx))*(1 + abs(tmaxy - tminy));
- GDALDriver* jpegDriver = GetGDALDriverManager()->GetDriverByName("PNG");
- int tz = tmaxz;
- for (int ty = tmaxy; ty >= tminy; ty--)
- {
- #pragma omp parallel for schedule(dynamic, 1)
- for (int tx = tminx; tx <= tmaxx; tx++){
- // TODO tilefilename is exits
- int googleY = (pow(2, tz) - 1) - ty;
- string tileDir = "D:\test2\" + to_string(tz) + "\" + to_string(tx);
- string tilefilename = tileDir + "\" +to_string(googleY) + "." + tileext;
- create_dir(tileDir.c_str());
- Envelope b = mercator->TileBounds(tx, ty, tz);
- int * rwxy;
- rwxy = geo_query(b,querysize);
- int rx, ry, rxsize, rysize, wx, wy, wxsize, wysize;
- rx = *(rwxy+0);
- ry = *(rwxy + 1);
- rxsize = *(rwxy + 2);
- rysize = *(rwxy + 3);
- wx = *(rwxy + 4);
- wy = *(rwxy + 5);
- wxsize = *(rwxy + 6);
- wysize = *(rwxy + 7);
- GDALDataset *dstile;
- char **papszOptions = NULL;
- dstile = mem_drv->Create("temp", tilesize, tilesize, 3, GDT_Byte, papszOptions);
- int bandNum;
- bandNum = ds->GetRasterCount(); //波段数
- bandNum = 3;
- int depth = GDALGetDataTypeSize(ds->GetRasterBand(1)->GetRasterDataType());//8; //图像深度
- size_t imgBufNum = (size_t)wxsize * wysize * bandNum*depth;
- GByte *data = new GByte[imgBufNum];
- ds->RasterIO(GF_Read, rx, ry, rxsize, rysize, data, wxsize, wysize,
- GDT_Byte, bandNum, nullptr, bandNum*depth, wxsize*bandNum*depth, depth);
- if (tilesize == querysize)
- {
- //写入
- dstile->RasterIO(GF_Write, wx, wy, wxsize, wysize, data, wxsize, wysize,
- GDT_Byte, bandNum, nullptr, bandNum*depth, wxsize*bandNum*depth, depth);
- dstile->GetRasterBand(4)->SetNoDataValue(0);
- }
- else
- {
- GDALDataset *dsquery;
- dsquery = mem_drv->Create("temp", querysize, querysize, 3, GDT_Byte, papszOptions);
- dsquery->RasterIO(GF_Write, wx, wy, wxsize, wysize, data, wxsize, wysize,
- GDT_Byte, bandNum, nullptr, bandNum*depth, wxsize*bandNum*depth, depth);
- scale_query_to_tile(dsquery, dstile);
- GDALClose((GDALDatasetH)dsquery);
- }
- delete[] data;
- data = NULL;
- clock_t start, finish;
- start = clock();
- GDALDataset *poDstDS;
- poDstDS = jpegDriver->CreateCopy(tilefilename.c_str(), dstile, FALSE, NULL, NULL, NULL);
- //Once we're done, close properly the dataset */
- if (poDstDS != NULL)
- GDALClose((GDALDatasetH)poDstDS);
- GDALClose((GDALDatasetH)dstile);
- }
- }
- //GetLocalTime(&st);
- }
Add Comment
Please, Sign In to add comment