# Bounding box of region

**URL:** <https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391>\
**Category:** Q&A\
**Created:** [April 2, 2026, 3:34pm UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391 "2026-04-02T15:34:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [April 2, 2026, 3:34pm UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/1 "2026-04-02T15:34:56Z")

</div>

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

I’m using

```auto
                        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).

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [April 2, 2026, 8:09pm UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/2 "2026-04-02T20:09:42Z")

</div>

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

e.g. [example 28](https://docs.generic-mapping-tools.org/latest/gallery/ex28.html):

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

```

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [April 2, 2026, 9:32pm UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/3 "2026-04-02T21:32:57Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [April 3, 2026, 7:23am UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/4 "2026-04-03T07:23:53Z")

</div>

> [@Andreas](#):
>
> `-R` is not the same as my grid; it’s given by the resulting bounding box from `-JS$lon/$lat/20c -R40+uk`

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

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

```

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [April 3, 2026, 7:46am UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/5 "2026-04-03T07:46:07Z")

</div>

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

```auto
    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..](https://docs.generic-mapping-tools.org/dev/plot.html#a), but I want to check if there exists a ‘ready made option’ for this already.

Thanks for responding @mkononets.

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [April 3, 2026, 7:59am UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/6 "2026-04-03T07:59:15Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [April 4, 2026, 2:05am UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/7 "2026-04-04T02:05:06Z")

</div>

> [@Andreas](#):
>
> I need the bounding box of the area shown in my main map, to feed `plot` in an inset map.

I think I use basemap -A for that.

> **[Optional Arguments - basemap — GMT 6.7.0 documentation](https://docs.generic-mapping-tools.org/dev/basemap.html#a)**
>
> No plotting is performed. Instead, we determine the geographical coordinates of the polygon outline for the (possibly oblique) rectangular map domain. The plot domain must be given via -R and -J, with no other options allowed. The sampling interval...

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [April 4, 2026, 12:19pm UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/8 "2026-04-04T12:19:43Z")

</div>

> [@Esteban82](#):
>
> basemap -A

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](https://github.com/GenericMappingTools/gmt/issues/8962)

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [April 7, 2026, 8:03pm UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/9 "2026-04-07T20:03:25Z")

</div>

This is exactly what I was looking for. I never noticed the [mapproject -W](https://docs.generic-mapping-tools.org/dev/mapproject.html#w) `+n` modifier before. Thanks @mkononets.

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [April 7, 2026, 9:23pm UTC](https://forum.generic-mapping-tools.org/t/bounding-box-of-region/6391/10 "2026-04-07T21:23:29Z")

</div>

> [@Andreas](#):
>
> never noticed the [mapproject -W](https://docs.generic-mapping-tools.org/dev/mapproject.html#w) `+n` modifier

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.
