3

I have a large number of .asc DSM files which I'd like like to lower the vertical resolution for by two decimal places, preferably using a batch operation. I'm hoping this will reduce storage capacity needed and help speed up geoprocessing. Is there any way I can do this either in QGIS or windows command prompt?

To clarify: As an example, I'd like to go from a vertical reading of 1.161 to 1.2 (random raster cell example).

user77875
  • 906
  • 1
  • 6
  • 9
  • 1
    I didn't see your edit soon enough so i answered a bit differently. My method converts your data from float to integer, which is a good way to make data smaller and easier to manage. I'm not sure going from 1.161 to 1.2 will really change much. If really you want to do that, use a round() function, maybe, but i doubt it will change anything. – gisnside Aug 28 '17 at 20:00
  • Seems a bit similar to this one : https://gis.stackexchange.com/questions/146543/how-to-round-pixel-values-of-a-raster-in-qgis – gisnside Aug 28 '17 at 20:08
  • 2
    ASCII is the 2nd worst image format that I've used (Gridded XYZ is the worst) for gobbling up disc space.. May I suggest you convert to a binary format, like ERDAS Img or GeoTIFF (can include lossless compression); Is there a reason for maintaining your images as ASCII raster? Do you have any python skills? What GDAL version does your QGIS use? https://gis.stackexchange.com/questions/86296/how-do-i-check-which-version-of-gdal-i-have-and-how-many – Michael Stimson Aug 28 '17 at 20:56
  • Will see which of the two options (possibly a combination of both -?) reduces file sizes the most. Not tied to ASCII in any way so will try converting to a GeoTIFF. Would like to keep the 1 decimal place if possible, so integer isn't really an option. Had no idea you could batch process on raster calculator - good to know and should make things faster. Will report back on file size reduction! – user77875 Aug 28 '17 at 21:12
  • 1
    Depending on your GDAL version you can export AAIGRID (Esri ASCII) with the switch DECIMAL_PRECISION=1 to round the ASCII files as a batch operation; I would use python to seek out the files in a folder structure (os.walk()) which would save having to find them all. Another way to do the same is to use a command window and execute the command DIR *.ASC /B /S > C:\SOME\PATH\List.txt to get a list of all the ASCII files (full path) and write it to a list txt file.. One of those two options might save you some time when you get into it. – Michael Stimson Aug 28 '17 at 21:21
  • 1
    @user77875 " Would like to keep the 1 decimal place if possible" : is there a reason to stay in a float format ? Please note you don't loose data following my answer : you can still revert to your original float data at the end of your calculations by dividing the final results by a 10 factor * the number of decimal you rounded to. Exemple :if you go from 1.161 to 1161 in integer, it keeps the 3 decimals but reduce the data cost If you use a Erdas img, with the right settings, you can reduce even more the cost ;) – gisnside Aug 29 '17 at 05:28
  • Michael - I have version 2.1.2 according to OSGeo4W shell. I'm not sure where you're suggesting I'd run the export from (a processing tool or a script)? I've tried a Save As and the resulting GeoTIFF file was pretty much the same size as an ASCII (!) – user77875 Aug 29 '17 at 12:27
  • gisnside - It's data that will be shared among colleagues so both the file and data format have to be both obvious; ie data normally comes in meters so should remain in meters (it just doesn't need the vertical resolution), and has to have a commonly used file format internally that will allow for geoprocessing without conversion (eg in Arc & QGIS). – user77875 Aug 29 '17 at 12:30
  • @user77875 OK, I see now :) Thanks for your answer. – gisnside Aug 31 '17 at 09:33

1 Answers1

3

The basic trick in this method is to use a Raster Calculator to multiply your raster by 100 then turn it from float to integer by specifying Int16 or Int32 in the output format. It should considerably decrease the size of your data.

You can use the GDAL calculator + batch process

batch gdal calculator

Or via the interface (button upper right)

raster calculator

Batch calculate

gisnside
  • 7,818
  • 2
  • 29
  • 73
  • For keeping more decimals, just multiply by the number of decimals you need 10 (10 for 1.2 > 12, 100 for 1.23 > 123, 1000 for 1.234 > 1234 for example) – gisnside Aug 28 '17 at 20:02
  • To go back to your original data, just divide by the number you used to multiply. – gisnside Aug 29 '17 at 05:29