4
$\begingroup$

Can someone explain how can get the Lat/Lon of a given Grid square? (the middle of the grid would be the best). I've looked at this (that does the "reverse"...from lat/lo to grid"):

How can one convert from Lat/Long to Grid Square?

But i need to do the inverse...

Anyone can explain in step by step?

Many thanks!

$\endgroup$
3
  • 3
    $\begingroup$ Could you base your question off the obvious wikipedia article, and explain what in that article you did not understand? It's easier to fill gaps in understanding than to rewrite something that has already been written somewhere else. $\endgroup$ Jul 25, 2016 at 10:11
  • 1
    $\begingroup$ I understand the article, but i was not able to do the reverse calculation...from grid to coordinates. Edwin van Mierlo has given the right answer. Sorry for any mistake, this is my very first post on stackexchange :) $\endgroup$ Jul 26, 2016 at 15:54
  • 1
    $\begingroup$ It sounds like you found the information you were looking for to help others you should Mark that as the answer. Then we can Point other questions to here. $\endgroup$ Mar 16, 2017 at 2:43

3 Answers 3

3
$\begingroup$

if by "Grid" you mean "Maidenhead Locator" then here is a similar question, with some sample Python code as answer.

The result from the code will be

Lon = (start_lon) to (end_lon)
Lat = (start_lat) to (end_lat)

From that you can easily calculate the "middle" of the square. or you can take the code and adapt, here is the code from the above mentioned question/answer:

# -*- coding: utf-8 -*-
#maiden head to lon/lat

__MH__ = 'HK34wh'

def GetLon(ONE, THREE, FIVE):
    StrStartLon = ''
    StrEndLon = ''

    Field = ((ord(ONE.lower()) - 97) * 20) 
    Square = int(THREE) * 2
    SubSquareLow = (ord(FIVE.lower()) - 97) * (2/24)
    SubSquareHigh = SubSquareLow + (2/24)

    StrStartLon = str(Field + Square + SubSquareLow - 180 )
    StrEndLon = str(Field + Square + SubSquareHigh - 180 )

    return StrStartLon, StrEndLon

def GetLat(TWO, FOUR, SIX):
    StrStartLat = ''
    StrEndLat = ''

    Field = ((ord(TWO.lower()) - 97) * 10) 
    Square = int(FOUR)
    SubSquareLow = (ord(SIX.lower()) - 97) * (1/24)
    SubSquareHigh = SubSquareLow + (1/24)

    StrStartLat = str(Field + Square + SubSquareLow - 90)
    StrEndLat = str(Field + Square + SubSquareHigh - 90)    

    return StrStartLat, StrEndLat

def main(strMaidenHead = __MH__):
    if len(strMaidenHead) < 6: strMaidenHead = __MH__

    ONE = strMaidenHead[0:1]
    TWO = strMaidenHead[1:2]
    THREE = strMaidenHead[2:3]
    FOUR = strMaidenHead[3:4]
    FIVE = strMaidenHead[4:5]
    SIX = strMaidenHead[5:6]

    (strStartLon, strEndLon) = GetLon(ONE, THREE, FIVE)
    (strStartLat, strEndLat) = GetLat(TWO, FOUR, SIX)

    print ('Start Lon = ' + strStartLon)
    print ('End   Lon = ' + strEndLon)
    print ()
    print ('Start Lat = ' + strStartLat)
    print ('End   Lat = ' + strEndLat)

    return strStartLon, strEndLon, strStartLat, strEndLat

#BEGIN
if __name__ == '__main__':
    main ()
    sys.exit ('end of script: '+ os.path.basename(__file__) + os.linesep + 'by: Edwin van Mierlo')
#END

(for the purists amongst you, no; this is not very 'pythonic', but it does work)

$\endgroup$
1
  • $\begingroup$ Thanks Edwin van Mierlo, it seems to be what i was looking for!!!!! $\endgroup$ Jul 26, 2016 at 15:53
1
$\begingroup$

I've created many (two, PHP is going up shortly) implementations of this on my github page. Please feel free to use these: https://github.com/gravypod/maidenhead/

I'm also very happy to take pulls in to either add more implementations or clean up my implementations. It would be nice to get a version for every manjor language out there. I just haven't got the time to do that sadly.

I've also found it hard to convert from Lat Lon to maidenhead which would be very nice to have.

$\endgroup$
1
$\begingroup$

There is a Python package converting to/from Maidenhead/WGS84 Lat/Lon

$\endgroup$
3
  • 1
    $\begingroup$ Link is broken now. This is why StackExchange suggests posting content, not just links. $\endgroup$
    – pidloop
    Jul 31, 2021 at 17:37
  • $\begingroup$ @pidloop Yes, and it's not even on archive.org. $\endgroup$ Aug 5, 2021 at 12:09
  • $\begingroup$ Thanks, I updated the link to PyPI, which is semi-permanent. $\endgroup$
    – scivision
    Oct 18, 2021 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .