You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
def parse_coordinates(file_path):
|
|
|
|
|
valid_coordinates = []
|
|
|
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
|
|
|
for line in file:
|
|
|
|
|
match = re.match(r'(\d+°\d+′\d+″[NS]),(\d+°\d+′\d+″[EW])', line.strip())
|
|
|
|
|
if match:
|
|
|
|
|
lat, lon = match.groups()
|
|
|
|
|
lat_value = parse_dms(lat)
|
|
|
|
|
lon_value = parse_dms(lon)
|
|
|
|
|
if -90 <= lat_value <= 90 and -180 <= lon_value <= 180:
|
|
|
|
|
valid_coordinates.append((lat, lon))
|
|
|
|
|
return valid_coordinates
|
|
|
|
|
|
|
|
|
|
def parse_dms(dms):
|
|
|
|
|
parts = re.split('[°′″]', dms)
|
|
|
|
|
degrees = int(parts[0])
|
|
|
|
|
minutes = int(parts[1])
|
|
|
|
|
seconds = float(parts[2])
|
|
|
|
|
direction = parts[3]
|
|
|
|
|
|
|
|
|
|
total_degrees = degrees + minutes / 60 + seconds / 3600
|
|
|
|
|
if direction in ['S', 'W']:
|
|
|
|
|
total_degrees = -total_degrees
|
|
|
|
|
|
|
|
|
|
return total_degrees
|
|
|
|
|
|
|
|
|
|
file_path = 'e:\\_Ufo\\000jiegou\\TheBattleCar\\coordinate.txt'
|
|
|
|
|
valid_coords = parse_coordinates(file_path)
|
|
|
|
|
|
|
|
|
|
for coord in valid_coords:
|
|
|
|
|
print(coord)
|