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

Kalev Julge kalev.julge at reach-u.com
Tue Jun 26 03:53:26 PDT 2018


Hi Even,

"After your gdalwarp to VRT, do: gdal_translate new.vrt new.jpg -of JPEG"
This suggestion worked well. Thanks!

I have one more issue. I would like to mask off (or make transparent) areas with no data. Originally, I had PNG files that I used as a mask. However, with gdalwarp the dimensions of the image changed slightly, so these PNG masks cannot be used anymore.

So far I've used the following commands:
" //Add reprojection info to VRT
for %N in (C:\....\*.vrt) DO gdalwarp -s_srs "EPSG:2006" -t_srs "EPSG:3857" -of "VRT" -r "bilinear" %N C:\....\out\reprojected_%~nN.vrt
//Reproject JPEG
for %N in (C:\....\out\*.vrt) DO gdal_translate -of "JPEG" %N C:\....\out\%~nN.jpg
//Make new VRT
for %N in (C:\....\out\*.jpg) DO gdal_translate -of "VRT" %N C:\....\out\%~nN.vrt"

I've uploaded an example of the original VRT+JPEG+PNG mask and reprojected VRT+JPEG here:
https://drive.google.com/file/d/1g_Iw6HkY3NSUk7LjzDSPzPjBhtGjbiAW/view?usp=sharing

Any help on how to mask off the areas?
Thanks!

Kalev


-----Original Message-----
From: Even Rouault <even.rouault at spatialys.com> 
Sent: Monday, June 25, 2018 4:30 PM
To: gdal-dev at lists.osgeo.org
Cc: Kalev Julge <kalev.julge at reach-u.com>; Doug Newcomb <doug_newcomb at fws.gov>
Subject: Re: [gdal-dev] [EXTERNAL] Convert VRT+JPEG with gdalwarp

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