Bounding box of region

I need the bounding box of a subregion of a grid.

I’m using

                        command substitution returning -R of interest
                        —————-----------------------------------------
gmt grdinfo -Ib grid.nc $(gmt mapproject -JS$lon/$lat/20c -R40+uk -WE)

This works, but is clumsy, since there is no need to involve the grid at all.

Is there any better way to get the bounding box of a region, -R, and a projection, -J? I tried all -W options in mapproject, but none gave me what I need (i.e., what grdinfo gives me).

-Rgrid.nc ? you likely need to specify the projection manually anyway

e.g. example 28:

gmt coast -R@Kilauea.utm.nc -Ju5Q/1:160000 -Df+ ...

The -R is not the same as my grid; it’s given by the resulting bounding box from -JS$lon/$lat/20c -R40+uk. That’s why I mentioned that the grid does not have anything to do with finding it, and thus grdinfo feels ‘wrong for the task’.

grdinfo -Ib outputs (from my original post) many lines of lon/lat points, which I can plot with plot. But there should be no need for grdinfo, mapproject should be able to do it, but I can’t see how (and maybe I’m wrong).

why don’t you just specify -JS$lon/$lat/20c -R40+uk when plotting? Like

gmt coast -Di -Wthinner,blue -JS0/-90/20c -R3000+uk -png test -Bxa30 -Bya30

I need the bounding box of the area shown in my main map, to feed plot in an inset map. Here’s the code:

    gmt inset begin -DjTL+w3c+o0.2c
      [...]
      gmt grdinfo -Ib grid.nc $(gmt mapproject -JS$lon/$lat/20c -R40+uk -WE) | gmt plot # plot bounding box of main map for overview on inset map
    gmt inset end

Again, using grdinfo seems wrong, since I do not need a grid to make a bounding box of a given -J and -R.
I think I can manually create the bounding box, based on output from mapproject, and plot with plot -A.., but I want to check if there exists a ‘ready made option’ for this already.

Thanks for responding @mkononets.

If you just need a closed rectangle for gmt plot, use -We+n2:

gmt mapproject -JS0/-90/20c -R3000+uk -We+n2
-135	-53.2621319284
135	-53.2621319284
45	-53.2621319284
-45	-53.2621319284
-135	-53.2621319284

I think I use basemap -A for that.

works as a classic mode gmt psbasemap call, works in a multi-call modern mode session, but fails as a modern mode one-liner, #8962

This is exactly what I was looking for. I never noticed the mapproject -W +n modifier before. Thanks @mkononets.

No wonder. The documentation is super condensed. Two example illustration are shown but with no code. I learned how to use it by trial and error.