Search code examples
gpsarcgisdata-conversionarcmap

What are these GPS data mean, and how to correctly convert them into decimal degrees?


I have a set of household GPS coordinates data, and the format in excel sheet looks like the following (edited for confidential reason):

    ID    GPSN   GPSS   GPSE   GPSW
    1    211234   -9   890123   -9
    2    211255   -9   890155   -9
    ...

My questions are: what kind of GPS coordinates this is (looks like UTM data)? How do I accurately convert them into decimal degrees that only containing a longitude and a latitude (or X, Y data)? Do I need some kind of zoning information to do this correctly? Thanks


Solution

  • I doubt that a GPS receiver would put out UTM coordinates. It looks to me like latitude and longitude in degrees/minutes/seconds (DDMMSS). If so, then one way to do it is the following, in simple Python. The Convert Coordinate Notation tool in ArcGIS might be useful, but you'll have to reformat the data first, probably using Python.

    import csv
    import sys
    
    # A function that takes 211234, treats it as 21°12'34",
    # and returns 21.209444.
    def convertToDegrees(DMS):
        dms = DMS
        dms = int(dms)
        seconds = dms % 100
        if 60 <= seconds:
            print "More than 60 seconds! " + str(DMS) + " is not degrees/minutes/seconds!"
        dms /= 100
        minutes = dms % 100
        if 60 <= minutes:
            print "More than 60 minutes! " + str(DMS) + " is not degrees/minutes/seconds!"
        dms -= minutes
        degrees = dms / 100
        degrees += (minutes / 60.0)
        degrees += (seconds / (60.0 * 60.0))
        if 180 < degrees or -180 > degrees:
            print "In " + str(DMS) + ", degrees is outside [-180, 180]: " + str(degrees)
        return degrees
    
    # Input and output files from command line parameters
    inFilename = sys.argv[1]
    outFilename = sys.argv[2]
    readFirstRow = False
    with open(inFilename, "rb") as inFile:
        reader = csv.reader(inFile)
        with open(outFilename, "wb") as outFile:
            writer = csv.writer(outFile)
    
            # Loop through the rows
            for row in reader:
                if (not readFirstRow):
                    # Write the header row only once
                    writer.writerow(["ID", "latitude", "longitude"])
                    readFirstRow = True
                else:
                    # Convert this row to latitude and longitude
                    latitude = 0
                    longitude = 0
                    if "-9" != row[1]:
                        latitude = convertToDegrees(row[1])
                    if "-9" != row[2]:
                        latitude = -1 * convertToDegrees(row[2])
                    if "-9" != row[3]:
                        longitude = convertToDegrees(row[3])
                    if "-9" != row[4]:
                        longitude = -1 * convertToDegrees(row[4])
                    writer.writerow([row[0], latitude, longitude])
    

    To make sure you get it right, you'll want to confirm that the GPS was putting out latitude and longitude and find out which datum it used (probably WGS 1984).