Guest User

Untitled

a guest
Apr 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. void generate( GDALDataset *ds)
  2. {
  3. int tcount = (1 + abs(tmaxx - tminx))*(1 + abs(tmaxy - tminy));
  4. GDALDriver* jpegDriver = GetGDALDriverManager()->GetDriverByName("PNG");
  5. int tz = tmaxz;
  6. for (int ty = tmaxy; ty >= tminy; ty--)
  7. {
  8. #pragma omp parallel for schedule(dynamic, 1)
  9. for (int tx = tminx; tx <= tmaxx; tx++){
  10.  
  11. // TODO tilefilename is exits
  12. int googleY = (pow(2, tz) - 1) - ty;
  13. string tileDir = "D:\test2\" + to_string(tz) + "\" + to_string(tx);
  14. string tilefilename = tileDir + "\" +to_string(googleY) + "." + tileext;
  15. create_dir(tileDir.c_str());
  16. Envelope b = mercator->TileBounds(tx, ty, tz);
  17. int * rwxy;
  18. rwxy = geo_query(b,querysize);
  19. int rx, ry, rxsize, rysize, wx, wy, wxsize, wysize;
  20. rx = *(rwxy+0);
  21. ry = *(rwxy + 1);
  22. rxsize = *(rwxy + 2);
  23. rysize = *(rwxy + 3);
  24. wx = *(rwxy + 4);
  25. wy = *(rwxy + 5);
  26. wxsize = *(rwxy + 6);
  27. wysize = *(rwxy + 7);
  28.  
  29. GDALDataset *dstile;
  30. char **papszOptions = NULL;
  31. dstile = mem_drv->Create("temp", tilesize, tilesize, 3, GDT_Byte, papszOptions);
  32.  
  33. int bandNum;
  34. bandNum = ds->GetRasterCount(); //波段数
  35. bandNum = 3;
  36. int depth = GDALGetDataTypeSize(ds->GetRasterBand(1)->GetRasterDataType());//8; //图像深度
  37. size_t imgBufNum = (size_t)wxsize * wysize * bandNum*depth;
  38. GByte *data = new GByte[imgBufNum];
  39.  
  40. ds->RasterIO(GF_Read, rx, ry, rxsize, rysize, data, wxsize, wysize,
  41. GDT_Byte, bandNum, nullptr, bandNum*depth, wxsize*bandNum*depth, depth);
  42. if (tilesize == querysize)
  43. {
  44. //写入
  45. dstile->RasterIO(GF_Write, wx, wy, wxsize, wysize, data, wxsize, wysize,
  46. GDT_Byte, bandNum, nullptr, bandNum*depth, wxsize*bandNum*depth, depth);
  47. dstile->GetRasterBand(4)->SetNoDataValue(0);
  48. }
  49. else
  50. {
  51.  
  52.  
  53. GDALDataset *dsquery;
  54. dsquery = mem_drv->Create("temp", querysize, querysize, 3, GDT_Byte, papszOptions);
  55. dsquery->RasterIO(GF_Write, wx, wy, wxsize, wysize, data, wxsize, wysize,
  56. GDT_Byte, bandNum, nullptr, bandNum*depth, wxsize*bandNum*depth, depth);
  57. scale_query_to_tile(dsquery, dstile);
  58. GDALClose((GDALDatasetH)dsquery);
  59.  
  60.  
  61. }
  62.  
  63. delete[] data;
  64. data = NULL;
  65. clock_t start, finish;
  66. start = clock();
  67. GDALDataset *poDstDS;
  68. poDstDS = jpegDriver->CreateCopy(tilefilename.c_str(), dstile, FALSE, NULL, NULL, NULL);
  69. //Once we're done, close properly the dataset */
  70. if (poDstDS != NULL)
  71. GDALClose((GDALDatasetH)poDstDS);
  72. GDALClose((GDALDatasetH)dstile);
  73. }
  74. }
  75. //GetLocalTime(&st);
  76. }
Add Comment
Please, Sign In to add comment