[gdal-dev] [EXTERNAL] Convert VRT+JPEG with gdalwarp

Even Rouault even.rouault at spatialys.com
Mon Jun 25 06:29:50 PDT 2018


On lundi 25 juin 2018 13:10:16 CEST Kalev Julge wrote:
> Hi Doug,
> 
> Thanks for the info. I know that JPEG is lossy but our datasets are very
> large. That’s why we use JPEG, which is good enough for our needs and the
> file sizes are smaller.

After your gdalwarp to VRT, do:
gdal_translate new.vrt new.jpg -of JPEG

You cannot directly wrap to JPEG, because of the driver limitation
See https://trac.osgeo.org/gdal/wiki/FAQRaster#Whywontgdalwarporgdal_mergewritetomostformats
 
> It seems that GDAL doesn’t create new JPEG files without having pre-existing
> JPEG-s to modify. 

Actually, that's right the opposite :-)

> If I try to modify old JPEG, I get a message “Output
> dataset exists, but cannot be opened in update mode.

That means you cannot modify an existing JPEG. You have to recreate a completely new file.
 
> I also tried using “CreateCopy” but that produced syntax error. Used command
> on GDAL CMD:
 “GDALDriver::CreateCopy ("new.jpg","old.jpg", FALSE, NULL,
> NULL, NULL)” 

The second argument must be a GDALDataset* object, not a string, so do something like

GDALDataset* srcDS = reinterpret_cast<GDALDataset*>(
   GDALOpen("old.jpg", GA_ReadOnly));
GDALDataset* outDS = jpegDriver->CreateCopy(
    "new.jpg", srcDS, FALSE, NULL, NULL, NULL);
GDALClose(outDS);
GDALClose(srcDS);

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list