I'm trying to extract coordinates based on the name of imagery files. I created a script to do this using functions:
Expand|Select|Wrap|Line Numbers
- def lat(dd):
- global lat
- lat_lon = dd.split('_')[1]
- if 'N' in lat_lon:
- lat = int(lat_lon[1:3])
- else:
- lat = int(lat_lon[1:3]) * -1
- def lon(dd):
- global lon
- lat_lon = dd.split('_')[1]
- if 'W' in lat_lon:
- lon = int(lat_lon[4:]) * -1
- else:
- lon = int(lat_lon[4:])
- list = ['ASTMGTM2_N37W110', 'ASTMGTM2_N45E80']
- for n in list:
- lat(n)
- lon(n)
- print lat, lon
TypeError: 'int' object is not callable
Does anyone know what I am doing wrong? I am new to python and have never really used the 'global' variable before.
I also tried using the 'return' keyword instead of the global variable:
Expand|Select|Wrap|Line Numbers
- def lat(dd):
- lat_lon = dd.split('_')[1]
- if 'N' in lat_lon:
- lat = int(lat_lon[1:3])
- return lat
- else:
- lat = int(lat_lon[1:3]) * -1
- return lat
- def lon(dd):
- lat_lon = dd.split('_')[1]
- if 'W' in lat_lon:
- lon = int(lat_lon[4:]) * -1
- return lon
- else:
- lon = int(lat_lon[4:])
- return lon
- list = ['ASTMGTM2_N37W110', 'ASTMGTM2_N45E80']
- for n in list:
- lat(n)
- lon(n)
- print lat, lon
<function lat at 0x03681F30> <function lon at 0x075A9530>
I am currently using Python 2.6 and Windows 7 64-bit. Thank you for your help!