(17) Images clipped by coastlines — GMT 5.1.1 documentation

### Navigation

- index
- next
- previous
- Project Home »
- GMT 5.1.1 documentation »
- The GMT historical collection »
- Search:

# (17) Images clipped by coastlines

This example demonstrates how pscoast can be used to set up clip paths based on coastlines. This approach is well suited when different gridded data sets are to be merged on a plot using different color palette files. Merging the files themselves may not be doable since they may represent different data sets, as we show in this example. Here, we lay down a color map of the geoid field near India with grdimage, use pscoast to set up land clip paths, and then overlay topography from the ETOPO5 data set with another call to grdimage. We finally undo the clippath with a second call to pscoast with the option -Q (Figure [fig:example:sub:17]):

We also plot a color legend on top of the land. So here we basically have three layers of “paint” stacked on top of each other: the underlaying geoid map, the land mask, and finally the color legend. This legend makes clear how grd2cpt distributed the colors over the range: they are not of equal length put are associated with equal amounts of area in the plot. Since the high amounts (in red) are not very prevalent, that color spans a long range.

For this image it is appropriate to use the -I option in psscale so the legend gets shaded, similar to the geoid grid. See Appendix [app:M] to learn more about color palettes and ways to draw color legends.

    #!/bin/bash
    #		GMT EXAMPLE 17
    #
    # Purpose:	Illustrates clipping of images using coastlines
    # GMT progs:	grd2cpt, grdgradient, grdimage, pscoast, pstext
    # Unix progs:	rm
    #
    ps=example_17.ps

    # First generate geoid image w/ shading

    gmt grd2cpt india_geoid.nc -Crainbow > geoid.cpt
    gmt grdgradient india_geoid.nc -Nt1 -A45 -Gindia_geoid_i.nc
    gmt grdimage india_geoid.nc -Iindia_geoid_i.nc -JM6.5i -Cgeoid.cpt -P -K > $ps

    # Then use gmt pscoast to initiate clip path for land

    gmt pscoast -Rindia_geoid.nc -J -O -K -Dl -Gc >> $ps

    # Now generate topography image w/shading

    echo "-10000 150 10000 150" > gray.cpt
    gmt grdgradient india_topo.nc -Nt1 -A45 -Gindia_topo_i.nc
    gmt grdimage india_topo.nc -Iindia_topo_i.nc -J -Cgray.cpt -O -K >> $ps

    # Finally undo clipping and overlay basemap

    gmt pscoast -R -J -O -K -Q -B10f5 -B+t"Clipping of Images" >> $ps

    # Put a color legend on top of the land mask

    gmt psscale -D4i/7.6i/4i/0.2ih -Cgeoid.cpt -Bx5f1 -By+lm -I -O -K >> $ps

    # Add a text paragraph

    gmt pstext -R -J -O -M -Gwhite -Wthinner -TO -D-0.1i/0.1i -F+f12,Times-Roman+jRB >> $ps << END
    > 90 -10 12p 3i j
    @_@%5%Example 17.@%%@_  We first plot the color geoid image
    for the entire region, followed by a gray-shaded @#etopo5@#
    image that is clipped so it is only visible inside the coastlines.
    END

    # Clean up

    rm -f geoid.cpt gray.cpt *_i.nc

Clipping of images using coastlines.

### Navigation

- index
- next
- previous
- Project Home »
- GMT 5.1.1 documentation »
- The GMT historical collection »
- Search: