-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImportARGOS.py
96 lines (74 loc) · 3.08 KB
/
ImportARGOS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
##---------------------------------------------------------------------
## ImportARGOS.py
##
## Description: Read in ARGOS formatted tracking data and create a line
## feature class from the [filtered] tracking points
##
## Usage: ImportArgos <ARGOS folder> <Output feature class>
##
## Created: Fall 2021
## Author: John.Fay@duke.edu (for ENV859)
##---------------------------------------------------------------------
# Import modules
import sys, os, arcpy
#Allow outputs to be overwritten
arcpy.env.overwriteOutput = True
# Set input variables (Hard-wired)
inputFile = 'V:/ARGOSTracking/Data/ARGOSData/1997dg.txt'
outputSR = arcpy.SpatialReference(54002)
outputFC = "V:/ARGOSTracking/Scratch/ARGOStrack.shp"
# Create feature class to which we will add features
outPath, outFile = os.path.split(outputFC)
arcpy.management.CreateFeatureclass(outPath,outFile,"POINT","","","",outputSR)
# Add TagID, LC, IQ, and Date fields to the output feature class
arcpy.AddField_management(outputFC,"TagID","LONG")
arcpy.AddField_management(outputFC,"LC","TEXT")
arcpy.AddField_management(outputFC,"Date","DATE")
#%% Construct a while loop and iterate through all lines in the data file
# Open the ARGOS data file
inputFileObj = open(inputFile,'r')
# Get the first line of data, so we can use the while loop
lineString = inputFileObj.readline()
#Start the while loop
while lineString:
# Set code to run only if the line contains the string "Date: "
if ("Date :" in lineString):
# Parse the line into a list
lineData = lineString.split()
# Extract attributes from the datum header line
tagID = lineData[0]
# Extract location info from the next line
line2String = inputFileObj.readline()
# Parse the line into a list
line2Data = line2String.split()
# Extract the date we need to variables
obsLat = line2Data[2]
obsLon= line2Data[5]
# Extract the date, time, and LC values
obsDate = lineData[3]
obsTime = lineData[4]
obsLC = lineData[7]
# Print results to see how we're doing
#print (tagID,"Lat:"+obsLat,"Long:"+obsLon, obsLC, obsDate, obsTime)
#Try to convert coordinates to point object
try:
# Convert raw coordinate strings to numbers
if obsLat[-1] == 'N':
obsLat = float(obsLat[:-1])
else:
obsLat = float(obsLat[:-1]) * -1
if obsLon[-1] == 'E':
obsLon = float(obsLon[:-1])
else:
obsLon = float(obsLon[:-1]) * -1
# Create point object from lat/long coordinates
obsPoint = arcpy.Point()
obsPoint.X = obsLon
obsPoint.Y = obsLat
#Handle any error
except Exception as e:
print(f"Error adding record {tagID} to the output: {e}")
# Move to the next line so the while loop progresses
lineString = inputFileObj.readline()
#Close the file object
inputFileObj.close()