def GenerateShps(self, Avoid=[]):
     print("Generating Shapefiles !")
     #creation du fichier de la sortie
     try:
         os.mkdir(self.Root + "/Shps")
     except WindowsError:
         print("Folder Already existing")
     #preparation des descriptifs du shp
     SpatialRef = osr.SpatialReference()
     SpatialRef.ImportFromEPSG(4326)
     Fields = self.AllFields()
     print(Fields)
     #iteration sur les fichiers fit
     for File in os.listdir(self.Root):
         if "." in File:
             if File.split(".")[1] == "fit":
                 print("    executing on this file : " + File)
                 Name = File.split(".")[0]
                 if Name in Avoid:
                     print("Avoiding this file as specified : " + Name)
                 else:
                     if os.path.isfile(self.Root + "/Shps/" + Name +
                                       ".shp") == False:
                         FitTable = FitToDataTable(
                             self.Root + '/' + File,
                             Config["FitFile"]["Fields"])
                         Shp = VL.JFastLayer("")
                         Shp.MakeItEmpty({
                             "SpatialRef":
                             SpatialRef,
                             "Fields": [F.Name for F in Fields],
                             "FieldsTypes":
                             [FieldConverter[F.Type] for F in Fields]
                         })
                         #remplissage du shp
                         for Row in FitTable.Iterate(True):
                             print("     Iterating on time : " +
                                   datetime.datetime.fromtimestamp(
                                       Row["TIME"]).strftime(
                                           '%Y-%m-%d %H:%M:%S') + " : " +
                                   str(Row["TIME"]))
                             Pt = ogr.Geometry(ogr.wkbPoint)
                             T = Row["TIME"]
                             Pt.AddPoint(garmin.degrees(Row["Lon"]),
                                         garmin.degrees(Row["Lat"]))
                             Datas = self.Request(int(Row["TIME"]))
                             Datas.update(Row)
                             Datas["TIME"] = T
                             Datas[
                                 "DATETIME"] = datetime.datetime.fromtimestamp(
                                     Row["TIME"]).strftime(
                                         '%Y-%m-%d %H:%M:%S')
                             #                    print(Datas)
                             #                    print([F.Name for F in Fields])
                             #                    print([FieldConverter[F.Type] for F in Fields])
                             Shp.AppendFeat(Datas, Pt)
                         #enregistrement du shp
                         Shp.Save(self.Root + "/Shps/" + Name + ".shp")
                         print("\a")
 def GetValue(self, row, col):
     try:
         if col==1 or col==2:
             return garmin.degrees(self.data[row][col])
         elif col==4:
             return str(time.asctime(time.gmtime(TimeEpoch+int(self.data[row][col]))))
         else:
             return str(self.data[row][col])
     except IndexError:
         return ''
예제 #3
0
 def GetValue(self, row, col):
     try:
         if col == 1 or col == 2:
             return garmin.degrees(self.data[row][col])
         elif col == 4:
             return str(
                 time.asctime(
                     time.gmtime(TimeEpoch + int(self.data[row][col]))))
         else:
             return str(self.data[row][col])
     except IndexError:
         return ''
예제 #4
0
def doCommand(serialDevice=None, outputURI=None, doTracks=1, doWaypoints=1, verbose=0):

   if os.name == 'nt':
      if not serialDevice: serialDevice =  "com1"
      phys = Win32SerialLink(serialDevice)
   else:
      if not serialDevice:  serialDevice =  "/dev/ttyS0"
#      serialDevice =  "/dev/cu.USA19H191P1.1"
      phys = UnixSerialLink(serialDevice)
      
   gps = Garmin(phys)

   print "GPS Product ID: %d Descriptions: %s Software version: %2.2f" % \
         (gps.prod_id, gps.prod_descs, gps.soft_ver)


   f = formula() # Empty store of RDF data
   base = uripath.base()
   
   record = f.newBlankNode()
   f.add(record, RDF.type, GPS.Record)

   if doWaypoints:
        # show waypoints
        if verbose: print "Getting waypoints"
        wpts = gps.getWaypoints()
        for w in wpts:
            if verbose: progress(`w`)
            wpt = symbol(uripath.join(base, w.ident))
            f.add(record, GPS.waypoint, wpt)
            f.add(wpt, WGS.lat, obj=intern(degrees(w.slat)))
            f.add(wpt, WGS.long, obj=intern(degrees(w.slon)))


   if doTracks:
      # show track
      if verbose: print "Getting tracks"
      tracks = gps.getTracks()
      for t in tracks:
        track = f.newBlankNode()
        f.add(record, GPS.track, track)
        for p in t:
            if isinstance(p, TrackHdr):
                if verbose: progress(`p`)
                f.add(track, GPS.disp, intern(p.dspl))
                f.add(track, GPS.color, intern(p.color))
                f.add(track, GPS.trk_ident, intern(p.trk_ident))
            else:
                if verbose: progress(`p`)
                point = f.newBlankNode()
                f.add(track, GPS.trackpoint, point)
                f.add(point, WGS.lat, obj=intern(degrees(p.slat)))
                f.add(point, WGS.long, obj=intern(degrees(p.slon)))
#               if verbose: progress("    time=", p.time)
#                progress('p.time='+`p.time`) # @@
                if p.time == 0 or p.time == 0xffffffffL:
                    if verbose: progress("time=%8x, ignoring" % p.time)
                else:
                    f.add(point, WGS.time, obj=intern(isodate.fullString(TimeEpoch+p.time)))

   phys.f.close()  # Should really be done by the del() below, but isn't
   del(phys) # close serial link (?)
   f = f.close()
   if verbose:
        progress("Beginning output. You can disconnect the GPS now.")
   s = f.n3String(base=base, flags="d")   # Flag - no default prefix, preserve gps: prefix hint
   if outputURI != None:
        op = open(outputURI, "w")
        op.write(s)
        op.close()
   else:
        print s 
예제 #5
0
def doCommand(serialDevice=None,
              outputURI=None,
              doTracks=1,
              doWaypoints=1,
              verbose=0):

    if os.name == 'nt':
        if not serialDevice: serialDevice = "com1"
        phys = Win32SerialLink(serialDevice)
    else:
        if not serialDevice: serialDevice = "/dev/ttyS0"
        #      serialDevice =  "/dev/cu.USA19H191P1.1"
        phys = UnixSerialLink(serialDevice)

    gps = Garmin(phys)

    print "GPS Product ID: %d Descriptions: %s Software version: %2.2f" % \
          (gps.prod_id, gps.prod_descs, gps.soft_ver)

    f = formula()  # Empty store of RDF data
    base = uripath.base()

    record = f.newBlankNode()
    f.add(record, RDF.type, GPS.Record)

    if doWaypoints:
        # show waypoints
        if verbose: print "Getting waypoints"
        wpts = gps.getWaypoints()
        for w in wpts:
            if verbose: progress( ` w `)
            wpt = symbol(uripath.join(base, w.ident))
            f.add(record, GPS.waypoint, wpt)
            f.add(wpt, WGS.lat, obj=intern(degrees(w.slat)))
            f.add(wpt, WGS.long, obj=intern(degrees(w.slon)))

    if doTracks:
        # show track
        if verbose: print "Getting tracks"
        tracks = gps.getTracks()
        for t in tracks:
            track = f.newBlankNode()
            f.add(record, GPS.track, track)
            for p in t:
                if isinstance(p, TrackHdr):
                    if verbose: progress( ` p `)
                    f.add(track, GPS.disp, intern(p.dspl))
                    f.add(track, GPS.color, intern(p.color))
                    f.add(track, GPS.trk_ident, intern(p.trk_ident))
                else:
                    if verbose: progress( ` p `)
                    point = f.newBlankNode()
                    f.add(track, GPS.trackpoint, point)
                    f.add(point, WGS.lat, obj=intern(degrees(p.slat)))
                    f.add(point, WGS.long, obj=intern(degrees(p.slon)))
                    #               if verbose: progress("    time=", p.time)
                    #                progress('p.time='+`p.time`) # @@
                    if p.time == 0 or p.time == 0xffffffffL:
                        if verbose: progress("time=%8x, ignoring" % p.time)
                    else:
                        f.add(point,
                              WGS.time,
                              obj=intern(isodate.fullString(TimeEpoch +
                                                            p.time)))

    phys.f.close()  # Should really be done by the del() below, but isn't
    del (phys)  # close serial link (?)
    f = f.close()
    if verbose:
        progress("Beginning output. You can disconnect the GPS now.")
    s = f.n3String(
        base=base,
        flags="d")  # Flag - no default prefix, preserve gps: prefix hint
    if outputURI != None:
        op = open(outputURI, "w")
        op.write(s)
        op.close()
    else:
        print s
예제 #6
0
 def add_position(self, tag, tag_name, latitude, longitude):
     position_tag = ET.SubElement(tag, tag_name)
     self.add_float(
         position_tag, 'LatitudeDegrees', garmin.degrees(latitude))
     self.add_float(
         position_tag, 'LongitudeDegrees', garmin.degrees(longitude))
예제 #7
0
#! /usr/bin/env python

import garmin

# Create a 'physical layer' connection using serial port
phys = garmin.UnixSerialLink("/dev/ttyS0")

# Create a Garmin object using this connection
gps = garmin.Garmin(phys)

# Get the waypoints from the GPS
# (This may take a little while)
waypoints = gps.getWaypoints()

# Print the waypoints
for w in waypoints:
    print w.ident,
    lat = garmin.degrees(w.slat)
    lon = garmin.degrees(w.slon)
    print lat, lon, w.cmnt