def to_station_feature(self, station: dict, fields: QgsFields) -> QgsFeature: """ Creates a station feature """ f = QgsFeature(fields) for k, v in station.items(): try: if fields[fields.lookupField(k)].type() == QVariant.DateTime: v = v.replace('--', '00') v = QDateTime.fromString(v, Qt.ISODate) elif fields[fields.lookupField(k)].type() == QVariant.Date: v = QDate.fromString(v, Qt.ISODate) elif fields[fields.lookupField(k)].type() == QVariant.Time: v = QTime.fromString(v, Qt.ISODate) elif fields[fields.lookupField(k)].type() == QVariant.Double: v = float(v) elif fields[fields.lookupField(k)].type() == QVariant.Int: v = int(v) except Exception: # pylint: disable=broad-except v = NULL f[k] = v if station.get('Latitude') and station.get('Longitude'): geom = QgsPoint(x=float(station['Longitude']), y=float(station['Latitude'])) f.setGeometry(QgsGeometry(geom)) return f
def to_mdp_feature(self, event: dict, fields: QgsFields) -> QgsFeature: """ Converts results to a MDP feature """ f = QgsFeature(fields) for k, v in event.items(): try: if fields[fields.lookupField(k)].type() == QVariant.DateTime: v = v.replace('--', '00') v = QDateTime.fromString(v, Qt.ISODate) elif fields[fields.lookupField(k)].type() == QVariant.Date: v = QDate.fromString(v, Qt.ISODate) elif fields[fields.lookupField(k)].type() == QVariant.Time: v = QTime.fromString(v, Qt.ISODate) elif fields[fields.lookupField(k)].type() == QVariant.Double: v = float(v) elif fields[fields.lookupField(k)].type() == QVariant.Int: v = int(v) except Exception: # pylint: disable=broad-except v = NULL f[k] = v if event.get('ReferenceLatitude') and event.get('ReferenceLongitude'): geom = QgsPoint(x=float(event['ReferenceLongitude']), y=float(event['ReferenceLatitude'])) f.setGeometry(QgsGeometry(geom)) return f
def global_settings_defaults(self): """Global settings defaults.""" defaults = { "id": 1, "advection_1d": 1, "advection_2d": 1, "control_group_id": None, "dem_file": None, "dem_obstacle_detection": 0, "dem_obstacle_height": None, "dist_calc_points": 1000.0, "embedded_cutoff_threshold": 0.05, "epsg_code": None, "flooding_threshold": 0.0001, "frict_avg": 0, "frict_coef": None, "frict_coef_file": None, "frict_type": None, "grid_space": 0.0, "groundwater_settings_id": None, "initial_groundwater_level": None, "initial_groundwater_level_file": None, "initial_groundwater_level_type": None, "initial_waterlevel": -99.0, "initial_waterlevel_file": None, "interflow_settings_id": None, "interception_global": None, "interception_file": None, "max_interception": None, "max_interception_file": None, "kmax": 1, "manhole_storage_area": None, "max_angle_1d_advection": 90.0, "maximum_sim_time_step": None, "minimum_sim_time_step": 0.01, "name": "default", "nr_timesteps": 9999, "numerical_settings_id": 1, "output_time_step": None, "sim_time_step": None, "simple_infiltration_settings_id": None, "start_date": QDate.fromString("2000-01-01", "yyyy-MM-dd"), "start_time": QTime.fromString("00:00:00", "HH:MM:SS"), "table_step_size": 0.01, "table_step_size_1d": 0.01, "table_step_size_volume_2d": None, "timestep_plus": 0, "use_0d_inflow": None, "use_1d_flow": None, "use_2d_flow": None, "use_2d_rain": None, "water_level_ini_type": None, "wind_shielding_file": None, } return defaults
def getSelectedTime(self): """ Returns the currently selected data and time """ try: hour = self.hourpicker.currentItem().text() except AttributeError: hour = "" try: minute = self.minutepicker.currentItem().text() except AttributeError: minute = "" zone = self.ambutton.isChecked() and "AM" or "PM" return QTime.fromString("%s%s%s" % (hour.zfill(2), minute.zfill(2), zone), "hhmAP")
def set_widgets_parameters(main_widget, find_combobox_text=True, **widget_parameters): """Set widget children values based on derived parameters.""" for name, value in widget_parameters.items(): widget = getattr(main_widget, name, None) if widget is None: continue if isinstance(widget, QLineEdit): widget.setText(value) elif isinstance(widget, (QCheckBox, QRadioButton)): widget.setChecked(value) elif isinstance(widget, QComboBox): idx = widget.findText(value) if find_combobox_text else value widget.setCurrentIndex(idx) elif isinstance(widget, QDateEdit): widget.setDate(QDate.fromString(value, "yyyy-MM-dd")) elif isinstance(widget, QTimeEdit): widget.setTime(QTime.fromString(value, "H:m")) elif isinstance(widget, (QSpinBox, QDoubleSpinBox)): widget.setValue(value)
def to_event_feature(self, event: dict, fields: QgsFields) -> QgsFeature: # pylint: disable=too-many-branches """ Converts an event to a feature """ f = QgsFeature(fields) for k, v in event.items(): if k == 'Depth/km' and self.depth_unit == QgsUnitTypes.DistanceMeters: k = 'DepthMeters' elif k == 'Depth/km': k = 'DepthKm' try: if fields[fields.lookupField(k)].type() == QVariant.DateTime: v = v.replace('--', '00') v = QDateTime.fromString(v, Qt.ISODate) elif fields[fields.lookupField(k)].type() == QVariant.Date: v = QDate.fromString(v, Qt.ISODate) elif fields[fields.lookupField(k)].type() == QVariant.Time: v = QTime.fromString(v, Qt.ISODate) elif fields[fields.lookupField(k)].type() == QVariant.Double: v = float(v) elif fields[fields.lookupField(k)].type() == QVariant.Int: v = int(v) elif fields[fields.lookupField(k)].type() == QVariant.String: v = v.replace('--', '') except Exception: # pylint: disable=broad-except v = NULL if k in ('DepthKm', 'DepthMeters') and v != NULL: if self.depth_unit == QgsUnitTypes.DistanceMeters: v *= 1000 if self.convert_negative_depths: v = -v f[k] = v if event.get('Latitude') and event.get('Longitude'): geom = QgsPoint(x=float(event['Longitude']), y=float(event['Latitude'])) f.setGeometry(QgsGeometry(geom)) return f