I’ve been trying to apply attributes from a shapefile in GMT when using the psxy command.
To be specific, I am trying to vary the color and width of lines based on an attribute in the shapefile. I am also trying to control the color and radius of points based on a shapefile attribute.
A minimum working example is provided below (code and output, example data is attached as a zip). I have had some success and been able to control the color of the lines based on the information on the shapefile. However I have been unsuccessful in trying to extract and apply the attribute in the shapefile to set the line widths. For the points I have been entirely unsuccessful
#!/bin/bash # minimum working example of lines and points from shapefiles proj=-JM0/5i # projection reg=-RUS # region lines=lines.shp # shapefile with lines circles=circles.shp # shapefile with circles line_thickness=thickness # line thickness attribute name circle_size=size # circle size attribute name ofile=ex # output file name # make colormap and plot the lines gmt makecpt -Cabyss -T0.0/1.0/0.25 -D > colors.cpt gmt psxy $lines $reg $proj -W1.5+cl -aZ=$line_thickness -Ccolors.cpt -K > $ofile.ps # plot the circles gmt psxy $circles $reg $proj -Sc0.25 -O >> $ofile.ps # conversion from eps to pdf +m<top/bottom/left/right> I think for margins gmt psconvert $ofile.ps -Tf -A+m0.25/0.5/0.25/0.25 # to pdf gmt psconvert $ofile.ps -Tg -A+m0.25/0.5/0.25/0.25 # to png rm -f $ofile.ps rm -f $ofile.eps
This example shows how the “line_thickness” attribute from the “lines.shp” file is successfully extracted and applied to color the psxy lines based on a colormap that has been defined using makecpt.
Example.zip (8.8 KB)