def __init__(self,mole): #, progress_model): #from qgis import utils #standard_workflow = utils.plugins['mole'].standard_workflow QtGui.QDockWidget.__init__(self) self.setupUi(self) self._check_mark = QtGui.QPixmap(_fromUtf8(":/Controls/icons/checkmark.png")) self._open_mark = QtGui.QPixmap(_fromUtf8(":/Controls/icons/openmark.png")) self._semiopen_mark = QtGui.QPixmap(_fromUtf8(":/Controls/icons/semiopenmark.png")) #self.progress_model = progress_model self.ol_plugin_installed.pressed.connect(lambda: mole.standard_workflow.do_workstep('ol_plugin_installed')) self.pst_plugin_installed.pressed.connect(lambda: mole.standard_workflow.do_workstep('pst_plugin_installed')) self.real_centroid_plugin_installed.pressed.connect(lambda: mole.standard_workflow.do_workstep('real_centroid_plugin_installed')) self.project_created.pressed.connect(lambda: mole.standard_workflow.do_workstep('project_created')) self.project_saved.pressed.connect(lambda: mole.standard_workflow.do_workstep('project_saved')) self.investigationarea_defined.pressed.connect(lambda: mole.standard_workflow.do_workstep('investigationarea_defined')) self.building_outlines_acquired.pressed.connect(lambda: mole.standard_workflow.do_workstep('building_outlines_acquired')) self.building_coordinates_acquired.pressed.connect(lambda: mole.standard_workflow.do_workstep('building_coordinates_acquired')) self.import_ext_selected.pressed.connect(lambda: mole.standard_workflow.do_workstep('import_ext_selected')) self.information_layers_loaded.pressed.connect(lambda: mole.standard_workflow.do_workstep('information_layers_loaded')) self.needle_request_done.pressed.connect(lambda: mole.standard_workflow.do_workstep('needle_request_done')) self.database_created.pressed.connect(lambda: mole.standard_workflow.do_workstep('database_created')) self.buildings_evaluated.pressed.connect(lambda: mole.standard_workflow.do_workstep('buildings_evaluated')) self.json_export_done.pressed.connect(mole.export_database_to_json) self.sqlite_export_done.pressed.connect(mole.export_database_to_sqlite) self.csv_export_done.pressed.connect(mole.export_database_to_csv) self.process_button_next.clicked.connect(lambda: self.call_next_workstep(mole)) self.run_button.clicked.connect(lambda: self.run_automode(mole))
def get_location_from_web(self, index): index -= 1 self.lineedit_city_layout() self.location_city.setText(self.municipals[index]['NAME']) self.location_postal.setText(str(self.municipals[index]['POSTCODE'])) pop_dens = '{}'.format(self.municipals[index]['POP_DENS']) self.population_density.setText(pop_dens) avg_yoc = '{}'.format(self.municipals[index]['AVG_YOC']) self.average_build_year.setText(avg_yoc) citystring = ' '.join( [self.location_postal.text(), self.location_city.text()]) address = ', '.join( [config.country, citystring, self.location_street.text()]) self.found_locations = googlemaps.getCoordinatesByAddress(address, crs=4326) if len(self.found_locations) == 1: self.update_form(1) elif len(self.found_locations) > 1: self.combobox_city_layout() self.location_city.clear() self.location_city.addItem(_fromUtf8(u'< Select Location >')) for loc in self.found_locations: self.location_city.addItem(_fromUtf8( loc['formatted_location'])) self.location_city.currentIndexChanged.connect(self.update_form)
def save_color_map(self): """ Save the currently open color-map as a qml-file into the project folder. :return: :rtype: """ from mole import extensions layer = iface.activeLayer() selected_layer = self.layers_dropdown.currentText() if layer.name() != selected_layer: layer = layer_interaction.find_layer_by_name(selected_layer) out_path = os.path.dirname(layer.publicSource()) out_path = os.path.join(out_path, layer.name() + '.qml') self.update_color_values() entry_written = self.color_entry_manager.write_color_map_as_qml(layer.name(), out_path) if entry_written: self.message_label.setStyleSheet(_fromUtf8("color: green;")) self.message_label.setText('Success - Legend was successfully written to \n\t"{}".'.format(out_path)) else: self.message_label.setStyleSheet(_fromUtf8("color: red;")) self.message_label.setText('Failure - Could not write legend to to \n\t"{}".'.format(out_path)) activeextensions = extensions.by_layername(layer.name()) try: activeextensions[0].colortable = out_path except: pass
def save_color_map(self): """ Save the currently open color-map as a qml-file into the project folder. :return: :rtype: """ from mole import extensions layer = iface.activeLayer() selected_layer = self.layers_dropdown.currentText() if layer.name() != selected_layer: layer = layer_interaction.find_layer_by_name(selected_layer) out_path = os.path.dirname(layer.publicSource()) out_path = os.path.join(out_path, layer.name() + '.qml') self.update_color_values() entry_written = self.color_entry_manager.write_color_map_as_qml( layer.name(), out_path) if entry_written: self.message_label.setStyleSheet(_fromUtf8("color: green;")) self.message_label.setText( 'Success - Legend was successfully written to \n\t"{}".'. format(out_path)) else: self.message_label.setStyleSheet(_fromUtf8("color: red;")) self.message_label.setText( 'Failure - Could not write legend to to \n\t"{}".'.format( out_path)) activeextensions = extensions.by_layername(layer.name()) try: activeextensions[0].colortable = out_path except: pass
def find_municipal_information(self): city = self.location_city.text() postal = self.location_postal.text() if ((city == '') | (city == u'')): if ((postal != '') & (postal != u'')): self.municipals = filter( lambda x: str(x['POSTCODE']).startswith(postal), self.municipal_information.municipal_db) if len(self.municipals) > 0: if len(self.municipals) == 1: self.lineedit_city_layout(self.municipals[0]['NAME']) self.location_city.setText(self.municipals[0]['NAME']) self.location_city.editingFinished.connect( self.location_by_address, True) pop_dens = '{}'.format(self.municipals[0]['POP_DENS']) self.population_density.setText(pop_dens) avg_yoc = '{}'.format(self.municipals[0]['AVG_YOC']) self.average_build_year.setText(avg_yoc) else: self.combobox_city_layout() for i in [ i['POSTCODE'] + ' ' + i['NAME'] for i in self.municipals ]: self.location_city.addItem(_fromUtf8(i)) self.location_city.currentIndexChanged.connect( self.set_city) else: if ((city != '') & (city != u'')): self.municipals = filter( lambda x: ((x['NAME'] == city) | x['NAME'].startswith( city + ',') | x['NAME'].startswith(city + ' ')), self.municipal_information.municipal_db) if len(self.municipals) > 0: if len(self.municipals) == 1: self.lineedit_postal_layout() self.location_postal.setText( str(self.municipals[0]['POSTCODE'])) pop_dens = '{}'.format(self.municipals[0]['POP_DENS']) self.population_density.setText(pop_dens) avg_yoc = '{}'.format(self.municipals[0]['AVG_YOC']) self.average_build_year.setText(avg_yoc) else: self.combobox_postal_layout() for i in [ i['POSTCODE'] + ' ' + i['NAME'] for i in self.municipals ]: self.location_postal.addItem(_fromUtf8(i)) self.location_postal.currentIndexChanged.connect( self.set_postal)
def __init__(self, mole): #, progress_model): #from qgis import utils #standard_workflow = utils.plugins['mole'].standard_workflow QtGui.QDockWidget.__init__(self) self.setupUi(self) self._check_mark = QtGui.QPixmap( _fromUtf8(":/Controls/icons/checkmark.png")) self._open_mark = QtGui.QPixmap( _fromUtf8(":/Controls/icons/openmark.png")) self._semiopen_mark = QtGui.QPixmap( _fromUtf8(":/Controls/icons/semiopenmark.png")) #self.progress_model = progress_model self.ol_plugin_installed.pressed.connect( lambda: mole.standard_workflow.do_workstep('ol_plugin_installed')) self.pst_plugin_installed.pressed.connect( lambda: mole.standard_workflow.do_workstep('pst_plugin_installed')) self.real_centroid_plugin_installed.pressed.connect( lambda: mole.standard_workflow.do_workstep( 'real_centroid_plugin_installed')) self.project_created.pressed.connect( lambda: mole.standard_workflow.do_workstep('project_created')) self.project_saved.pressed.connect( lambda: mole.standard_workflow.do_workstep('project_saved')) self.investigationarea_defined.pressed.connect( lambda: mole.standard_workflow.do_workstep( 'investigationarea_defined')) self.building_outlines_acquired.pressed.connect( lambda: mole.standard_workflow.do_workstep( 'building_outlines_acquired')) self.building_coordinates_acquired.pressed.connect( lambda: mole.standard_workflow.do_workstep( 'building_coordinates_acquired')) self.import_ext_selected.pressed.connect( lambda: mole.standard_workflow.do_workstep('import_ext_selected')) self.information_layers_loaded.pressed.connect( lambda: mole.standard_workflow.do_workstep( 'information_layers_loaded')) self.needle_request_done.pressed.connect( lambda: mole.standard_workflow.do_workstep('needle_request_done')) self.database_created.pressed.connect( lambda: mole.standard_workflow.do_workstep('database_created')) self.buildings_evaluated.pressed.connect( lambda: mole.standard_workflow.do_workstep('buildings_evaluated')) self.json_export_done.pressed.connect(mole.export_database_to_json) self.sqlite_export_done.pressed.connect(mole.export_database_to_sqlite) self.csv_export_done.pressed.connect(mole.export_database_to_csv) self.process_button_next.clicked.connect( lambda: self.call_next_workstep(mole)) self.run_button.clicked.connect(lambda: self.run_automode(mole))
def add_color(self, color): """ Insert a new color (and the values associated to it, if any), into the color-table. :param color: The color in RGBa :type color: QColor :return: :rtype: """ from mole import extensions layer = self.layers_dropdown.currentText() self.recent_layer = layer color_map = self.color_entry_manager.layer_values_map[layer] model = QColorTableModel(color_map, self.header, self) self.color_table_view.setModel(model) color_key = 'RGBa({}, {}, {}, {})'.format(color.red(), color.green(), color.blue(), color.alpha()) if color_map.has_key(color_key): self.message_label.setStyleSheet(_fromUtf8("color: red;")) self.message_label.setText('Attention: Color {} is defined already.'.format(color_key)) else: self.message_label.clear() #ToDo change to use the correct para-name instead #parameter_name = str(self.layers_dropdown.currentText())[:10] parameter_name = extensions.by_layername(layer) if not parameter_name: return None parameter_name = parameter_name[0].field_id self.color_entry_manager.add_color_value_quadruple_to_layer([color_key, parameter_name, 0, 0], layer) color_map = self.color_entry_manager.layer_values_map[layer] model = QColorTableModel(color_map, self.header, self) self.color_table_view.setModel(model) self.raise_()
def location_by_coordinates(self): #if not issubclass(type(self.location_city), QtGui.QLineEdit): return None #if not issubclass(type(self.location_postal), QtGui.QLineEdit): return None lat = float(self.location_lat.text()) lon = float(self.location_lon.text()) crs = self.location_crs.text() if crs: crs=int(crs[5:]) self.found_locations = googlemaps.getBuildingLocationDataByCoordinates(lon, lat, crs) if len(self.found_locations) == 1: self.update_form(1) elif len(self.found_locations) > 1: self.combobox_city_layout() self.location_city.clear() self.location_city.addItem(_fromUtf8(u'< Select Project Location >')) for loc in self.found_locations: self.location_city.addItem(_fromUtf8(loc['formatted_location'])) self.location_city.currentIndexChanged.connect(self.update_form)
def lineedit_postal_layout(self, text=''): location_box = self.gridLayout.findChild(QtGui.QHBoxLayout, 'location_postal_layout') location_edit = location_box.itemAt(0).widget() if isinstance(location_edit, QtGui.QComboBox): location_box.removeWidget(location_edit) location_edit.deleteLater() self.location_postal = QtGui.QLineEdit(self.form) self.location_postal.setMinimumWidth(228) self.location_postal.setObjectName(_fromUtf8("location_postal")) self.location_postal.setStyleSheet('color: rgb(0,0,0)') location_box.insertWidget(0, self.location_postal)
def combobox_city_layout(self, entries=[]): location_box = self.gridLayout.findChild(QtGui.QHBoxLayout, 'location_city_layout') city_edit = location_box.itemAt(0).widget() if isinstance(city_edit, QtGui.QLineEdit): location_box.removeWidget(city_edit) width = city_edit.minimumWidth() city_edit.deleteLater() self.location_city = QtGui.QComboBox(self.form) self.location_city.setObjectName(_fromUtf8("location_city")) self.location_city.setMinimumWidth(width) location_box.insertWidget(0, self.location_city)
def location_by_coordinates(self): #if not issubclass(type(self.location_city), QtGui.QLineEdit): return None #if not issubclass(type(self.location_postal), QtGui.QLineEdit): return None lat = float(self.location_lat.text()) lon = float(self.location_lon.text()) crs = self.location_crs.text() if crs: crs = int(crs[5:]) self.found_locations = googlemaps.getBuildingLocationDataByCoordinates( lon, lat, crs) if len(self.found_locations) == 1: self.update_form(1) elif len(self.found_locations) > 1: self.combobox_city_layout() self.location_city.clear() self.location_city.addItem( _fromUtf8(u'< Select Project Location >')) for loc in self.found_locations: self.location_city.addItem(_fromUtf8( loc['formatted_location'])) self.location_city.currentIndexChanged.connect(self.update_form)
def get_location_from_web(self,index): index -= 1 self.lineedit_city_layout() self.location_city.setText(self.municipals[index]['NAME']) self.location_postal.setText(str(self.municipals[index]['POSTCODE'])) pop_dens = '{}'.format(self.municipals[index]['POP_DENS']) self.population_density.setText(pop_dens) avg_yoc = '{}'.format(self.municipals[index]['AVG_YOC']) self.average_build_year.setText(avg_yoc) citystring = ' '.join([self.location_postal.text(),self.location_city.text()]) address = ', '.join([config.country, citystring, self.location_street.text()]) self.found_locations = googlemaps.getCoordinatesByAddress(address, crs=4326) if len(self.found_locations) == 1: self.update_form(1) elif len(self.found_locations) > 1: self.combobox_city_layout() self.location_city.clear() self.location_city.addItem(_fromUtf8(u'< Select Location >')) for loc in self.found_locations: self.location_city.addItem(_fromUtf8(loc['formatted_location'])) self.location_city.currentIndexChanged.connect(self.update_form)
def lineedit_city_layout(self, text=''): location_box = self.gridLayout.findChild(QtGui.QHBoxLayout, 'location_city_layout') city_edit = location_box.itemAt(0).widget() if isinstance(city_edit, QtGui.QComboBox): location_box.removeWidget(city_edit) city_edit.deleteLater() self.location_city = QtGui.QLineEdit(self.form) self.location_city.setMinimumWidth(228) self.location_city.setObjectName(_fromUtf8("location_city")) self.location_city.setStyleSheet('color: rgb(0,0,0)') location_box.insertWidget(0, self.location_city)
def combobox_city_layout(self, entries=[]): location_box = self.gridLayout.findChild(QtGui.QHBoxLayout, 'location_city_layout') city_edit = location_box.itemAt(0).widget() if isinstance(city_edit, QtGui.QLineEdit): location_box.removeWidget(city_edit) width = city_edit.minimumWidth() city_edit.deleteLater() self.location_city = QtGui.QComboBox(self.form) self.location_city.setObjectName(_fromUtf8("location_city")) self.location_city.setMinimumWidth(width) location_box.insertWidget(0, self.location_city)
def check_character_constraint(self, parameter_name): """ Check if the parameter-name has a length of ten characters at most, since layer-attributes are limited to 10 characters. :param parameter_name: :type parameter_name: :return: :rtype: """ if len(parameter_name) == 10 and parameter_name != 'Parameter ': self.message_label.setStyleSheet(_fromUtf8("color: red;")) self.message_label.setText('Warning: A maximum of 10 characters is allowed as a parameter name!') else: self.message_label.clear()
def find_municipal_information(self): city = self.location_city.text() postal = self.location_postal.text() if ((city == '') | (city == u'')): if ((postal != '') & (postal != u'')): self.municipals = filter(lambda x : str(x['POSTCODE']).startswith(postal) , self.municipal_information.municipal_db) if len(self.municipals) > 0: if len(self.municipals) == 1: self.lineedit_city_layout(self.municipals[0]['NAME']) self.location_city.setText(self.municipals[0]['NAME']) self.location_city.editingFinished.connect(self.location_by_address, True) pop_dens = '{}'.format(self.municipals[0]['POP_DENS']) self.population_density.setText(pop_dens) avg_yoc = '{}'.format(self.municipals[0]['AVG_YOC']) self.average_build_year.setText(avg_yoc) else: self.combobox_city_layout() for i in [i['POSTCODE']+' '+i['NAME'] for i in self.municipals]: self.location_city.addItem(_fromUtf8(i)) self.location_city.currentIndexChanged.connect(self.set_city) else: if ((city != '') & (city != u'')): self.municipals = filter(lambda x : ((x['NAME'] == city) | x['NAME'].startswith(city+',') | x['NAME'].startswith(city+' ')) , self.municipal_information.municipal_db) if len(self.municipals) > 0: if len(self.municipals) == 1: self.lineedit_postal_layout() self.location_postal.setText(str(self.municipals[0]['POSTCODE'])) pop_dens = '{}'.format(self.municipals[0]['POP_DENS']) self.population_density.setText(pop_dens) avg_yoc = '{}'.format(self.municipals[0]['AVG_YOC']) self.average_build_year.setText(avg_yoc) else: self.combobox_postal_layout() for i in [i['POSTCODE']+' '+i['NAME'] for i in self.municipals]: self.location_postal.addItem(_fromUtf8(i)) self.location_postal.currentIndexChanged.connect(self.set_postal)
def check_character_constraint(self, parameter_name): """ Check if the parameter-name has a length of ten characters at most, since layer-attributes are limited to 10 characters. :param parameter_name: :type parameter_name: :return: :rtype: """ if len(parameter_name) == 10 and parameter_name != 'Parameter ': self.message_label.setStyleSheet(_fromUtf8("color: red;")) self.message_label.setText( 'Warning: A maximum of 10 characters is allowed as a parameter name!' ) else: self.message_label.clear()
def location_by_address(self): #if not issubclass(type(self.location_city), QtGui.QLineEdit): return None #if not issubclass(type(self.location_postal), QtGui.QLineEdit): return None if oeq_global.isEmpty(self.location_city.text()) & oeq_global.isEmpty(self.location_street.text()) & (not oeq_global.isEmpty(self.location_postal.text())): postal = self.location_postal.text() self.municipals = filter(lambda x : str(x['POSTCODE']).startswith(postal) , self.municipal_information.municipal_db) if len(self.municipals) > 0: if len(self.municipals) == 1: self.lineedit_city_layout() self.location_city.setText(self.municipals[0]['NAME']) self.location_postal.setText(str(self.municipals[0]['POSTCODE'])) self.get_location_from_web(1) else: self.combobox_city_layout() self.location_city.addItem(_fromUtf8(u'< Select Location >')) for i in [ str(i['POSTCODE']) + u' ' + i['NAME'] for i in self.municipals]: self.location_city.addItem(_fromUtf8(i)) self.location_city.currentIndexChanged.connect(self.get_location_from_web) elif oeq_global.isEmpty(self.location_postal.text()) & oeq_global.isEmpty(self.location_street.text()) & (not oeq_global.isEmpty(self.location_city.text())): city = self.location_city.text() self.municipals = filter(lambda x : x['NAME'].split()[0].split(',')[0] == city.split()[0].split(',')[0] , self.municipal_information.municipal_db) if len(self.municipals) > 0: if len(self.municipals) == 1: self.lineedit_city_layout() self.location_city.setText(self.municipals[0]['NAME']) self.location_postal.setText(str(self.municipals[0]['POSTCODE'])) self.get_location_from_web(1) else: self.combobox_city_layout() self.location_city.addItem(_fromUtf8(u'< Select Location >')) for i in [ str(i['POSTCODE']) + u' ' + i['NAME'] for i in self.municipals]: self.location_city.addItem(_fromUtf8(i)) self.location_city.currentIndexChanged.connect(self.get_location_from_web) else: #self.lineedit_city_layout() #self.lineedit_postal_layout() citystring = ' '.join([self.location_postal.text(),self.location_city.text()]) address = ', '.join([config.country, citystring, self.location_street.text()]) self.found_locations = googlemaps.getCoordinatesByAddress(address, crs=4326) if len(self.found_locations) == 1: self.update_form(1) elif len(self.found_locations) > 1: self.combobox_city_layout() self.location_city.clear() self.location_city.addItem(_fromUtf8(u'< Select Location >')) for loc in self.found_locations: self.location_city.addItem(_fromUtf8(loc['formatted_location'])) self.location_city.currentIndexChanged.connect(self.update_form)
def add_color(self, color): """ Insert a new color (and the values associated to it, if any), into the color-table. :param color: The color in RGBa :type color: QColor :return: :rtype: """ from mole import extensions layer = self.layers_dropdown.currentText() self.recent_layer = layer color_map = self.color_entry_manager.layer_values_map[layer] model = QColorTableModel(color_map, self.header, self) self.color_table_view.setModel(model) color_key = 'RGBa({}, {}, {}, {})'.format(color.red(), color.green(), color.blue(), color.alpha()) if color_map.has_key(color_key): self.message_label.setStyleSheet(_fromUtf8("color: red;")) self.message_label.setText( 'Attention: Color {} is defined already.'.format(color_key)) else: self.message_label.clear() #ToDo change to use the correct para-name instead #parameter_name = str(self.layers_dropdown.currentText())[:10] parameter_name = extensions.by_layername(layer) if not parameter_name: return None parameter_name = parameter_name[0].field_id self.color_entry_manager.add_color_value_quadruple_to_layer( [color_key, parameter_name, 0, 0], layer) color_map = self.color_entry_manager.layer_values_map[layer] model = QColorTableModel(color_map, self.header, self) self.color_table_view.setModel(model) self.raise_()
def location_by_address(self): #if not issubclass(type(self.location_city), QtGui.QLineEdit): return None #if not issubclass(type(self.location_postal), QtGui.QLineEdit): return None if oeq_global.isEmpty(self.location_city.text()) & oeq_global.isEmpty( self.location_street.text()) & (not oeq_global.isEmpty( self.location_postal.text())): postal = self.location_postal.text() self.municipals = filter( lambda x: str(x['POSTCODE']).startswith(postal), self.municipal_information.municipal_db) if len(self.municipals) > 0: if len(self.municipals) == 1: self.lineedit_city_layout() self.location_city.setText(self.municipals[0]['NAME']) self.location_postal.setText( str(self.municipals[0]['POSTCODE'])) self.get_location_from_web(1) else: self.combobox_city_layout() self.location_city.addItem( _fromUtf8(u'< Select Location >')) for i in [ str(i['POSTCODE']) + u' ' + i['NAME'] for i in self.municipals ]: self.location_city.addItem(_fromUtf8(i)) self.location_city.currentIndexChanged.connect( self.get_location_from_web) elif oeq_global.isEmpty( self.location_postal.text()) & oeq_global.isEmpty( self.location_street.text()) & (not oeq_global.isEmpty( self.location_city.text())): city = self.location_city.text() self.municipals = filter( lambda x: x['NAME'].split()[0].split(',')[0] == city.split()[0] .split(',')[0], self.municipal_information.municipal_db) if len(self.municipals) > 0: if len(self.municipals) == 1: self.lineedit_city_layout() self.location_city.setText(self.municipals[0]['NAME']) self.location_postal.setText( str(self.municipals[0]['POSTCODE'])) self.get_location_from_web(1) else: self.combobox_city_layout() self.location_city.addItem( _fromUtf8(u'< Select Location >')) for i in [ str(i['POSTCODE']) + u' ' + i['NAME'] for i in self.municipals ]: self.location_city.addItem(_fromUtf8(i)) self.location_city.currentIndexChanged.connect( self.get_location_from_web) else: #self.lineedit_city_layout() #self.lineedit_postal_layout() citystring = ' '.join( [self.location_postal.text(), self.location_city.text()]) address = ', '.join( [config.country, citystring, self.location_street.text()]) self.found_locations = googlemaps.getCoordinatesByAddress(address, crs=4326) if len(self.found_locations) == 1: self.update_form(1) elif len(self.found_locations) > 1: self.combobox_city_layout() self.location_city.clear() self.location_city.addItem(_fromUtf8(u'< Select Location >')) for loc in self.found_locations: self.location_city.addItem( _fromUtf8(loc['formatted_location'])) self.location_city.currentIndexChanged.connect( self.update_form)