Compressing georeferenced images Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How to digitize polygons from georeferenced raster fileIllustrator to QGIS workflow for vectorsRaster diff: how to check if images have identical values?What causes wrong placement of JPGs in QGIS 2.8.1?World file in georeferenced file does not work in QGIS?Compressing raster using PyQGIS?Reducing File Size without losing qualityEditing/adding GCPs using QGIS?Geo-referenced UAV image does not align with Sentinel-2Adding compression variable to CopyRaster_management for TIFF Raster Dataset?

Is the argument below valid?

Is there any avatar supposed to be born between the death of Krishna and the birth of Kalki?

Single word antonym of "flightless"

Do I really need recursive chmod to restrict access to a folder?

How to find all the available tools in macOS terminal?

Were Kohanim forbidden from serving in King David's army?

Why does Python start at index -1 when indexing a list from the end?

When to stop saving and start investing?

What would be the ideal power source for a cybernetic eye?

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

Why is "Captain Marvel" translated as male in Portugal?

What is the correct way to use the pinch test for dehydration?

Should I call the interviewer directly, if HR aren't responding?

Is the address of a local variable a constexpr?

How to motivate offshore teams and trust them to deliver?

What is this single-engine low-wing propeller plane?

Why did the IBM 650 use bi-quinary?

Sorting numerically

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

I am not a queen, who am I?

Is it true that "carbohydrates are of no use for the basal metabolic need"?

Proof involving the spectral radius and the Jordan canonical form

When -s is used with third person singular. What's its use in this context?

What causes the vertical darker bands in my photo?



Compressing georeferenced images



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How to digitize polygons from georeferenced raster fileIllustrator to QGIS workflow for vectorsRaster diff: how to check if images have identical values?What causes wrong placement of JPGs in QGIS 2.8.1?World file in georeferenced file does not work in QGIS?Compressing raster using PyQGIS?Reducing File Size without losing qualityEditing/adding GCPs using QGIS?Geo-referenced UAV image does not align with Sentinel-2Adding compression variable to CopyRaster_management for TIFF Raster Dataset?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a bunch of georeferenced TIFF images created in QGIS. The person creating them saved them as uncompressed (around 1 GB each).
I would like to compress them as LZW to save space.



How can I do that in a programmatic way (e.g. batch)?



I am open to QGIS or R approches. Please consider I do not know how Georeferencing information are attached to an image (e.g. I have seen somewhere references to a world file, but I do not know what it is).










share|improve this question



















  • 2





    TIFF files can be georeferenced in one of two ways: (1) Georeferencing information is embedded in the TIFF file as part of the metadata, so you only have one file, with the extension .tif or .tiff. (2) Georeferencing information is written in a second, ("sidecar") file with the extension .tfw, alongside the TIFF file. If you want more information about how georeferencing info is attached to a tiff file, read this Wikipedia article.

    – csk
    14 hours ago

















1















I have a bunch of georeferenced TIFF images created in QGIS. The person creating them saved them as uncompressed (around 1 GB each).
I would like to compress them as LZW to save space.



How can I do that in a programmatic way (e.g. batch)?



I am open to QGIS or R approches. Please consider I do not know how Georeferencing information are attached to an image (e.g. I have seen somewhere references to a world file, but I do not know what it is).










share|improve this question



















  • 2





    TIFF files can be georeferenced in one of two ways: (1) Georeferencing information is embedded in the TIFF file as part of the metadata, so you only have one file, with the extension .tif or .tiff. (2) Georeferencing information is written in a second, ("sidecar") file with the extension .tfw, alongside the TIFF file. If you want more information about how georeferencing info is attached to a tiff file, read this Wikipedia article.

    – csk
    14 hours ago













1












1








1








I have a bunch of georeferenced TIFF images created in QGIS. The person creating them saved them as uncompressed (around 1 GB each).
I would like to compress them as LZW to save space.



How can I do that in a programmatic way (e.g. batch)?



I am open to QGIS or R approches. Please consider I do not know how Georeferencing information are attached to an image (e.g. I have seen somewhere references to a world file, but I do not know what it is).










share|improve this question
















I have a bunch of georeferenced TIFF images created in QGIS. The person creating them saved them as uncompressed (around 1 GB each).
I would like to compress them as LZW to save space.



How can I do that in a programmatic way (e.g. batch)?



I am open to QGIS or R approches. Please consider I do not know how Georeferencing information are attached to an image (e.g. I have seen somewhere references to a world file, but I do not know what it is).







qgis r georeferencing compression






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 14 hours ago









Vince

14.8k32850




14.8k32850










asked 14 hours ago









FilippoFilippo

7918




7918







  • 2





    TIFF files can be georeferenced in one of two ways: (1) Georeferencing information is embedded in the TIFF file as part of the metadata, so you only have one file, with the extension .tif or .tiff. (2) Georeferencing information is written in a second, ("sidecar") file with the extension .tfw, alongside the TIFF file. If you want more information about how georeferencing info is attached to a tiff file, read this Wikipedia article.

    – csk
    14 hours ago












  • 2





    TIFF files can be georeferenced in one of two ways: (1) Georeferencing information is embedded in the TIFF file as part of the metadata, so you only have one file, with the extension .tif or .tiff. (2) Georeferencing information is written in a second, ("sidecar") file with the extension .tfw, alongside the TIFF file. If you want more information about how georeferencing info is attached to a tiff file, read this Wikipedia article.

    – csk
    14 hours ago







2




2





TIFF files can be georeferenced in one of two ways: (1) Georeferencing information is embedded in the TIFF file as part of the metadata, so you only have one file, with the extension .tif or .tiff. (2) Georeferencing information is written in a second, ("sidecar") file with the extension .tfw, alongside the TIFF file. If you want more information about how georeferencing info is attached to a tiff file, read this Wikipedia article.

– csk
14 hours ago





TIFF files can be georeferenced in one of two ways: (1) Georeferencing information is embedded in the TIFF file as part of the metadata, so you only have one file, with the extension .tif or .tiff. (2) Georeferencing information is written in a second, ("sidecar") file with the extension .tfw, alongside the TIFF file. If you want more information about how georeferencing info is attached to a tiff file, read this Wikipedia article.

– csk
14 hours ago










2 Answers
2






active

oldest

votes


















2














You can do this using the command line tool gdal_translate. This is available for Windows, Linux, and Mac OSs (you don't state your OS).



Running:



gdalinfo none.tif


will show the info on the file, including the compression type and the locations:



Driver: GTiff/GeoTIFF
Files: none.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 96.5464352, 17.5351143) ( 96d32'47.17"E, 17d32' 6.41"N)
Lower Left ( 96.5464352, 16.5110349) ( 96d32'47.17"E, 16d30'39.73"N)
Upper Right ( 97.4627168, 17.5351143) ( 97d27'45.78"E, 17d32' 6.41"N)
Lower Right ( 97.4627168, 16.5110349) ( 97d27'45.78"E, 16d30'39.73"N)
Center ( 97.0045760, 17.0230746) ( 97d 0'16.47"E, 17d 1'23.07"N)
[etc]


it doesn't mention a compression type, because it doesn't have one. If your GeoTIFFs aren't compressed they should also not say anything. Note the spatial information is stored in geoTIFF chunks and is output as a bounding box corner set. Great.



Let's compress it. Uncompressed file is 4.7Mb:



$ ls -hs none.tif 
4.7M none.tif


Run this:



$ gdal_translate none.tif lzw.tif -co COMPRESS=LZW
Input file size is 204, 228
0...10...20...30...40...50...60...70...80...90...100 - done.


and get



$ ls -hs lzw.tif 
1.6M lzw.tif


1.6Mbytes in LZW compressed form. Again gdalinfo shows:



$ gdalinfo lzw.tif 
Driver: GTiff/GeoTIFF
Files: lzw.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=PIXEL
Corner Coordinates:
[etc]


Note the COMPRESSION=LZW message.



Loop over your files using your command line interpreter loop functions.



You might also be able to do this via the gdalUtils package in R which will run these command line commands via a shell.



Indeed for my test file:



library(gdalUtils)
gdal_translate(
src_dataset="none.tif",
dst_dataset="lzwR.tif",
co="COMPRESS=LZW")


results in a byte-for-byte identical output file.






share|improve this answer




















  • 1





    some other -co to consider and offers additional compression (lossless) are -mo "INTERLEAVE=PIXEL" -co "INTERLEAVE=PIXEL" -co "TILED=YES" -co "COMPRESS=LZW" -co "PREDICTOR=2"

    – SaultDon
    11 hours ago


















2














In addition to @Spacedman's answer, you can set up a loop in R to compress tiffs using LZW with the writeRaster function in the raster package, which still uses GDAL. The options argument allows you to apply LZW compression.



In this example, the file is not overwritten but rather has an "_LZW" appended to the original name. To just overwrite the original file you can omit the paste0 function in writeRaster and just use the file iterator (ie., rfiles[i]). You could also paste a directory path into the file name to aim the compressed files to a different directory. If the tif files are multi-band then you would use stack rather than raster to read the data.



library(raster)
setwd("C:/...")
rfiles <- list.files(getwd(), "tif$")
for(i in 1:length(rfiles))
r <- raster::raster(rfiles[i])
raster::writeRaster(r, paste0(gsub(pattern = "\.tif$", "",
rfiles[i]), "_LZW", ".tif"), overwrite=TRUE,
options="COMPRESS=LZW")






share|improve this answer























  • Thanks Jeffrey Evans and @Spacedman. Just for clarity. I assume that an image georeferenced in qgis and saved as .tif is a geoTif. is this correct? if not... will the solutions you both proposed work anyway?

    – Filippo
    12 hours ago











  • I'd be concerned that this would read in the entire +1Gb files. Might not be too efficient. The GDAL command line routines are pretty well optimised.

    – Spacedman
    12 hours ago











  • A "geoTIFF" is a TIFF with special metadata blocks in it that give it a spatial reference. Rasters saved from QGIS should have this data and so be valid geoTIFFs - check with the gdalinfo command line or gdalUtils package.

    – Spacedman
    12 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318858%2fcompressing-georeferenced-images%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can do this using the command line tool gdal_translate. This is available for Windows, Linux, and Mac OSs (you don't state your OS).



Running:



gdalinfo none.tif


will show the info on the file, including the compression type and the locations:



Driver: GTiff/GeoTIFF
Files: none.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 96.5464352, 17.5351143) ( 96d32'47.17"E, 17d32' 6.41"N)
Lower Left ( 96.5464352, 16.5110349) ( 96d32'47.17"E, 16d30'39.73"N)
Upper Right ( 97.4627168, 17.5351143) ( 97d27'45.78"E, 17d32' 6.41"N)
Lower Right ( 97.4627168, 16.5110349) ( 97d27'45.78"E, 16d30'39.73"N)
Center ( 97.0045760, 17.0230746) ( 97d 0'16.47"E, 17d 1'23.07"N)
[etc]


it doesn't mention a compression type, because it doesn't have one. If your GeoTIFFs aren't compressed they should also not say anything. Note the spatial information is stored in geoTIFF chunks and is output as a bounding box corner set. Great.



Let's compress it. Uncompressed file is 4.7Mb:



$ ls -hs none.tif 
4.7M none.tif


Run this:



$ gdal_translate none.tif lzw.tif -co COMPRESS=LZW
Input file size is 204, 228
0...10...20...30...40...50...60...70...80...90...100 - done.


and get



$ ls -hs lzw.tif 
1.6M lzw.tif


1.6Mbytes in LZW compressed form. Again gdalinfo shows:



$ gdalinfo lzw.tif 
Driver: GTiff/GeoTIFF
Files: lzw.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=PIXEL
Corner Coordinates:
[etc]


Note the COMPRESSION=LZW message.



Loop over your files using your command line interpreter loop functions.



You might also be able to do this via the gdalUtils package in R which will run these command line commands via a shell.



Indeed for my test file:



library(gdalUtils)
gdal_translate(
src_dataset="none.tif",
dst_dataset="lzwR.tif",
co="COMPRESS=LZW")


results in a byte-for-byte identical output file.






share|improve this answer




















  • 1





    some other -co to consider and offers additional compression (lossless) are -mo "INTERLEAVE=PIXEL" -co "INTERLEAVE=PIXEL" -co "TILED=YES" -co "COMPRESS=LZW" -co "PREDICTOR=2"

    – SaultDon
    11 hours ago















2














You can do this using the command line tool gdal_translate. This is available for Windows, Linux, and Mac OSs (you don't state your OS).



Running:



gdalinfo none.tif


will show the info on the file, including the compression type and the locations:



Driver: GTiff/GeoTIFF
Files: none.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 96.5464352, 17.5351143) ( 96d32'47.17"E, 17d32' 6.41"N)
Lower Left ( 96.5464352, 16.5110349) ( 96d32'47.17"E, 16d30'39.73"N)
Upper Right ( 97.4627168, 17.5351143) ( 97d27'45.78"E, 17d32' 6.41"N)
Lower Right ( 97.4627168, 16.5110349) ( 97d27'45.78"E, 16d30'39.73"N)
Center ( 97.0045760, 17.0230746) ( 97d 0'16.47"E, 17d 1'23.07"N)
[etc]


it doesn't mention a compression type, because it doesn't have one. If your GeoTIFFs aren't compressed they should also not say anything. Note the spatial information is stored in geoTIFF chunks and is output as a bounding box corner set. Great.



Let's compress it. Uncompressed file is 4.7Mb:



$ ls -hs none.tif 
4.7M none.tif


Run this:



$ gdal_translate none.tif lzw.tif -co COMPRESS=LZW
Input file size is 204, 228
0...10...20...30...40...50...60...70...80...90...100 - done.


and get



$ ls -hs lzw.tif 
1.6M lzw.tif


1.6Mbytes in LZW compressed form. Again gdalinfo shows:



$ gdalinfo lzw.tif 
Driver: GTiff/GeoTIFF
Files: lzw.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=PIXEL
Corner Coordinates:
[etc]


Note the COMPRESSION=LZW message.



Loop over your files using your command line interpreter loop functions.



You might also be able to do this via the gdalUtils package in R which will run these command line commands via a shell.



Indeed for my test file:



library(gdalUtils)
gdal_translate(
src_dataset="none.tif",
dst_dataset="lzwR.tif",
co="COMPRESS=LZW")


results in a byte-for-byte identical output file.






share|improve this answer




















  • 1





    some other -co to consider and offers additional compression (lossless) are -mo "INTERLEAVE=PIXEL" -co "INTERLEAVE=PIXEL" -co "TILED=YES" -co "COMPRESS=LZW" -co "PREDICTOR=2"

    – SaultDon
    11 hours ago













2












2








2







You can do this using the command line tool gdal_translate. This is available for Windows, Linux, and Mac OSs (you don't state your OS).



Running:



gdalinfo none.tif


will show the info on the file, including the compression type and the locations:



Driver: GTiff/GeoTIFF
Files: none.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 96.5464352, 17.5351143) ( 96d32'47.17"E, 17d32' 6.41"N)
Lower Left ( 96.5464352, 16.5110349) ( 96d32'47.17"E, 16d30'39.73"N)
Upper Right ( 97.4627168, 17.5351143) ( 97d27'45.78"E, 17d32' 6.41"N)
Lower Right ( 97.4627168, 16.5110349) ( 97d27'45.78"E, 16d30'39.73"N)
Center ( 97.0045760, 17.0230746) ( 97d 0'16.47"E, 17d 1'23.07"N)
[etc]


it doesn't mention a compression type, because it doesn't have one. If your GeoTIFFs aren't compressed they should also not say anything. Note the spatial information is stored in geoTIFF chunks and is output as a bounding box corner set. Great.



Let's compress it. Uncompressed file is 4.7Mb:



$ ls -hs none.tif 
4.7M none.tif


Run this:



$ gdal_translate none.tif lzw.tif -co COMPRESS=LZW
Input file size is 204, 228
0...10...20...30...40...50...60...70...80...90...100 - done.


and get



$ ls -hs lzw.tif 
1.6M lzw.tif


1.6Mbytes in LZW compressed form. Again gdalinfo shows:



$ gdalinfo lzw.tif 
Driver: GTiff/GeoTIFF
Files: lzw.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=PIXEL
Corner Coordinates:
[etc]


Note the COMPRESSION=LZW message.



Loop over your files using your command line interpreter loop functions.



You might also be able to do this via the gdalUtils package in R which will run these command line commands via a shell.



Indeed for my test file:



library(gdalUtils)
gdal_translate(
src_dataset="none.tif",
dst_dataset="lzwR.tif",
co="COMPRESS=LZW")


results in a byte-for-byte identical output file.






share|improve this answer















You can do this using the command line tool gdal_translate. This is available for Windows, Linux, and Mac OSs (you don't state your OS).



Running:



gdalinfo none.tif


will show the info on the file, including the compression type and the locations:



Driver: GTiff/GeoTIFF
Files: none.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 96.5464352, 17.5351143) ( 96d32'47.17"E, 17d32' 6.41"N)
Lower Left ( 96.5464352, 16.5110349) ( 96d32'47.17"E, 16d30'39.73"N)
Upper Right ( 97.4627168, 17.5351143) ( 97d27'45.78"E, 17d32' 6.41"N)
Lower Right ( 97.4627168, 16.5110349) ( 97d27'45.78"E, 16d30'39.73"N)
Center ( 97.0045760, 17.0230746) ( 97d 0'16.47"E, 17d 1'23.07"N)
[etc]


it doesn't mention a compression type, because it doesn't have one. If your GeoTIFFs aren't compressed they should also not say anything. Note the spatial information is stored in geoTIFF chunks and is output as a bounding box corner set. Great.



Let's compress it. Uncompressed file is 4.7Mb:



$ ls -hs none.tif 
4.7M none.tif


Run this:



$ gdal_translate none.tif lzw.tif -co COMPRESS=LZW
Input file size is 204, 228
0...10...20...30...40...50...60...70...80...90...100 - done.


and get



$ ls -hs lzw.tif 
1.6M lzw.tif


1.6Mbytes in LZW compressed form. Again gdalinfo shows:



$ gdalinfo lzw.tif 
Driver: GTiff/GeoTIFF
Files: lzw.tif
Size is 204, 228
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (96.546435160745574,17.535114346013060)
Pixel Size = (0.004491576420598,-0.004491576420598)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=PIXEL
Corner Coordinates:
[etc]


Note the COMPRESSION=LZW message.



Loop over your files using your command line interpreter loop functions.



You might also be able to do this via the gdalUtils package in R which will run these command line commands via a shell.



Indeed for my test file:



library(gdalUtils)
gdal_translate(
src_dataset="none.tif",
dst_dataset="lzwR.tif",
co="COMPRESS=LZW")


results in a byte-for-byte identical output file.







share|improve this answer














share|improve this answer



share|improve this answer








edited 13 hours ago

























answered 13 hours ago









SpacedmanSpacedman

25k23551




25k23551







  • 1





    some other -co to consider and offers additional compression (lossless) are -mo "INTERLEAVE=PIXEL" -co "INTERLEAVE=PIXEL" -co "TILED=YES" -co "COMPRESS=LZW" -co "PREDICTOR=2"

    – SaultDon
    11 hours ago












  • 1





    some other -co to consider and offers additional compression (lossless) are -mo "INTERLEAVE=PIXEL" -co "INTERLEAVE=PIXEL" -co "TILED=YES" -co "COMPRESS=LZW" -co "PREDICTOR=2"

    – SaultDon
    11 hours ago







1




1





some other -co to consider and offers additional compression (lossless) are -mo "INTERLEAVE=PIXEL" -co "INTERLEAVE=PIXEL" -co "TILED=YES" -co "COMPRESS=LZW" -co "PREDICTOR=2"

– SaultDon
11 hours ago





some other -co to consider and offers additional compression (lossless) are -mo "INTERLEAVE=PIXEL" -co "INTERLEAVE=PIXEL" -co "TILED=YES" -co "COMPRESS=LZW" -co "PREDICTOR=2"

– SaultDon
11 hours ago













2














In addition to @Spacedman's answer, you can set up a loop in R to compress tiffs using LZW with the writeRaster function in the raster package, which still uses GDAL. The options argument allows you to apply LZW compression.



In this example, the file is not overwritten but rather has an "_LZW" appended to the original name. To just overwrite the original file you can omit the paste0 function in writeRaster and just use the file iterator (ie., rfiles[i]). You could also paste a directory path into the file name to aim the compressed files to a different directory. If the tif files are multi-band then you would use stack rather than raster to read the data.



library(raster)
setwd("C:/...")
rfiles <- list.files(getwd(), "tif$")
for(i in 1:length(rfiles))
r <- raster::raster(rfiles[i])
raster::writeRaster(r, paste0(gsub(pattern = "\.tif$", "",
rfiles[i]), "_LZW", ".tif"), overwrite=TRUE,
options="COMPRESS=LZW")






share|improve this answer























  • Thanks Jeffrey Evans and @Spacedman. Just for clarity. I assume that an image georeferenced in qgis and saved as .tif is a geoTif. is this correct? if not... will the solutions you both proposed work anyway?

    – Filippo
    12 hours ago











  • I'd be concerned that this would read in the entire +1Gb files. Might not be too efficient. The GDAL command line routines are pretty well optimised.

    – Spacedman
    12 hours ago











  • A "geoTIFF" is a TIFF with special metadata blocks in it that give it a spatial reference. Rasters saved from QGIS should have this data and so be valid geoTIFFs - check with the gdalinfo command line or gdalUtils package.

    – Spacedman
    12 hours ago















2














In addition to @Spacedman's answer, you can set up a loop in R to compress tiffs using LZW with the writeRaster function in the raster package, which still uses GDAL. The options argument allows you to apply LZW compression.



In this example, the file is not overwritten but rather has an "_LZW" appended to the original name. To just overwrite the original file you can omit the paste0 function in writeRaster and just use the file iterator (ie., rfiles[i]). You could also paste a directory path into the file name to aim the compressed files to a different directory. If the tif files are multi-band then you would use stack rather than raster to read the data.



library(raster)
setwd("C:/...")
rfiles <- list.files(getwd(), "tif$")
for(i in 1:length(rfiles))
r <- raster::raster(rfiles[i])
raster::writeRaster(r, paste0(gsub(pattern = "\.tif$", "",
rfiles[i]), "_LZW", ".tif"), overwrite=TRUE,
options="COMPRESS=LZW")






share|improve this answer























  • Thanks Jeffrey Evans and @Spacedman. Just for clarity. I assume that an image georeferenced in qgis and saved as .tif is a geoTif. is this correct? if not... will the solutions you both proposed work anyway?

    – Filippo
    12 hours ago











  • I'd be concerned that this would read in the entire +1Gb files. Might not be too efficient. The GDAL command line routines are pretty well optimised.

    – Spacedman
    12 hours ago











  • A "geoTIFF" is a TIFF with special metadata blocks in it that give it a spatial reference. Rasters saved from QGIS should have this data and so be valid geoTIFFs - check with the gdalinfo command line or gdalUtils package.

    – Spacedman
    12 hours ago













2












2








2







In addition to @Spacedman's answer, you can set up a loop in R to compress tiffs using LZW with the writeRaster function in the raster package, which still uses GDAL. The options argument allows you to apply LZW compression.



In this example, the file is not overwritten but rather has an "_LZW" appended to the original name. To just overwrite the original file you can omit the paste0 function in writeRaster and just use the file iterator (ie., rfiles[i]). You could also paste a directory path into the file name to aim the compressed files to a different directory. If the tif files are multi-band then you would use stack rather than raster to read the data.



library(raster)
setwd("C:/...")
rfiles <- list.files(getwd(), "tif$")
for(i in 1:length(rfiles))
r <- raster::raster(rfiles[i])
raster::writeRaster(r, paste0(gsub(pattern = "\.tif$", "",
rfiles[i]), "_LZW", ".tif"), overwrite=TRUE,
options="COMPRESS=LZW")






share|improve this answer













In addition to @Spacedman's answer, you can set up a loop in R to compress tiffs using LZW with the writeRaster function in the raster package, which still uses GDAL. The options argument allows you to apply LZW compression.



In this example, the file is not overwritten but rather has an "_LZW" appended to the original name. To just overwrite the original file you can omit the paste0 function in writeRaster and just use the file iterator (ie., rfiles[i]). You could also paste a directory path into the file name to aim the compressed files to a different directory. If the tif files are multi-band then you would use stack rather than raster to read the data.



library(raster)
setwd("C:/...")
rfiles <- list.files(getwd(), "tif$")
for(i in 1:length(rfiles))
r <- raster::raster(rfiles[i])
raster::writeRaster(r, paste0(gsub(pattern = "\.tif$", "",
rfiles[i]), "_LZW", ".tif"), overwrite=TRUE,
options="COMPRESS=LZW")







share|improve this answer












share|improve this answer



share|improve this answer










answered 13 hours ago









Jeffrey EvansJeffrey Evans

22.2k22870




22.2k22870












  • Thanks Jeffrey Evans and @Spacedman. Just for clarity. I assume that an image georeferenced in qgis and saved as .tif is a geoTif. is this correct? if not... will the solutions you both proposed work anyway?

    – Filippo
    12 hours ago











  • I'd be concerned that this would read in the entire +1Gb files. Might not be too efficient. The GDAL command line routines are pretty well optimised.

    – Spacedman
    12 hours ago











  • A "geoTIFF" is a TIFF with special metadata blocks in it that give it a spatial reference. Rasters saved from QGIS should have this data and so be valid geoTIFFs - check with the gdalinfo command line or gdalUtils package.

    – Spacedman
    12 hours ago

















  • Thanks Jeffrey Evans and @Spacedman. Just for clarity. I assume that an image georeferenced in qgis and saved as .tif is a geoTif. is this correct? if not... will the solutions you both proposed work anyway?

    – Filippo
    12 hours ago











  • I'd be concerned that this would read in the entire +1Gb files. Might not be too efficient. The GDAL command line routines are pretty well optimised.

    – Spacedman
    12 hours ago











  • A "geoTIFF" is a TIFF with special metadata blocks in it that give it a spatial reference. Rasters saved from QGIS should have this data and so be valid geoTIFFs - check with the gdalinfo command line or gdalUtils package.

    – Spacedman
    12 hours ago
















Thanks Jeffrey Evans and @Spacedman. Just for clarity. I assume that an image georeferenced in qgis and saved as .tif is a geoTif. is this correct? if not... will the solutions you both proposed work anyway?

– Filippo
12 hours ago





Thanks Jeffrey Evans and @Spacedman. Just for clarity. I assume that an image georeferenced in qgis and saved as .tif is a geoTif. is this correct? if not... will the solutions you both proposed work anyway?

– Filippo
12 hours ago













I'd be concerned that this would read in the entire +1Gb files. Might not be too efficient. The GDAL command line routines are pretty well optimised.

– Spacedman
12 hours ago





I'd be concerned that this would read in the entire +1Gb files. Might not be too efficient. The GDAL command line routines are pretty well optimised.

– Spacedman
12 hours ago













A "geoTIFF" is a TIFF with special metadata blocks in it that give it a spatial reference. Rasters saved from QGIS should have this data and so be valid geoTIFFs - check with the gdalinfo command line or gdalUtils package.

– Spacedman
12 hours ago





A "geoTIFF" is a TIFF with special metadata blocks in it that give it a spatial reference. Rasters saved from QGIS should have this data and so be valid geoTIFFs - check with the gdalinfo command line or gdalUtils package.

– Spacedman
12 hours ago

















draft saved

draft discarded
















































Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318858%2fcompressing-georeferenced-images%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







-compression, georeferencing, qgis, r

Popular posts from this blog

Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

My Life (Mary J. Blige album) Contents Background Critical reception Accolades Commercial performance Track listing Personnel Charts Certifications See also References External links Navigation menu"1. Mary J Blige, My Life - The 50 Best R&B albums of the '90s""American album certifications – Mary J. Blige – My Life""Mary J. Blige's My Life LP (1994) revisited with co-producer Chucky Thompson | Return To The Classics"the original"Key Tracks: Mary J. Blige's My Life""My Life – Mary J. Blige""Worth The Wait""My Life""Forget '411,' Mary J., Better Call 911""Spins"My Life AccoladesThe 500 Greatest Albums of All TimeTime's All-TIME 100 Albums"Top RPM Albums: Issue chartid""Dutchcharts.nl – Mary J. Blige – My Life""Mary J. Blige | Artist | Official Charts""Mary J. Blige Chart History (Billboard 200)""Mary J. Blige Chart History (Top R&B/Hip-Hop Albums)""Canadian album certifications – Mary J Blige – My Life""British album certifications – Mary J Blige – My Life""American album certifications – Mary J Blige – My Life"My LifeMy Life accoladesee

Frič See also Navigation menuinternal link