On 7/10/07, John <[EMAIL PROTECTED]> wrote:
I was trying to read in a tab delimited file i was given with lat and lon,
the thing is I needed decimal lat, and decimal long... well, anyway I think
you can see what my problem was:
for i in range(0,344)
y=d[i][2].split('\xb0')
x=d[i][3].split('\xb0')
ydeg,ymin=y[0].strip(),y[1].rstrip('\' N').rstrip("\' S")
xdeg,xmin=x[0].strip(),x[1].rstrip("\' E").rstrip("\' W")
if re.search('\ZW','x[1]') xmin=-1*xmin
if re.search('\ZS','y[1]') ymin=-1*ymin
declat=int(ydeg)+(float(ymin)/60)
declon=int(xdeg)+(float(xmin)/60)
The thing is, it isn't terribly robust (I'm not even positive it's working
correctly!!). For instance, as you might have guessed I was given Lat and
Lon in the following format:
STNA 45° 49' N 08° 38' E
STNB 46° 58' 19° 33' E
STNC 53°33' -9°54'
STND 51°32' N 12°54' W
Off the top of my head
regex=re.compile("STD[A-Z] (\d+)[ ]?(\d+)'[ ]?N?[ ]?\-?(\d+)[ ]?(\d+)'
[EW]")
m = re.search(regex,linesOfFile)
print m.group(1)
That should work, but you might need to massage the regex a little
HTH,
Tino
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor