2

I am working in a tabular set (.dbf) In ArcGIS Desktop 10.1 with an odd DMS format.The format is as follows:

Lat: 45585400
Long: 89560600

I believe this is a strange notation for 45°58'54" and -89°56'06". My problem is I can't figure out how to parse the Degrees, Minutes and Seconds out into individual fields in the .dbf. Once I get that far I can easily convert the value to decimal degrees and create point data out of it.

Can you help me with this?

0

1 Answer 1

1

This should work, assuming that the input is a double, long, or string. If the input is a string, you can remove the line that casts the value to a string.

exp = """
def convert(value,latlong):
    num = str(int(value))
    i = 0 if len(num) == 8 else 1
    val = int(num[0:2+i]) + int(num[2+i:4+i])/60.0 + int(num[4+i:])/360000.0
    if latlong.lower() in ["longitude", "long", "lambda"]: val = -val    
    return val"""

arcpy.CalculateField_management("<DBF FILE>", "<new lat field>", 
                                'convert(!LAT!,"")', "PYTHON_9.3", exp)

With built in exp, it's difficult to maintain exact spacing and newline characters.

arcpy.CalculateField_management("<DBF FILE>", "<new lat field>", 
                                'convert(!LAT!,"")', "PYTHON_9.3",
                                """def convert(value,latlong):\n    num = str(int(value))\n    i = 0 if len(num) == 8 else 1\n    val = int(num[0:2+i]) + int(num[2+i:4+i])/60.0 + int(num[4+i:])/360000.0\n    if latlong.lower() in ["longitude", "long", "lambda"]: val = -val\n    return val""")
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.