1#!/usr/bin/env bash 2# Testing gmt spatial intersection 3 4ps=intersect.ps 5 6cat << EOF > A.txt 70 0 80.6 -0.3 91.3 0 101 0.9 110.8 0.2 120 1 13-0.3 0.7 140 0 15EOF 16cat << EOF > B.txt 170.3 0.3 181 0.6 191.5 0.3 201.4 1.1 210.7 1.2 220.1 1 230.3 0.3 24EOF 25 26# Cartesian 27# Find intersections between A and B 28R=-R-0.5/1.6/-0.5/1.5 29gmt psxy $R -Jx1.5i -P -Ba1g1 -BWSne A.txt -W3p,red -K -X0.75i > $ps 30gmt psxy $R -J -O B.txt -W3p,blue -K >> $ps 31gmt spatial A.txt B.txt -Ie | gmt psxy $R -Jx1.5i -O -K -Sc0.15i -W0.25p >> $ps 32# Truncate A given B 33gmt spatial A.txt -TB.txt | gmt psxy $R -Jx1.5i -O -K -W0.5p,green >> $ps 34# Clip A and B to a smaller region 35gmt psxy $R -J -O -K -Ba1g1 -BWSne+tCartesian -W0.25p,. [AB].txt -Y4i >> $ps 36gmt psxy $R -J -O -K -L -W0.5p,- << EOF >> $ps 37-0.2 -0.4 381.1 -0.4 391.1 0.9 40-0.2 0.9 41EOF 42# Do clipping and plot the clipped files 43gmt spatial A.txt -C -R-0.2/1.1/-0.4/0.9 | gmt psxy $R -Jx1.5i -O -K -W3p,red >> $ps 44gmt spatial B.txt -C -R-0.2/1.1/-0.4/0.9 | gmt psxy $R -Jx1.5i -O -K -W3p,blue >> $ps 45 46# Make geographic files and scale coordinates by 10 47gmt math -T A.txt 10 MUL = Ag.txt 48gmt math -T B.txt 10 MUL = Bg.txt 49# Geographic 50# Find intersections between Ag and Bg 51R=-R-5/16/-5/15 52gmt psxy $R -Jm0.15i -O -Ba5g5 -BWSne Ag.txt -W3p,red -K -Y-4i -X3.75i >> $ps 53gmt psxy $R -J -O Bg.txt -W3p,blue -K >> $ps 54gmt spatial Ag.txt Bg.txt -Ie -fg | gmt psxy $R -Jm0.15i -O -K -Sc0.15i -W0.25p >> $ps 55# Truncate Ag given Bg 56gmt spatial Ag.txt -TBg.txt -fg | gmt psxy $R -Jm0.15i -O -K -W0.5p,green >> $ps 57# Clip Ag and Bg to a smaller region 58gmt psxy $R -J -O -K -Ba5g5 -BWSne+tGeographic -W0.25p,. [AB]g.txt -Y4i >> $ps 59gmt psxy $R -J -O -K -L -W0.5p,- << EOF >> $ps 60-2 -4 6111 -4 6211 9 63-2 9 64EOF 65# Do clipping and plot the clipped files 66gmt spatial Ag.txt -C -R-2/11/-4/9 -fg | gmt psxy $R -Jm0.15i -O -K -W3p,red >> $ps 67gmt spatial Bg.txt -C -R-2/11/-4/9 -fg | gmt psxy $R -Jm0.15i -O -W3p,blue >> $ps 68