Coordinates of the center of the map for inset map

I adapt the ex44 which shows how to plot inset map. I include some commands that calculate the center of the map, save them into variables ($Lon and $Lat) and finally used them as input for the projection of the inset.

The method that I used it is not very simpler (it has a lot extra calculations) and its not exactly precise (see below). Is any simpler way to calculate the center? Is this a good idea for a feature request for inset map?

For example I get this:
gmt psbasemap -R0/10/0/10 -JM25c -A | gmt spatial -fg -Qk
5.00000137334 4.99421799545 1222176.73074


gmt begin ex44 png
    gmt coast -RIT -JM15c -Wfaint -N1/0.5p -EAU+gbisque -Gbrown -Sazure1 -Da -B -BWSne

 # Calculate centroide and create variables
	gmt basemap -A > region.txt
	Lon=$(gmt spatial region.txt -fg -Qk -o0)
	Lat=$(gmt spatial region.txt -fg -Qk -o1)

	gmt inset begin -DjTR+w3.8c+o0.4c/0.25c -F+gwhite+p1p+c0.1c+s
		gmt coast -Rg -JG$Lon/$Lat/? -Da -Gbrown -A5000 -Bg -Wfaint -EAU+gbisque
	gmt inset end
gmt end

You can use mapproject -W to convert things like CM into plot or user coordinates, among other things:

     Print map width and/or height or a reference point. No input files are read. Select optional directive:
       g: Print map coordinates of reference point <gx/gy>.
       h: Print map height (See -D for plot units).
       j: Print map coordinates of justification point given as 2-char justification code (BL, MC, etc.).
       n: Print map coordinates of reference point with normalized coordinates <rx/ry> in 0-1 range.
       r: Print rectangular region for an oblique -R -J selection.
       R: Same as r but prints -Rw/e/s/n string as trailing text instead.
       w: Print map width (See -D for plot units).
       x: Print map coordinates of reference point given in plot coordinates <px/py>.
     Default prints both map width and map height.


gmt mapproject -JG-75.5835118511/37.1301956985/13.5c+du+z160+a210+t55+v36 -Rg -WjCM
283.123470979 35.2949364106
1 Like

And do you think it would be a good a feature request?
To be clear, in the inset map to write something like -JG?/?/? and let GMT select the lon0 and lat0 of the main map (and the width).

I think it is hard to know what is useful here. For you case, maybe this makes sense, but for other cases it may not. Also, this would not translate well to all projections, and because of the different projection syntax it would be challenging to deal with multiple question marks. BUT, perhaps we should examine how many projections take a point (lon,lat) - perhaps mostly azimuthal, and consider that as a special case.

Ok. I was thinking in a general case where for example batch is used to make a lot of maps from sevaral countries. And maybe it would be good to have like a default inset map (-JG -Rd center in the main map?) for each map. But, yes, maybe it is too much work.

Please make a feature request so we can check this out more.