コード例 #1
0
    def toStr(self, form=F_DMS, prec=None, m='m', sep=', '):  # PYCHOK expected
        '''Convert this point to a "lat, lon [+/-height]" string,
           formatted in the given form.

           @keyword form: Optional format, F_D, F_DM, F_DMS for
                          deg°, deg°min′, deg°min′sec″ (C{str}).
           @keyword prec: Optional number of decimal digits (0..8 or C{None}).
           @keyword m: Optional unit of the height (C{str}), use C{None}
                       to exclude height from the returned string.
           @keyword sep: Optional separator to join (C{str}).

           @return: Point in the specified form (C{str}).

           @example:

           >>> LatLon(51.4778, -0.0016).toStr()  # 51°28′40″N, 000°00′06″W
           >>> LatLon(51.4778, -0.0016).toStr(F_D)  # 51.4778°N, 000.0016°W
           >>> LatLon(51.4778, -0.0016, 42).toStr()  # 51°28′40″N, 000°00′06″W, +42.00m

        '''
        t = [
            latDMS(self.lat, form=form, prec=prec),
            lonDMS(self.lon, form=form, prec=prec)
        ]
        if self.height and m is not None:
            t += ['%+.2f%s' % (self.height, m)]
        return sep.join(t)
コード例 #2
0
    def convertFile(self):

        coord_system = self.left_coord_sys_file.currentText()
        crs_name = self.left_crs_select_file.currentText()
        left_coord = coord_system
        left_crs = crs_name
        crs_from = crsObject[coord_system][crs_name][0]
        crs_from_type = crsObject[coord_system][crs_name][1]
        coord_system = self.right_coord_sys_file.currentText()
        crs_name = self.right_crs_select_file.currentText()
        right_coord = coord_system
        right_crs = crs_name
        crs_to = crsObject[coord_system][crs_name][0]
        crs_to_type = crsObject[coord_system][crs_name][1]

        dms_format = settings['ang_fmt']
        precision = settings['ang_prec']
        lin_format = settings['lin_fmt']

        # crs_from = 4326
        # crs_to = 3124
        trans = Transformer.from_crs(crs_from, crs_to)

        # iterate over model, get values of columns  0 and 1, calculate values for cols 3 and 4
        no_rows = self.tableview.model().rowCount(self.tableview.rootIndex())

        model = self.tableview.model()

        # get columns for data
        lat_col = self.combo_lat.currentText()
        lon_col = self.combo_lon.currentText()
        northing_col = self.combo_northing.currentText()
        easting_col = self.combo_easting.currentText()

        for row in self.data.index:
            if crs_from_type == 'geographic':
                lat = parseDMS(self.data.loc[row, lat_col])
                lon = parseDMS(self.data.loc[row, lon_col])
                # make input column formats reflect user seleccted format
                self.data.loc[row, lat_col] = latDMS(lat, form=dms_format, prec=precision)
                self.data.loc[row, lon_col] = latDMS(lon, form=dms_format, prec=precision)
            else:
                lon = self.data.loc[row, lat_col]
                lat = self.data.at[row, lon_col]
            results = trans.transform(lat, lon, errcheck=True)
            if crs_to_type == 'geographic':
                # set column data type to string
                self.data[northing_col] = self.data[northing_col].astype('str')
                self.data[easting_col] = self.data[easting_col].astype('str')
                lat_dms = latDMS(results[0], form=dms_format, prec=precision)
                lon_dms = latDMS(results[1], form=dms_format, prec=precision)

                self.data.loc[row, northing_col] = lat_dms
                self.data.loc[row, easting_col] = lon_dms

            else:
                self.data.loc[row, northing_col] = lin_format.format(results[1])
                self.data.loc[row, easting_col] = lin_format.format(results[0])
        # reset the model to show the newly computed values
        model = TableModel(self.data)
        self.tableview.setModel(model)

        # save coordinate system selections
        settings['left_coord'] = left_coord
        settings['left_crs'] = left_crs
        settings['right_coord'] = right_coord
        settings['right_crs'] = right_crs

        with open('coordsys.ini', 'wb') as f:
            pickle.dump(settings, f)
