Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jbants/f8b190f3d567b0f459ac to your computer and use it in GitHub Desktop.
Save jbants/f8b190f3d567b0f459ac to your computer and use it in GitHub Desktop.
Feathering a raster with transparency for display.
Description: This document describes the steps involved for creating a transparent mask around the edges of a raster for display on map or tiling service.
1. Convert the raw raster data to appropriate projection (EPSG: 900913 or EPSG: 3857 for the web) and data format to TIFF.
2. Apply any styling to the raster (colour ramps, discrete colouring, etc...) using mapping software or image editing software. Save as TIFF.
3. Feather transparent edges in GIMP
a. Open the coloured raster in GIMP
b. Use the free select tool (f) to define an area within the raster extents. Ensure there is sufficient raster data outside of the area you define as this will be used to feather the transparency.
c. On the layer menu (with the selection still highlighted), right click your layer and select Add Layer Mask. (At this point you may want to save the image as a gimp image file in case you need to edit is further)
d. A Dialog will open, select Black (full transparency). Select Add. The image on the screen will go fully transparent.
e. Using the toolbox, select the Bucket Fill tool and change the fill colour to white. Click within your selection to make it opaque.
f. Only the selected areas of your image should now be shown. Deselect everything. Select  None
g. From the Filter menu, select blur Gaussian Blur. A dialog will open. Change the horizontal and vertical blur radius to set feathering distance. (500-100 seems to work).
h. Export the image as a TIFF file.
4. Your feathered image does not have any geospatial information attached to it anymore. You will need to define the projection again. (use QGIS, ESRI, gdal)
5. Run gdalinfo <image_name>.tif on your image to ensure that it has an Alpha channel present.
6. You can now compress the image and make it ready for presentation
a. gdal_translate -co COMPRESS=LZW -co ALPHA=YES ./<input_image >.tif ./<output_image>.tif
7. Finished.
a. If editing just an image and you need transparecny, export to gimp, add alpha channel, select by colour and export to new file.
References:
http://gis.stackexchange.com/questions/144535/how-to-create-transparent-hillshade
http://www.gdal.org/gdal_translate.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment