+ Reply to Thread
Results 1 to 12 of 12

Latitude & Longitude processing help please

  1. #1
    Registered User
    Join Date
    12-12-2009
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    4

    Latitude & Longitude processing help please

    Hi All,

    I'm currently working on a project with data that includes columns for both latitude and longitude which I will need to convert from its current form into decimal degrees. The problem is that the coordinates are in the format DDDMMSS followed by a single letter indicating the direction, which means I have to first extract proper degree minute second format before I can do anything. Further complicating the problem is that each of the entries does not necessarily have all of the components I just described (eg some of the latitudes only have degrees and minutes but not seconds) and also if a longitude is less than 100 degrees, the third digit is not used in the data. There are over 2000 records so doing the conversion by hand just won't work and I've only got a few days to present this part of my project anyway.

    So, to sum up, I'm looking for a formula or series of formulas that will reliably convert something like 1083000W into -108.5000 when the last two zeros may or may not be there and the first digit may also be missing.

    Thank you in advance,
    Greg
    Last edited by Pilot_Greg; 12-14-2009 at 03:31 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Latitude & Longitude processing help please

    Welcome to the forum.

    Post a workbook that illustrates the possibilities.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    01-18-2005
    Location
    Auckland New Zealand
    MS-Off Ver
    Office Professional 2007
    Posts
    295

    Re: Latitude & Longitude processing help please

    Having posted this I think I've overlooked the conversion from minutes/seconds to decimal. Maybe further examples can be given.

    With 1083015W in A1 try this in B1:
    =IF(LEN(A1)=8,LEFT(A1,LEN(A1)-1)/10000,LEFT(A1,LEN(A1)-1)/100)*IF(ISERROR(FIND(RIGHT(A1,1),"WS")),1,-1)

    Format the answer to 4 decimal places. (-108.3015)

    I'm assuming:
    - West and South must be negative. If I am wrong, change the "WS" text accordingly.
    - the last letter is always upper case.
    - if the format is DDDMM, the SS is zero.

    Excel 2007 has a nicer formula to test for errors, but I only have the 2003 version.

    hth
    Mike
    Last edited by Mikeopolo; 12-13-2009 at 03:29 AM.

  4. #4
    Registered User
    Join Date
    12-12-2009
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Latitude & Longitude processing help please

    Quote Originally Posted by shg View Post
    Welcome to the forum.

    Post a workbook that illustrates the possibilities.
    Ok here is the example document... I've noticed that the issue with the zero's that I've described earlier does not exist not that I've brought the data home with me (maybe a format setting on the other copy of excel?), so that part of the problem at least is out of the picture... the lat is always in the format DDMMSS N/S and the lon is always in the format DDDMMSS E/W with W/S needing to be negative. I'm not 100% sure that all of the E/W/N/S are capital or not, but at least one of the problems is off the table.

    Having posted this I think I've overlooked the conversion from minutes/seconds to decimal. Maybe further examples can be given.

    With 1083015W in A1 try this in B1:
    =IF(LEN(A1)=8,LEFT(A1,LEN(A1)-1)/10000,LEFT(A1,LEN(A1)-1)/100)*IF(ISERROR(FIND(RIGHT(A1,1),"WS")),1,-1)

    Format the answer to 4 decimal places. (-108.3015)

    I'm assuming:
    - West and South must be negative. If I am wrong, change the "WS" text accordingly.
    - the last letter is always upper case.
    - if the format is DDDMM, the SS is zero.

    Excel 2007 has a nicer formula to test for errors, but I only have the 2003 version.

    hth
    Mike
    I'll go ahead and give this a try, but I think there are a couple of problems that might arise with the new info in mind. First, all of the lat are 7 digits including the letter and all of the lon are 8, so the determining code might get tripped up? Second, I'm not sure if the letter is always upper case... I'm in the process of scanning through the full table to see, but there are a lot so it may take a little while. And last, with the new data format that I've found since I've come home, if there are any double zero's its usually in the DD part of the coordinate rather than the SS part. Should this still work? Or is a new formula required?

    Thanks again,
    Greg
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    01-18-2005
    Location
    Auckland New Zealand
    MS-Off Ver
    Office Professional 2007
    Posts
    295

    Re: Latitude & Longitude processing help please

    with a test longitude value 1222659W in A1, try this in B1:
    =(LEFT(A1,3)+MID(A1,4,2)/60+MID(A1,6,2)/3600)*IF(ISERROR(FIND(upper(RIGHT(A1,1)),"WS")),1,-1)
    Gives -122.4497.

    hth

    Regards
    Mike

  6. #6
    Forum Contributor
    Join Date
    01-18-2005
    Location
    Auckland New Zealand
    MS-Off Ver
    Office Professional 2007
    Posts
    295

    Re: Latitude & Longitude processing help please

    And for latitude (length 7 characters), eg 381326N in A7:

    =(LEFT(A7,2)+MID(A7,3,2)/60+MID(A7,3,2)/3600)*IF(ISERROR(FIND(RIGHT(A7,1),"WS")),1,-1)

    gives 38.2203

    hth
    Mike

  7. #7
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Latitude & Longitude processing help please

    another possibility is i think
    =(SUBSTITUTE(TEXT(LEFT(R1,7),"000-00-00"),"-",":"))*24*IF(RIGHT(R1,1)="W",-1,1)
    =(SUBSTITUTE(TEXT(LEFT(Q1,6),"00-00-00"),"-",":"))*24*IF(RIGHT(Q1,1)="S",-1,1)
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  8. #8
    Registered User
    Join Date
    12-12-2009
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Latitude & Longitude processing help please

    Well it almost works like a charm... nothing is wrong with the formula, but the data in this case again. Some of the records are missing a lat or long (or both) coordinate, which produces an unusable entry into the formula field, causing an error when I'm trying to import the resultant table into the mapping program I'm using. What changes would be needed to the formulas already given to cause the output to be a zero if there is nothing there?

    Thanks a lot,
    Greg

  9. #9
    Forum Contributor
    Join Date
    01-18-2005
    Location
    Auckland New Zealand
    MS-Off Ver
    Office Professional 2007
    Posts
    295

    Re: Latitude & Longitude processing help please

    Try:
    =IF(A1<>"",(LEFT(A1,3)+MID(A1,4,2)/60+MID(A1,6,2)/3600)*IF(ISERROR(FIND(RIGHT(A1,1),"WS")),1,-1),0)
    and
    =IF(A7<>"",(LEFT(A7,2)+MID(A7,3,2)/60+MID(A7,3,2)/3600)*IF(ISERROR(FIND(RIGHT(A7,1),"WS")),1,-1),0)

    I've added an if statement that checks if the cell is not empty, calculates the formula if not empty, or returns a zero if it is empty.

    Regards
    Mike

  10. #10
    Forum Contributor
    Join Date
    01-18-2005
    Location
    Auckland New Zealand
    MS-Off Ver
    Office Professional 2007
    Posts
    295

    Re: Latitude & Longitude processing help please

    @martin - awesomely simple, thanks for sharing!

    PS - uh oh, doesn't work for 0952836W?

    Regards
    Mike

  11. #11
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Latitude & Longitude processing help please

    oops to many leading 0
    =(SUBSTITUTE(TEXT(LEFT(A1,7),"0-00-00"),"-",":"))*24*IF(RIGHT(A1,1)="W",-1,1)
    should work for either
    =(SUBSTITUTE(TEXT(LEFT(A1,6),"0-00-00"),"-",":"))*24*IF(RIGHT(A1,1)="S",-1,1)

  12. #12
    Registered User
    Join Date
    12-12-2009
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Latitude & Longitude processing help please

    Thank you both for your efforts. Thanks to you, I've been able to quickly convert all of the records in a matter of seconds rather than days. In the end I went with Mike's solution, even though it is a little more complicated, as even Martin's corrected solution appeared not to work for every coordinate. Anyway, thank you again.

    Thanks,
    Greg

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1