Pointer Reader Example¶
Copyright (c) 2014-2020 National Technology and Engineering Solutions of Sandia, LLC. Under the terms of Contract DE-NA0003525 with National Technology and Engineering Solutions of Sandia, LLC, the U.S. Government retains certain rights in this software.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Imports
[1]:
from tracktable.domain.terrestrial import TrajectoryPointReader
from tracktable.core import data_directory
import os.path
[2]:
data_filename = os.path.join(data_directory(), 'SampleASDI.csv')
inFile = open(data_filename, 'r')
reader = TrajectoryPointReader()
reader.input = inFile
reader.comment_character = '#'
reader.field_delimiter = ','
[3]:
i = 10 # Used to limit how many results we see
for x in reader: # Only need this line and the next to see all the data
print(x)
i-=1
if i <=0:
break
inFile.close()
[DAL54@ 2013-07-01 05:53:50: (-66.75, 28.25) Properties: ( )]
[UAL48@ 2013-07-01 05:53:53: (-42.1, 58.4167) Properties: ( )]
[KAL86@ 2013-07-01 05:53:53: (-74.0833, 47.4) Properties: ( )]
[BAW288@ 2013-07-01 05:53:54: (-82.9333, 45.7167) Properties: ( )]
[DAL248@ 2013-07-01 05:53:55: (-49.1667, 59.0167) Properties: ( )]
[ANZ2@ 2013-07-01 05:53:55: (-53.0667, 52.2833) Properties: ( )]
[DAL61@ 2013-07-01 05:53:56: (-66.35, 17.55) Properties: ( )]
[JBU1103@ 2013-07-01 05:53:56: (-66.55, 19.5667) Properties: ( )]
[CFG234@ 2013-07-01 05:53:56: (-67.9167, 20) Properties: ( )]
[AZA62J@ 2013-07-01 05:53:57: (-51.1, 48.7667) Properties: ( )]
object_id_column
- Column in dataset holding the object idtimestamp_column
- Column in dataset holding the timestampcoordinate0
- Column in dataset holding the longitudecoordinate1
- Column in dataset holding the latitudeThese four columns are required.
In the next example, we set a numeric field (speed) and a string field(status) and see the results.
[4]:
data_filename = os.path.join(data_directory(), 'SampleASDI.csv')
inFile = open(data_filename, 'r')
reader.input = inFile
reader.object_id_column = 0
reader.timestamp_column = 1
reader.coordinates[0] = 2
reader.coordinates[1] = 3
reader.set_real_field_column('speed', 4) # The column name is 'speed' and it is located in column 4
reader.set_string_field_column('status', 9)
[5]:
i=10
for x in reader:
print(x)
i-=1
if i <= 0:
break
[DAL54@ 2013-07-01 05:53:50: (-66.75, 28.25) Properties: ( {speed [null]: (null real)}, {status [null]: (null string)})]
[UAL48@ 2013-07-01 05:53:53: (-42.1, 58.4167) Properties: ( {speed [real]: 530}, {status [null]: (null string)})]
[KAL86@ 2013-07-01 05:53:53: (-74.0833, 47.4) Properties: ( {speed [real]: 510}, {status [null]: (null string)})]
[BAW288@ 2013-07-01 05:53:54: (-82.9333, 45.7167) Properties: ( {speed [real]: 510}, {status [null]: (null string)})]
[DAL248@ 2013-07-01 05:53:55: (-49.1667, 59.0167) Properties: ( {speed [real]: 560}, {status [null]: (null string)})]
[ANZ2@ 2013-07-01 05:53:55: (-53.0667, 52.2833) Properties: ( {speed [real]: 610}, {status [null]: (null string)})]
[DAL61@ 2013-07-01 05:53:56: (-66.35, 17.55) Properties: ( {speed [real]: 480}, {status [null]: (null string)})]
[JBU1103@ 2013-07-01 05:53:56: (-66.55, 19.5667) Properties: ( {speed [real]: 440}, {status [null]: (null string)})]
[CFG234@ 2013-07-01 05:53:56: (-67.9167, 20) Properties: ( {speed [real]: 390}, {status [null]: (null string)})]
[AZA62J@ 2013-07-01 05:53:57: (-51.1, 48.7667) Properties: ( {speed [real]: 550}, {status [null]: (null string)})]