コード例 #3
0
ファイル: sensors.py プロジェクト: jacky4566/ykpilot
	def update(self, val):
		self.iter+= 1
		if self.avgPos[0] == None:
			self.avgPos = [ val['lat'],val['lon'] ]
			self.lat = val['lat']
			self.lon = val['lon']
		
		self.avgPos[0] = (self.avgPos[0]*self.avgReadings)+(val['lat']*(1.0-self.avgReadings))
		self.avgPos[1] = (self.avgPos[1]*self.avgReadings)+(val['lon']*(1.0-self.avgReadings))
		
		doIt = True
		
		tSinceLast = (self.th.getTimestamp(True)-self.updateTime)/1000000.0
		
		if tSinceLast < 0.5:
			doIt = False
		else:
			#print("-----------------")
			#print("time since last",tSinceLast)
			
			pavg = LatLon( self.avgPos[0], self.avgPos[1] )
			pNew = LatLon( val['lat'], val['lon'])
			dis = pavg.distanceTo(pNew)
			spe = (( dis/1000.00 )/tSinceLast)*60.0*60.0
			self.sog = (spe*0.539957) # to nm
			self.cog = pavg.bearingTo(pNew)
			#print("distance is ",dis)
			if spe > 100.00:
				doIt = False
				print( "gps data Dump to fast ! ",
					"Speed is ",spe," km/h"
					)
		if doIt:
			self.lat = val['lat']
			self.guiObjs['lat'].text = "%s"%self.lat
			self.lon = val['lon']		
			self.guiObjs['lon'].text = "%s"%self.lon
			
			self.gpssog = val['speed']
			self.guiObjs['sog'].text = "%s / %s"%(round(self.gpssog,2), round(self.sog,2))
			self.guiObjs['lSRacSog'].text = "%s" % round(self.sog,1)
			if self.maxSog < self.sog:
				self.maxSog = self.sog
			self.guiObjs['lSRacSogMax'].text = "max: %s" % round(self.maxSog,2)
			self.avgSog = (self.avgSog*0.998)+(self.sog*0.002)
			val['avgSog'] = self.avgSog
			self.guiObjs['lSRacSogAvg'].text = "avg: %s" % round(self.avgSog,2)
			
			
			self.gpscog = val['bearing']
			self.guiObjs['cog'].text = "%s / %s"%(round(self.gpscog,1), round(self.cog,1))
			self.avgCog = (self.avgCog*0.998)+(self.gpssog*0.002)
			val['avgCog'] = self.avgCog
			
			self.accur = val['accuracy']		
			self.guiObjs['accur'].text = "%s"%round(self.accur,0)
			
			self.updateTime = self.th.getTimestamp(True)
			
			# nmea
			latRaw = dms.latDMS( self.lat,form=dms.F_DM,prec=6).replace('°','').replace('′','')
			latDM = latRaw[:-1]
			latNS = latRaw[-1]
			lonRaw = dms.lonDMS( self.lon,form=dms.F_DM,prec=6).replace('°','').replace('′','')
			lonDM = lonRaw[:-1]
			lonEW = lonRaw[-1]
			msg = ("$YKRMC,,A,%s,%s,%s,%s,%s,%s,,,,A"%(latDM,latNS,lonDM,lonEW,round(self.sog,2),round(self.cog,2)))
			self.gui.sf.sendToAll(msg)
			
			if self.gui.isReady:
				# callbacks
				for o in self.callBacksForUpdate:
					o.update('gps', val)
				
				# json
				jMsg = str({
					"type": "gps",
					"data": val
					})
				self.gui.sf.sendToAll( jMsg )
コード例 #4
0
    def convertCoords(self):

        # clear old results
        self.clearNorthEast()

        coord_system = self.left_coord_sys.currentText()
        crs_name = self.left_crs_select.currentText()
        left_coord = coord_system
        left_crs = crs_name
        crs_from = crsObject[coord_system][crs_name][0]
        crs_from_type = crsObject[coord_system][crs_name][1]
        coord_system = self.right_coord_sys.currentText()
        crs_name = self.right_crs_select.currentText()
        right_coord = coord_system
        right_crs = crs_name
        crs_to = crsObject[coord_system][crs_name][0]
        crs_to_type = crsObject[coord_system][crs_name][1]

        # check to see that inputs are valid...
        if crs_from_type == 'geographic':
            pass

        # # set up appropriate formats
        # if self.optDms.isChecked():
        dms_format = settings['ang_fmt']
        precision = settings['ang_prec']

        lin_format = settings['lin_fmt']

        # Display EPSG codes  for conversion in status bar
        self.statusBar().showMessage('Coordinate transform from EPSG ' + str(crs_from) + ' to EPSG ' + str(crs_to))

        # process left side of conversion
        if crs_from_type == 'geographic':
            # parse the latitude, longitude input boxes using pyGeodesy function
            # check the entered values to ensure they are valid
            try:
                lat = parseDMS(self.latitude.text())
                if lat > 90.0 or lat < -90.0:
                    self.statusBar().showMessage('Latitude must be between -90 and +90')
                    return
            except ValueError:
                self.statusBar().showMessage('Invalid latitude')
                return
            try:
                lon = parseDMS(self.longitude.text())
                if lon > 180.0 or lon < -180.0:
                    self.statusBar().showMessage('Longitude must be between -180 and +180')
                    return
            except ValueError:
                self.statusBar().showMessage('Invalid longitude')
                return
        else:  # crs type is 'projected' need to reverse northing and easting
            if self.latitude.text() == '' or self.longitude.text() == '':
                self.statusBar().showMessage('Northing and/or easting cannot be blank')
                return
            try:
                lat = float(self.latitude.text().replace(',', ''))
            except ValueError:
                self.statusBar().showMessage('Invalid northing')
                return
            try:
                lon = float(self.longitude.text().replace(',', ''))
            except ValueError:
                self.statusBar().showMessage('Invalid easting')
                return

        # Do the transformation
        try:
            trans = Transformer.from_crs(crs_from, crs_to)
            if crs_from_type == 'geographic':
                results = trans.transform(lat, lon, errcheck=True)
            else:
                results = trans.transform(lon, lat, errcheck=True)
        except:
            print('transform error')
            self.statusBar().showMessage('Invalid conversion')
            return

        # output results according to crs_type
        if crs_to_type == 'projected':
            north = lin_format.format(results[1])
            east = lin_format.format(results[0])
            self.northing.setText(north)
            self.easting.setText(east)
        else:
            self.northing.setText(latDMS(results[0], form=dms_format, prec=precision))
            self.easting.setText(lonDMS(results[1], form=dms_format, prec=precision))

        if crs_from_type == 'geographic':
            self.latitude.setText(latDMS(lat, form=dms_format, prec=precision))
            self.longitude.setText(lonDMS(lon, form=dms_format, prec=precision))
        else:
            north = lin_format.format(lat)
            east = lin_format.format(lon)
            self.latitude.setText(north)
            self.longitude.setText(east)

        # save coordinate system selections
        settings['left_coord'] = left_coord
        settings['left_crs'] = left_crs
        settings['right_coord'] = right_coord
        settings['right_crs'] = right_crs

        with open('coordsys.ini', 'wb') as f:
            pickle.dump(settings, f)
コード例 #5
0
# TRACK Files don't have names or types, add them in with derived or specified versions
    if not endOfSegment and rowNum < 100:
        if not namePresent:
            row.insert(
                tags.index('NAME'),
                args.name + letter[fileNum - 1] + "_" + '{0}'.format(rowNum))
        elif args.replace:
            row[tags.index('NAME')] = args.name + letter[
                fileNum - 1] + "_" + '{0}'.format(rowNum)
        row.insert(tags.index('TYPE'), args.pointtype)
        # At this point in the process, we have a fully populated row that can be buffered as an xml item
        xmlBuffer += "<" + xmlRowType[args.type] + ">" + "\n"
        for tag, item in zip(tags, row):
            # Make sure that the LATITUDE and LONGITUDE are in the format specified by the "format" option
            if tag.upper() in lat_list:
                item = dms.normDMS(dms.latDMS(dms.parseDMS(item), args.format,
                                              3),
                                   norm=" ")

            if tag.upper() in lon_list:
                item = dms.normDMS(dms.lonDMS(dms.parseDMS(item), args.format,
                                              3),
                                   norm=" ")
            xmlBuffer += '    ' + '<' + tag + '>' \
                          + item + '</' + tag + '>' + "\n"
        xmlBuffer += "</" + xmlRowType[args.type] + ">" + "\n"
        rowNum += 1
        rowWritten = True
    else:
        if rowWritten:
            xmlData = open(
                baseFileName + "_" + '{0}'.format(fileNum) + baseFileExt, "w")