def airport_latlon(airport: str) -> LatLon: """ Find the latitude and longitude of an airport given that airport's 4-letter ICAO identifier. :param airport: Airport's 4-letter ICAO identifier. :return: LatLon object containing the airports latitude and longitude. """ db_listing = AIRPORT_DATA.get(airport) lat = db_listing[6] long = db_listing[7] return LatLon(parseDMS(lat, sep=':'), parseDMS(long, sep=':'))
def __new__(cls, arg, name='degrees', Error=UnitError, suffix='NSEW', clip=0): '''New named C{Degrees} instance. @arg cls: This class (C{Degrees} or sub-class). @arg arg: The value (any C{type} convertable to C{float} or parsable by L{parseDMS}). @kwarg name: Optional instance name (C{str}). @kwarg Error: Optional error to raise, overriding the default L{UnitError}. @kwarg suffix: Optional, valid compass direction suffixes (C{NSEW}). @kwarg clip: Optional B{C{arg}} range B{C{-clip..+clip}} (C{degrees} or C{0} or C{None} for unclipped). @returns: A C{Degrees} instance. @raise Error: Invalid B{C{arg}} or B{C{abs(deg)}} outside the B{C{clip}} range and L{rangerrors} set to C{True}. ''' try: return Float.__new__(cls, parseDMS(arg, suffix=suffix, clip=clip), name=name, Error=Error) except (RangeError, TypeError, ValueError) as _: x = str(_) # avoid Python 3+ nested exception messages raise _Error(cls, arg, name=name, Error=Error, txt=x)
def lon(self, lon): '''Set the longitude. @param lon: New longitude (C{str[E|W]} or C{degrees}). @raise ValueError: Invalid B{C{lon}}. ''' lon = parseDMS(lon, suffix='EW', clip=180) self._update(lon != self._lon) self._lon = lon
def lat(self, lat): '''Set the latitude. @param lat: New latitude (C{str[N|S]} or C{degrees}). @raise ValueError: Invalid B{C{lat}}. ''' lat = parseDMS(lat, suffix='NS', clip=90) self._update(lat != self._lat) self._lat = lat
def __new__(cls, arg=None, name=_degrees_, Error=UnitError, suffix=_NSEW_, clip=0, **name_arg): '''New named C{Degrees} instance. @arg cls: This class (C{Degrees} or sub-class). @kwarg arg: The value (any C{type} convertable to C{float} or parsable by L{parseDMS}). @kwarg name: Optional instance name (C{str}). @kwarg Error: Optional error to raise, overriding the default L{UnitError}. @kwarg suffix: Optional, valid compass direction suffixes (C{NSEW}). @kwarg clip: Optional B{C{arg}} range B{C{-clip..+clip}} (C{degrees} or C{0} or C{None} for unclipped). @kwarg name_arg: Optional C{name=arg} keyword argument, inlieu of B{C{name}} and B{C{arg}}. @returns: A C{Degrees} instance. @raise Error: Invalid B{C{arg}} or B{C{abs(deg)}} outside the B{C{clip}} range and L{rangerrors} set to C{True}. ''' if name_arg: name, arg = _xkwds_popitem(name_arg) try: return Float.__new__(cls, parseDMS(arg, suffix=suffix, clip=clip), name=name, Error=Error) except RangeError as x: t, E = str(x), type(x) except (TypeError, ValueError) as x: t, E = str(x), Error raise _Error(cls, arg, name=name, Error=E, txt=t)
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)
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)
# 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(
tags = next(csvData) tags = [element.upper() for element in tags] if "LONG" in tags: tags[tags.index('LONG')] = "LONGITUDE" if "LAT" in tags: tags[tags.index('LAT')] = "LATITUDE" if not set(['LATITUDE', 'LONGITUDE']).issubset(tags): raise Exception("LATITUDE and LONGITUDE are required but missing") row1 = next(csvData) row2 = next(csvData) deleted_points = [tags] new_route = [tags, row1] differences = [] for row in csvData: row3 = row point1 = (dms.parseDMS(row1[tags.index('LATITUDE')]), dms.parseDMS(row1[tags.index('LONGITUDE')])) point2 = (dms.parseDMS(row2[tags.index('LATITUDE')]), dms.parseDMS(row2[tags.index('LONGITUDE')])) point3 = (dms.parseDMS(row3[tags.index('LATITUDE')]), dms.parseDMS(row3[tags.index('LONGITUDE')])) distance1 = vincenty(point1, point2).m distance2 = vincenty(point2, point3).m distance3 = vincenty(point1, point3).m distance4 = distance1 + distance2 if args.diff_file: if 'NAME' in tags: rowname = row2[tags.index('NAME')] else: rowname = "Name not present" differences.append((rowname, point1, point2, point3, distance1,