def exportMetaAsTextFile(self, file_abspath): # get metadata from GUI, and store them in a dictionary metaInputInDict = {} temp_filename = file_abspath.split('/')[-1] strUuid = '{0}{1}'.format(self.base_uuid_edit.text(), temp_filename) metaInputInDict['uuid'] = strUuid metaInputInDict['title'] = self.title_edit.text() metaInputInDict['platform'] = \ self.platform_combo_box.currentText() metaInputInDict['acquisition_start'] = \ self.sense_start_edit.dateTime().toString(Qt.ISODate) metaInputInDict['acquisition_end'] = \ self.sense_end_edit.dateTime().toString(Qt.ISODate) metaInputInDict['provider'] = \ self.provider_edit.text() metaInputInDict['contact'] = self.contact_edit.text() # temporarily disable two keys (website and tags) # metaInputInDict['website'] = self.website_edit.text() # metaInputInDict['tags'] = self.tags_edit.text() properties = {} properties['sensor'] = self.sensor_edit.text() properties['thumbnail'] = strUuid + ".thumb.png" metaInputInDict['properties'] = properties # extract metadata from GeoTiff, # and merge with the metadata from textbox imgMetaHdlr = ImgMetadataHandler(file_abspath) imgMetaHdlr.extractMetaInImagery() metaForUpload = dict( imgMetaHdlr.getMetaInImagery().items() + metaInputInDict.items()) strMetaForUpload = str(json.dumps(metaForUpload)) json_file_abspath = file_abspath + '_meta.json' # print json_file_abspath f = open(json_file_abspath, 'w') f.write(strMetaForUpload) f.close() return(True)
def exportMetaAsTextFile(self, file_abspath): # get metadata from GUI, and store them in a dictionary metaInputInDict = {} temp_filename = os.path.basename(file_abspath) strUuid = '{0}{1}'.format(self.base_uuid_edit.text(), temp_filename) metaInputInDict['uuid'] = strUuid metaInputInDict['title'] = self.title_edit.text() metaInputInDict['platform'] = \ self.platform_combo_box.currentText() metaInputInDict['acquisition_start'] = \ self.sense_start_edit.dateTime().toString(Qt.ISODate) metaInputInDict['acquisition_end'] = \ self.sense_end_edit.dateTime().toString(Qt.ISODate) metaInputInDict['provider'] = \ self.provider_edit.text() metaInputInDict['contact'] = self.contact_edit.text() properties = {} properties['sensor'] = self.sensor_edit.text() properties['thumbnail'] = strUuid + ".thumb.png" metaInputInDict['properties'] = properties # extract metadata from GeoTiff, # and merge with the metadata from textbox imgMetaHdlr = ImgMetadataHandler(file_abspath) imgMetaHdlr.extractMetaInImagery() metaForUpload = dict( imgMetaHdlr.getMetaInImagery().items() + metaInputInDict.items()) strMetaForUpload = str(json.dumps(metaForUpload)) json_file_abspath = file_abspath + '_meta.json' # print json_file_abspath f = open(json_file_abspath, 'w') f.write(strMetaForUpload) f.close() return(True)
def saveMetadata(self): flag = False if self.reproject_check_box.isChecked(): qMsgBox = QMessageBox() qMsgBox.setWindowTitle("Confirmation") qMsgBox.setText( "You checked the reprojection option, which can require significant \ amount of time. Are you sure to continue?") qMsgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) #qMsgBox.setDefaultButton(QMessageBox.Cancel) if qMsgBox.exec_() == QMessageBox.Ok: flag = True else: flag = True if flag: num_selected_layers = 0 count = 0 """Open python console. I haven't indentified the exact reason, but messagebar doesn't work properly without opening python console and some print statements""" pluginMenu = self.iface.pluginMenu() #print(repr(pluginMenu)) for action in pluginMenu.actions(): if 'Python Console' in action.text(): action.trigger() self.activateWindow() selected_layers = self.added_sources_list_widget.selectedItems() if selected_layers: num_selected_layers = len(selected_layers) for each_layer in selected_layers: file_abspath = each_layer.data(Qt.UserRole) if self.reproject_check_box.isChecked(): self.bar1.clearWidgets() # this message doesn't show up without opening python console # need to identify the reason self.bar1.pushMessage( 'INFO', 'Reprojecting files: %sth image out of %s is being processed...'\ % (str(count+1), str(num_selected_layers)), level=QgsMessageBar.INFO) # Isn't it better to use thread? print('Reprojecting {0}'.format( str(os.path.basename(file_abspath)))) """ probably, it is better to create a class for reprojection """ file_abspath = reproject(file_abspath) print('Add the image as a raster layer...') original_file_name = each_layer.text() reprojected_file_name = '(EPSG3857) ' + original_file_name self.iface.addRasterLayer(file_abspath, reprojected_file_name) else: self.bar1.clearWidgets() self.bar1.pushMessage( 'INFO', '%sth image out of %s is processed.'\ % (str(count+1), str(num_selected_layers)), level=QgsMessageBar.INFO) """ probably need to insert the codes to create and insert the detailed footprint layer here""" # get metadata from GUI, and store them in a dictionary metaInputInDict = {} temp_filename = file_abspath.split('/')[-1] strUuid = '{0}{1}'.format(self.base_uuid_edit.text(), temp_filename) metaInputInDict['uuid'] = strUuid metaInputInDict['title'] = self.title_edit.text() metaInputInDict[ 'platform'] = self.platform_combo_box.currentText() metaInputInDict[ 'acquisition_start'] = self.sense_start_edit.dateTime( ).toString(Qt.ISODate) metaInputInDict[ 'acquisition_end'] = self.sense_end_edit.dateTime( ).toString(Qt.ISODate) metaInputInDict['provider'] = self.provider_edit.text() metaInputInDict['contact'] = self.contact_edit.text() # temporarily disable two keys (website and tags) #metaInputInDict['website'] = self.website_edit.text() #metaInputInDict['tags'] = self.tags_edit.text() properties = {} properties['sensor'] = self.sensor_edit.text() """need to implement thumbnail creation, etc.""" properties['thumbnail'] = "currently not available" metaInputInDict['properties'] = properties # extract metadata from GeoTiff, and merge with the metadata from textbox imgMetaHdlr = ImgMetadataHandler(file_abspath) imgMetaHdlr.extractMetaInImagery() metaForUpload = dict( imgMetaHdlr.getMetaInImagery().items() + metaInputInDict.items()) strMetaForUpload = str(json.dumps(metaForUpload)) #json_file_abspath = os.path.splitext(file_abspath)[0] + '.tif_meta.json' json_file_abspath = file_abspath + '_meta.json' #print json_file_abspath f = open(json_file_abspath, 'w') f.write(strMetaForUpload) f.close() count += 1 # refresh the list widget and selected items, if reprojection is done if self.reproject_check_box.isChecked(): print('update the listWidget to reflect the change...') items_for_remove = self.added_sources_list_widget.findItems( original_file_name, Qt.MatchExactly) self.added_sources_list_widget.takeItem( self.added_sources_list_widget.row( items_for_remove[0])) items_for_remove = self.sources_list_widget.findItems( original_file_name, Qt.MatchExactly) self.sources_list_widget.takeItem( self.sources_list_widget.row(items_for_remove[0])) #self.layers_list_widget.addItem(items_for_remove[0]) self.loadLayers() items_to_add = self.layers_list_widget.findItems( reprojected_file_name, Qt.MatchExactly) items_to_add[0].setSelected(True) self.addSources() self.bar1.clearWidgets() self.bar1.pushMessage( 'INFO', 'Metadata for the selected sources were saved', level=QgsMessageBar.INFO) else: self.bar1.clearWidgets() self.bar1.pushMessage( 'WARNING', 'One or more source imagery should be selected to have the metadata saved', level=QgsMessageBar.WARNING)
def saveMetadata(self): flag = False if self.reproject_check_box.isChecked(): qMsgBox = QMessageBox() qMsgBox.setWindowTitle("Confirmation") qMsgBox.setText("You checked the reprojection option, which can require significant \ amount of time. Are you sure to continue?") qMsgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) #qMsgBox.setDefaultButton(QMessageBox.Cancel) if qMsgBox.exec_() == QMessageBox.Ok: flag = True else: flag = True if flag: num_selected_layers = 0 count = 0 """Open python console. I haven't indentified the exact reason, but messagebar doesn't work properly without opening python console and some print statements""" pluginMenu = self.iface.pluginMenu() #print(repr(pluginMenu)) for action in pluginMenu.actions(): if 'Python Console' in action.text(): action.trigger() self.activateWindow() selected_layers = self.added_sources_list_widget.selectedItems() if selected_layers: num_selected_layers = len(selected_layers) for each_layer in selected_layers: file_abspath = each_layer.data(Qt.UserRole) if self.reproject_check_box.isChecked(): self.bar1.clearWidgets() # this message doesn't show up without opening python console # need to identify the reason self.bar1.pushMessage( 'INFO', 'Reprojecting files: %sth image out of %s is being processed...'\ % (str(count+1), str(num_selected_layers)), level=QgsMessageBar.INFO) # Isn't it better to use thread? print('Reprojecting {0}'.format(str(os.path.basename(file_abspath)))) """ probably, it is better to create a class for reprojection """ file_abspath = reproject(file_abspath) print('Add the image as a raster layer...') original_file_name = each_layer.text() reprojected_file_name = '(EPSG3857) ' + original_file_name self.iface.addRasterLayer(file_abspath, reprojected_file_name) else: self.bar1.clearWidgets() self.bar1.pushMessage( 'INFO', '%sth image out of %s is processed.'\ % (str(count+1), str(num_selected_layers)), level=QgsMessageBar.INFO) """ probably need to insert the codes to create and insert the detailed footprint layer here""" # get metadata from GUI, and store them in a dictionary metaInputInDict = {} temp_filename = file_abspath.split('/')[-1] strUuid = '{0}{1}'.format(self.base_uuid_edit.text(), temp_filename) metaInputInDict['uuid'] = strUuid metaInputInDict['title'] = self.title_edit.text() metaInputInDict['platform'] = self.platform_combo_box.currentText() metaInputInDict['acquisition_start'] = self.sense_start_edit.dateTime().toString(Qt.ISODate) metaInputInDict['acquisition_end'] = self.sense_end_edit.dateTime().toString(Qt.ISODate) metaInputInDict['provider'] = self.provider_edit.text() metaInputInDict['contact'] = self.contact_edit.text() # temporarily disable two keys (website and tags) #metaInputInDict['website'] = self.website_edit.text() #metaInputInDict['tags'] = self.tags_edit.text() properties = {} properties['sensor'] = self.sensor_edit.text() """need to implement thumbnail creation, etc.""" properties['thumbnail'] = "currently not available" metaInputInDict['properties'] = properties # extract metadata from GeoTiff, and merge with the metadata from textbox imgMetaHdlr = ImgMetadataHandler(file_abspath) imgMetaHdlr.extractMetaInImagery() metaForUpload = dict(imgMetaHdlr.getMetaInImagery().items() + metaInputInDict.items()) strMetaForUpload = str(json.dumps(metaForUpload)) #json_file_abspath = os.path.splitext(file_abspath)[0] + '.tif_meta.json' json_file_abspath = file_abspath + '_meta.json' #print json_file_abspath f = open(json_file_abspath,'w') f.write(strMetaForUpload) f.close() count += 1 # refresh the list widget and selected items, if reprojection is done if self.reproject_check_box.isChecked(): print('update the listWidget to reflect the change...') items_for_remove = self.added_sources_list_widget.findItems(original_file_name, Qt.MatchExactly) self.added_sources_list_widget.takeItem(self.added_sources_list_widget.row(items_for_remove[0])) items_for_remove = self.sources_list_widget.findItems(original_file_name, Qt.MatchExactly) self.sources_list_widget.takeItem(self.sources_list_widget.row(items_for_remove[0])) #self.layers_list_widget.addItem(items_for_remove[0]) self.loadLayers() items_to_add = self.layers_list_widget.findItems(reprojected_file_name, Qt.MatchExactly) items_to_add[0].setSelected(True) self.addSources() self.bar1.clearWidgets() self.bar1.pushMessage( 'INFO', 'Metadata for the selected sources were saved', level=QgsMessageBar.INFO) else: self.bar1.clearWidgets() self.bar1.pushMessage( 'WARNING', 'One or more source imagery should be selected to have the metadata saved', level=QgsMessageBar.WARNING)