Tool:Converting Degree Minutes (DM) to Decimal Degrees (DD) using python script
0
0
Entering edit mode
5 months ago
import csv
import sys

def dm_to_dd(degrees, minutes):
    """
    Convert Degree Minutes (DM) to Decimal Degrees (DD).

    Parameters:
    degrees (int): Degrees part of the angle.
    minutes (float): Minutes part of the angle.

    Returns:
    float: Decimal degrees representation of the angle.
    """
    return degrees + (minutes / 60)

def convert_dm_to_dd(input_file, output_file):
    """
    Convert Degree Minutes (DM) in a CSV file to Decimal Degrees (DD) and write to another CSV file.

    Parameters:
    input_file (str): Path to the input CSV file.
    output_file (str): Path to the output CSV file.
    """
    with open(input_file, 'r') as infile, open(output_file, 'w', newline='') as outfile:
        reader = csv.reader(infile)  # Default delimiter is comma
        writer = csv.writer(outfile)

        # Write header to output file
        header = next(reader)
        writer.writerow(header + ['Decimal Latitude', 'Decimal Longitude'])

        # Convert each row and write to output file
        for row in reader:
            # Latitude conversion
            lat_degrees, lat_minutes = map(float, row[0].split('°'))
            lat_decimal = dm_to_dd(lat_degrees, lat_minutes)

            # Longitude conversion
            lon_degrees, lon_minutes = map(float, row[1].split('°'))
            lon_decimal = dm_to_dd(lon_degrees, lon_minutes)

            # Write the original data along with the decimal values
            writer.writerow(row + [lat_decimal, lon_decimal])

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python converter.py input.csv output.csv")
        sys.exit(1)

    input_file = sys.argv[1]
    output_file = sys.argv[2]

    convert_dm_to_dd(input_file, output_file)
    print(f"Conversion completed. Results written to {output_file}.")

Usage:

 python converter.py "C:\Users\Desktop\5555.csv" Demo_convert.csv
Minutes Decimal offtopic Degrees python • 620 views
ADD COMMENT
1
Entering edit mode

this is not bioinformatics and is not a tool and as such it is off-topic on this site

ADD REPLY
0
Entering edit mode

Instead of simply posting a chunk of code it would be useful to add a line or two to say where this could would be useful. Not immediately apparent as to what area of bioinformatics this is applicable to.

ADD REPLY
0
Entering edit mode

Hello friends,

Thank you for your feedback. I understand that the post may not directly relate to bioinformatics. My aim was to share a useful script for converting Degree Minutes (DM) to Decimal Degrees (DD), which can be relevant in geospatial analysis of biological data. I appreciate your guidance and will ensure future posts align better with the forum's focus.

Best regards, KAMALAKKANNAN R

ADD REPLY

Login before adding your answer.

Traffic: 1345 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6