Hello,
Im working a project using gdal to slice TMS style png tiles.  The code 
currently works, but I'm running into some trouble optimizing to run fast 
enough for use on mobile devices.
My current strategy:
Open the source data(currently testing with BSB):
Get the transform, using GDALGetGeoTransform, and get the inverse transform
get coordinate transformers from dataset coordinates to lat/lon
store all that for when tiles are needed

When a tile is needed:
Determine the pixel coordinates of the source data that is needed, taking into 
account a clip line for the data that is not at the edge of the source image.
Create a new VRT using VRTCreate(tileSize, tileSize)
Copy data to the VRT: 
    VRTAddSimpleSource(destBand, sourceBand,
                       sourceDataRegion.origin.x, sourceDataRegion.origin.y,
                       sourceDataRegion.size.width, 
sourceDataRegion.size.height,
                       destDataRegion.origin.x, destDataRegion.origin.y,
                       destDataRegion.size.width,  destDataRegion.size.height,
                       "NEAREST",
                       VRT_NODATA_UNSET
                       );

Create a copy the VRT slice as PNG
  GDALDriverH pngDriver = GDALGetDriverByName("PNG");
  GDALDatasetH pngCopy = GDALCreateCopy(pngDriver, path.UTF8String, 
datasetToWrite, false, NULL, NULL, NULL);
  GDALClose(pngCopy);


Currently GDALCreateCopy is using 70% of the total CPU time

I've tried reusing the same VRT, but did not see a significant speed increase 
from that.

Is there a more CPU efficient way to do this?  Should I be creating a vet of 
the whole dataset warped to the target CRS using GDALAutoCreateWarpedVRT then 
slicing tiles from that?

Any suggestions for optimizing this would be greatly appreciated.

Also see that attached screenshot at 
https://s3.amazonaws.com/com.gaiagps.static/Screenshot_4_9_13_4_58_PM.png for a 
breakdown of CPU usage

Thanks,
Jesse Crocker
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to