[gdal-dev] Convert VRT+JPEG with gdalwarp

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] Convert VRT+JPEG with gdalwarp

kalevj
Hello,

I used gdalwarp to transform a VRT+JPEG pair from one EPSG projection to
another. Everything worked well. This conversion changed the VRT file so
that reprojection takes place when the images are loaded. However, I would
need to reproject the JPEG so that there would not be a need to reproject
every time the images are loaded. Is it possible somehow?

I used the command:
"gdalwarp -s_srs EPSG:2006 -t_srs EPSG:3857 -of VRT -r near old.vrt new.vrt"

Thanks!

Kalev



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Convert VRT+JPEG with gdalwarp

Doug Newcomb-2
Kalev,
Just set the output file format to -f  JPEG format   ( .jpg) or  -f JP2OpenJPEG (.jp2)

The JPEG format will be lossey by default.  Is that what you want?
See:


Doug

On Thu, Jun 21, 2018 at 10:00 AM kalevj <[hidden email]> wrote:
Hello,

I used gdalwarp to transform a VRT+JPEG pair from one EPSG projection to
another. Everything worked well. This conversion changed the VRT file so
that reprojection takes place when the images are loaded. However, I would
need to reproject the JPEG so that there would not be a need to reproject
every time the images are loaded. Is it possible somehow?

I used the command:
"gdalwarp -s_srs EPSG:2006 -t_srs EPSG:3857 -of VRT -r near old.vrt new.vrt"

Thanks!

Kalev



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev


--
Doug Newcomb
USFWS
551F Pylon Dr
Raleigh, NC
919-856-4520 ext. 14 [hidden email]
---------------------------------------------------------------------------------------------------------

NOTE: This email correspondence and any attachments to and from this sender is subject to the Freedom of Information Act (FOIA) and may be disclosed to third parties.

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Convert VRT+JPEG with gdalwarp

kalevj

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.

 

It seems that GDAL doesn’t create new JPEG files without having pre-existing JPEG-s to modify. If I try to modify old JPEG, I get a message “Output dataset exists, but cannot be opened in update mode.

 

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)”

 

Kalev

 

From: Doug Newcomb <[hidden email]>
Sent: Thursday, June 21, 2018 5:24 PM
To: Kalev Julge <[hidden email]>
Cc: gdal dev <[hidden email]>
Subject: Re: [EXTERNAL] [gdal-dev] Convert VRT+JPEG with gdalwarp

 

Kalev,

Just set the output file format to -f  JPEG format   ( .jpg) or  -f JP2OpenJPEG (.jp2)

 

The JPEG format will be lossey by default.  Is that what you want?

See:

 

 

Doug

 

On Thu, Jun 21, 2018 at 10:00 AM kalevj <[hidden email]> wrote:

Hello,

I used gdalwarp to transform a VRT+JPEG pair from one EPSG projection to
another. Everything worked well. This conversion changed the VRT file so
that reprojection takes place when the images are loaded. However, I would
need to reproject the JPEG so that there would not be a need to reproject
every time the images are loaded. Is it possible somehow?

I used the command:
"gdalwarp -s_srs EPSG:2006 -t_srs EPSG:3857 -of VRT -r near old.vrt new.vrt"

Thanks!

Kalev



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev


 

--

Doug Newcomb

USFWS

551F Pylon Dr

Raleigh, NC

919-856-4520 ext. 14 [hidden email]

---------------------------------------------------------------------------------------------------------

 

NOTE: This email correspondence and any attachments to and from this sender is subject to the Freedom of Information Act (FOIA) and may be disclosed to third parties.


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Convert VRT+JPEG with gdalwarp

Even Rouault-2
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
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Convert VRT+JPEG with gdalwarp

kalevj
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 <[hidden email]>
Sent: Monday, June 25, 2018 4:30 PM
To: [hidden email]
Cc: Kalev Julge <[hidden email]>; Doug Newcomb <[hidden email]>
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
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Convert VRT+JPEG with gdalwarp

jratike80
In reply to this post by kalevj
kalevj 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.

Hi,

If your datasets are large you should not create plain JPEG files with the
GDAL JPEG driver. Create JPEG compressed tiled GeoTIFFs instead. With JPEG
you must decompress the whole image before you can read a small region of
interest of your image but from tiled GeoTIFF you can access the right tiles
directly. You can read usage examples for example from here
http://blog.cleverelephant.ca/2015/02/geotiff-compression-for-dummies.html.

-Jukka Rahkonen-


 



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev