# Grdproject: convert X/Y grid to a lat/long grid

**URL:** <https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352>\
**Category:** Q&A\
**Tags:** gmt\
**Created:** [February 16, 2021, 2:13pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352 "2021-02-16T14:13:21Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![gg1slb](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gg1slb](https://forum.generic-mapping-tools.org/u/gg1slb)\
**Post date:** [February 16, 2021, 2:13pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/1 "2021-02-16T14:13:21Z")

</div>

Hello, I hope you can help. I am using gmt5.4.3:

I have a netcdf file which is in X/Y coordinate system: This is the information from grdinfo

_input.nc: Command: xyz2grd shear\_stress.xyz -I5000 -R-2000000/2500000/-1250000/3100000 -Ggrids/shear\_stress\_poly.nc_  
_input.nc: Remark:_  
_input.nc: Gridline node registration used_  
_Grid file format: nf (# 18) GMT netCDF format (float) (COARDS-compliant) [DEFAULT]_

- x\_min: -2000000 x\_max: 2500000 x\_inc: 5000 name: x nx: 901\*
- y\_min: -1250000 y\_max: 3100000 y\_inc: 5000 name: y ny: 871\*
- z\_min: 5000 z\_max: 130000 name: z\*  
_scale\_factor: 1 add\_offset: 0_

I want to convert to a latitude and longitude format: This is the information that was provided about the output original projection  
_project: albers_  
_center\_longitude=13.5_  
_center\_latitude=60.8_  
_southern\_standard\_parallel=43_  
_northern\_standard\_parallel=62_  
it has a scale of 5000m

I am using the command grdproject:

grdproject -Jl13.5/60.8/43/62/1:1 input.nc -I -C -F out.nc

However, the resultant latitude and longitude are not what I know there should be: i.e the input grid extends into the barents sea, ~ 75N but the final latitude and longitude limits are  
Longitude: -12W and 100E  
latitude: 46N to 68N

I am using the grdproject command correct given the information I was provided.

Thank!

Sarah

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 16, 2021, 2:43pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/2 "2021-02-16T14:43:30Z")

</div>

you are using -Jl, that is Lambert projection, but you says that it is a Albers projection, then you should use -Jb

---

<div class="post-metadata">

**Author:** ![gg1slb](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gg1slb](https://forum.generic-mapping-tools.org/u/gg1slb)\
**Post date:** [February 16, 2021, 3:28pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/3 "2021-02-16T15:28:59Z")

</div>

ops good spot. Thanks. However, nearly the same issues:  
the revised latitude and longitude in the out.nc are:

lat: 46.4N to 69N  
lon: -13W to 108.8E

So still does not seem to relate to where I know the data is?

Sarah

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 16, 2021, 3:59pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/4 "2021-02-16T15:59:20Z")

</div>

using info from grdinfo:

> cat \<\< EOF \> range.txt  
> -2000000 -1250000  
> 2500000 -1250000  
> 2500000 3100000  
> -2000000 3100000  
> EOF  
> gmt mapproject range.txt -Jb13.5/60.8/43/62/1:1 -Rd -I -C  
> 0.712780291462 55.8100384291  
> 29.3940832463 55.470337274  
> 38.6651742095 70.4229781997  
> -6.91795688286 71.0017797023

Are these values close to what you expected?

Not sure how deal with the ‘it has a scale of 5000m’

using gmt 6.1.1

---

<div class="post-metadata">

**Author:** ![gg1slb](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gg1slb](https://forum.generic-mapping-tools.org/u/gg1slb)\
**Post date:** [February 16, 2021, 4:15pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/5 "2021-02-16T16:15:42Z")

</div>

Hi Marcelo

I had not thought to try mapproject reading in the limits of the X/Y - I will give that a go.!

thank!

Sarah

---

<div class="post-metadata">

**Author:** ![gg1slb](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gg1slb](https://forum.generic-mapping-tools.org/u/gg1slb)\
**Post date:** [February 16, 2021, 4:44pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/6 "2021-02-16T16:44:20Z")

</div>

Hi Marcelo

It is still not quite in the right place - it should include UK and Barents sea; I will double check the projection information I was provided.

Sarah

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 16, 2021, 4:46pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/7 "2021-02-16T16:46:39Z")

</div>

If you use a `proj4` projection string in **-J** the **-R** option is not needed. In _map|grdproject_ the **-R** extend may select either spherical or ellipsoidal approximations. With `proj4` it’s always what those parameters set (default to ellipsoidal).

---

<div class="post-metadata">

**Author:** ![gg1slb](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gg1slb](https://forum.generic-mapping-tools.org/u/gg1slb)\
**Post date:** [February 16, 2021, 4:57pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/8 "2021-02-16T16:57:23Z")

</div>

Hi Joaquim

I am a bit confused by what you are suggest: should I think remove the -R command from the grdproject or mapproject?

I have tried to find a way of defined proj4 in the man pages but nothing is listed.

I removed the -R command from mapproject commands: but I get an error to define -R:  
mapproject range.txt -Jb13.5/60.8/43/62/1:1 -I -C

Thanks

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 16, 2021, 5:35pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/9 "2021-02-16T17:35:38Z")

</div>

The GMT docs explain on how to use `proj4` strings but does not list them (they are thousands). You would need to consult the `PROJ` manuals to know how to write one from your projection parameters. Then with it you don’t need **-R** but with the **-J** projection syntax you need, which is a pain.

---

<div class="post-metadata">

**Author:** ![gg1slb](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gg1slb](https://forum.generic-mapping-tools.org/u/gg1slb)\
**Post date:** [February 16, 2021, 5:51pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/10 "2021-02-16T17:51:05Z")

</div>

Hi Joaquim

I was just going by the grdproject information. I will go looking further into the GMT docs page.

Now that I know I am on the right track.

thanks for answering all my questions.

Sarah

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 16, 2021, 6:03pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/11 "2021-02-16T18:03:02Z")

</div>

> $ gmt mapproject range.txt -Jaea/13.5/60.8/43/62/1:1 -I -C  
> mapproject [ERROR]: Must specify -R option

Appears that mapproject with proj need -R  
using gmt 6.2.0\_50eafd2\_2021.02.10

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 16, 2021, 6:15pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/12 "2021-02-16T18:15:35Z")

</div>

You are not using **-J+proj=…** That’s using mappoject with `proj`

---

<div class="post-metadata">

**Author:** ![gg1slb](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gg1slb](https://forum.generic-mapping-tools.org/u/gg1slb)\
**Post date:** [February 17, 2021, 12:02pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/13 "2021-02-17T12:02:22Z")

</div>

Hi

Thanks for the suggestions. But as I only have version 5.4.3 not version6. I am working on HPC cluster and I do not have the access to GMT6.

From GMT6 docs; I can see all the many proj codes: -Jproj|EPSG.  
I have tried to use the listed codes for GMT5:

grdproject -Jaea/13.5/60.8/43/62/1:1 input.nc -I -C -F -Gout\_latlon.nc

however, I get an error message  
grdproject: Internal Error = GMT\_MAP\_BAD\_LAT\_MAXgrdproject (GMT\_grdproject): North is outside -90 to +90 degree range

I will see if I can upgrade to gmt6; but I might have to look into a different software.

Sarah

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 17, 2021, 3:43pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/14 "2021-02-17T15:43:30Z")

</div>

You could consider doing the pre and post processing in more simple computer than the HPC.

The following commands produce the same results:

> gmt mapproject range.txt -Jb13.5/60.8/43/62/1:1 -Rd -I -C -Fe

> proj=‘-J+proj=aea+lon\_0=13.5+lat\_0=60.8+lat\_1=43+lat\_2=62+ellps=WGS84+units=m’  
> gmt mapproject range.txt $proj -I

Just to you have some more things to try.

---

<div class="post-metadata">

**Author:** ![gg1slb](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gg1slb](https://forum.generic-mapping-tools.org/u/gg1slb)\
**Post date:** [February 17, 2021, 4:09pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/15 "2021-02-17T16:09:28Z")

</div>

I would love to be install things on a local machine - but I do not have that option with this newer version.  
Thanks for so much for trying the non-GMT6 version I will keep trying with these extra commands this is the output I get; - which i am going for is the four corners of a lat/lon square.

-13.2872884533 46.4046346244   
46.1998312515 44.6351070531   
103.977549608 73.0906845128   
-71.4534740956 78.0367484823

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [February 17, 2021, 4:13pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/16 "2021-02-17T16:13:05Z")

</div>

> [@gg1slb](#):
>
> Thanks for the suggestions. But as I only have version 5.4.3 not version6. I am working on HPC cluster and I do not have the access to GMT6.

If you have Anaconda or miniconda installed on your HPC, you can install GMT6 using the following command:

```auto
conda install -c conda-forge gmt

```

Then GMT6 should be installed in your own home directory.

---

<div class="post-metadata">

**Author:** ![gg1slb](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@gg1slb](https://forum.generic-mapping-tools.org/u/gg1slb)\
**Post date:** [February 17, 2021, 4:18pm UTC](https://forum.generic-mapping-tools.org/t/grdproject-convert-x-y-grid-to-a-lat-long-grid/1352/17 "2021-02-17T16:18:57Z")

</div>

Hi, never knew could try that. great tip!  
giving it a go now and so far - not crashed!

Sarah
