本文整理汇总了Python中safe.test.utilities.get_qgis_app函数的典型用法代码示例。如果您正苦于以下问题:Python get_qgis_app函数的具体用法?Python get_qgis_app怎么用?Python get_qgis_app使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_qgis_app函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_translation
def test_translation(self):
"""Test for metadata translation."""
from safe.gui.tools.wizard_dialog import WizardDialog
from safe.test.utilities import (
clone_shp_layer, remove_vector_temp_file)
from safe.test.utilities import BOUNDDATA
from safe.test.utilities import get_qgis_app
# Get QGis app handle
# noinspection PyPep8Naming
_, _, IFACE, PARENT = get_qgis_app()
layer = clone_shp_layer(
name='kabupaten_jakarta',
include_keywords=True,
source_directory=BOUNDDATA)
# noinspection PyTypeChecker
dialog = WizardDialog(PARENT, IFACE)
dialog.set_keywords_creation_mode(layer)
expected_categories = ['keterpaparan', 'ancaman', 'agregasi']
# noinspection PyTypeChecker
self.check_list(expected_categories, dialog.lstCategories)
self.check_current_text('agregasi', dialog.lstCategories)
dialog.pbnNext.click()
remove_vector_temp_file(layer.source())
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:28,代码来源:test_wizard_dialog_locale.py
示例2: analysis_execution
def analysis_execution():
from safe.test.utilities import get_qgis_app
# get_qgis_app must be called before importing Analysis
QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app()
from safe.utilities.analysis import Analysis
from safe.utilities.keyword_io import KeywordIO
analysis = Analysis()
arg = AnalysisArguments.read_arguments()
register_impact_functions()
registry = ImpactFunctionManager().registry
function = registry.get_instance(arg.impact_function_name)
hazard_layer = safe_to_qgis_layer(read_layer(arg.hazard_filename))
exposure_layer = safe_to_qgis_layer(read_layer(arg.exposure_filename))
if arg.aggregation_filename:
aggregation_layer = safe_to_qgis_layer(read_layer(
arg.aggregation_filename))
keywords_io = KeywordIO()
try:
analysis.map_canvas = IFACE.mapCanvas()
analysis.hazard_layer = hazard_layer
analysis.hazard_keyword = keywords_io.read_keywords(hazard_layer)
analysis.exposure_layer = exposure_layer
analysis.exposure_keyword = keywords_io.read_keywords(exposure_layer)
if aggregation_layer:
analysis.aggregation_layer = aggregation_layer
analysis.aggregation_keyword = keywords_io.read_keywords(
aggregation_layer)
analysis.impact_function = function
analysis.setup_analysis()
print 'Setup analysis done'
analysis.run_analysis()
print 'Analysis done'
except Exception as e:
print e.message
impact = analysis.impact_layer
qgis_impact = safe_to_qgis_layer(impact)
generate_styles(impact, qgis_impact)
copy_impact_layer(impact, arg.impact_filename)
开发者ID:inasafe,项目名称:inasafe-headless,代码行数:53,代码来源:run_analysis.py
示例3: test_qgis_app_locale
def test_qgis_app_locale(self):
"""Test for qgis app locale."""
from safe.definitions.constants import no_field
self.assertEqual(no_field, u'No Field')
# run qgis on bahasa
_ = get_qgis_app('id', INASAFE_TEST)
# test if string from inasafe module are translated
from safe.definitions.constants import no_field
self.assertNotEqual(no_field, u'No Field')
expected_locale = 'id'
self.assertEqual(locale(INASAFE_TEST), expected_locale)
# check for bahasa translation
expected_message = (
'Tidak ada informasi gaya yang ditemukan pada lapisan %s')
real_message = tr(
'No styleInfo was found for layer %s')
message = 'expected %s but got %s' % (expected_message, real_message)
self.assertEqual(expected_message, real_message, message)
# run qgis on english
_ = get_qgis_app(qsetting=INASAFE_TEST)
expected_locale = 'en'
self.assertEqual(locale(INASAFE_TEST), expected_locale)
# check for english translation
expected_message = (
'No styleInfo was found for layer %s')
real_message = tr(
'No styleInfo was found for layer %s')
message = 'expected %s but got %s' % (expected_message, real_message)
self.assertEqual(expected_message, real_message, message)
# Set back to en
os.environ['LANG'] = 'en'
开发者ID:inasafe,项目名称:inasafe,代码行数:40,代码来源:test_translations.py
示例4: main
def main():
"""Main function to run the example."""
def print_values(the_profile_widget):
data = the_profile_widget.data
from pprint import pprint
pprint(data)
def clear_widget(the_profile_widget):
the_profile_widget.clear()
def restore_data(the_profile_widget):
the_profile_widget.clear()
the_profile_widget.data = generate_default_profile()
from safe.test.utilities import get_qgis_app
QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app(qsetting=INASAFE_TEST)
default_profile = generate_default_profile()
profile_widget = ProfileWidget(data=default_profile)
get_result_button = QPushButton('Get result...')
get_result_button.clicked.connect(
partial(print_values, profile_widget))
clear_button = QPushButton('Clear widget...')
clear_button.clicked.connect(
partial(clear_widget, profile_widget))
restore_button = QPushButton('Restore data...')
restore_button.clicked.connect(
partial(restore_data, profile_widget))
widget = QWidget()
layout = QGridLayout()
layout.addWidget(profile_widget)
layout.addWidget(restore_button)
layout.addWidget(get_result_button)
layout.addWidget(clear_button)
widget.setLayout(layout)
widget.setFixedHeight(600)
widget.setFixedWidth(800)
widget.show()
sys.exit(QGIS_APP.exec_())
开发者ID:inasafe,项目名称:inasafe,代码行数:46,代码来源:profile_widget_example.py
示例5: test_hello_world_report
def test_hello_world_report(self):
"""Test for creating hello world report.
.. versionadded:: 4.1
"""
QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app(qsetting=INASAFE_TEST)
output_folder = self.fixtures_dir('../output/hello_world_report')
# sneaky monkey patch
ImpactFunction.outputs = ['Not implemented']
impact_function = ImpactFunction()
template_metadata = ReportMetadata(
metadata_dict=hello_world_metadata_html)
impact_report = ImpactReport(
iface=IFACE,
template_metadata=template_metadata,
impact_function=impact_function)
impact_report.output_folder = output_folder
impact_report.process_components()
开发者ID:inasafe,项目名称:inasafe,代码行数:23,代码来源:hello_world_report.py
示例6: import
from safe.definitions.hazard_classifications import (
generic_hazard_classes,
earthquake_mmi_scale,
tsunami_hazard_classes,
cyclone_au_bom_hazard_classes)
from safe.report.extractors.util import (
layer_definition_type,
layer_hazard_classification,
resolve_from_dictionary,
retrieve_exposure_classes_lists)
from safe.test.utilities import (
load_layer,
standard_data_path,
get_qgis_app)
QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app()
__copyright__ = "Copyright 2016, The InaSAFE Project"
__license__ = "GPL version 3"
__email__ = "[email protected]"
__revision__ = 'e54efb23cb33ed813dec3545321e0284b904e7a6'
LOGGER = logging.getLogger('InaSAFE')
class TestReportUtil(unittest.TestCase):
def setUp(self):
self.maxDiff = None
self.layer_paths_list = [
开发者ID:timlinux,项目名称:inasafe,代码行数:31,代码来源:test_util.py
示例7: setUp
def setUp(self):
from safe.test.utilities import get_qgis_app
QGIS_APP, CANVAS, self.iface, PARENT = get_qgis_app(
qsetting=INASAFE_TEST)
开发者ID:inasafe,项目名称:inasafe,代码行数:4,代码来源:test_multi_exposure.py
示例8: main
def main():
"""Main function to run the example."""
from safe.test.utilities import get_qgis_app
QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app(qsetting=INASAFE_TEST)
options = OrderedDict([
(DO_NOT_REPORT,
{
'label': 'Do not report',
'value': None,
'type': STATIC,
'constraint': {}
}),
(GLOBAL_DEFAULT,
{
'label': 'Global default',
'value': 0.5,
'type': STATIC,
'constraint': {}
}),
(CUSTOM_VALUE,
{
'label': 'Custom',
'value': 0.7, # Taken from keywords / recent value
'type': SINGLE_DYNAMIC,
'constraint':
{
'min': 0,
'max': 1
}
}),
(FIELDS,
{
'label': 'Ratio fields',
'value': ['field A', 'field B', 'field C'], # Taken from keywords
'type': MULTIPLE_DYNAMIC,
'constraint': {}
})
])
default_value_parameter = GroupSelectParameter()
default_value_parameter.name = 'Group Select parameter'
default_value_parameter.help_text = 'Help text'
default_value_parameter.description = 'Description'
default_value_parameter.options = options
default_value_parameter.selected = 'ratio fields'
parameters = [
default_value_parameter
]
extra_parameters = [
(GroupSelectParameter, GroupSelectParameterWidget)
]
parameter_container = ParameterContainer(
parameters, extra_parameters=extra_parameters)
parameter_container.setup_ui()
widget = QWidget()
layout = QGridLayout()
layout.addWidget(parameter_container)
def show_error_message(parent, exception):
"""Generate error message to handle parameter errors
:param parent: The widget as a parent of message box
:type parent: QWidget
:param exception: python Exception or Error
:type exception: Exception
"""
box = QMessageBox()
box.critical(parent, 'Error occured', str(exception))
def show_parameter(the_parameter_container):
"""Print the value of parameter.
:param the_parameter_container: A parameter container
:type the_parameter_container: ParameterContainer
"""
def show_parameter_value(a_parameter):
if isinstance(a_parameter, GroupParameter):
for param in a_parameter.value:
show_parameter_value(param)
else:
print((a_parameter.guid, a_parameter.name, a_parameter.value))
try:
the_parameters = the_parameter_container.get_parameters()
if the_parameters:
for parameter in the_parameters:
show_parameter_value(parameter)
except Exception as inst:
show_error_message(parameter_container, inst)
print_button = QPushButton('Print Result')
# noinspection PyUnresolvedReferences
print_button.clicked.connect(
partial(show_parameter, the_parameter_container=parameter_container))
#.........这里部分代码省略.........
开发者ID:inasafe,项目名称:inasafe,代码行数:101,代码来源:example_group_select.py
示例9: import
import unittest
import os
# This is to enable API V2
# noinspection PyUnresolvedReferences
import qgis # pylint: disable=unused-import
# noinspection PyPackageRequirements
from qgis.PyQt.QtWidgets import QDialogButtonBox
from safe.definitions.constants import INASAFE_TEST
from safe.gui.tools.shake_grid.shakemap_converter_dialog import (
ShakemapConverterDialog)
from safe.common.utilities import unique_filename, temp_dir
from safe.test.utilities import standard_data_path, get_qgis_app
QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app(qsetting=INASAFE_TEST)
__copyright__ = "Copyright 2016, The InaSAFE Project"
__license__ = "GPL version 3"
__email__ = "[email protected]"
__revision__ = 'bd00bfeac510722b427544b186bfa10861749e51'
class TestShakemapImporter(unittest.TestCase):
"""Test class to facilitate importing shakemaps."""
def test_init_dialog(self):
"""Test for showing table in the first."""
shakemap_converter_dialog = ShakemapConverterDialog(PARENT, IFACE)
msg = 'Dialog is failed to create'
self.assertIsNotNone(shakemap_converter_dialog, msg)
开发者ID:inasafe,项目名称:inasafe,代码行数:31,代码来源:test_shakemap_converter_dialog.py
示例10: test_existing_complex_keywords
def test_existing_complex_keywords(self):
"""Test for existing complex keywords in wizard in locale mode."""
from safe.gui.tools.wizard_dialog import WizardDialog
from safe.test.utilities import (
clone_shp_layer, remove_vector_temp_file)
layer = clone_shp_layer(
name='tsunami_polygon', include_keywords=True, source_directory='')
from safe.test.utilities import get_qgis_app
# Get QGis app handle
# noinspection PyPep8Naming
_, _, IFACE, PARENT = get_qgis_app()
# noinspection PyTypeChecker
dialog = WizardDialog(PARENT, IFACE)
dialog.set_keywords_creation_mode(layer)
# select hazard
self.select_from_list_widget('ancaman', dialog.lstCategories)
dialog.pbnNext.click()
# select volcano
self.select_from_list_widget('gunung berapi', dialog.lstSubcategories)
dialog.pbnNext.click()
# select volcano categorical unit
self.select_from_list_widget('Kategori gunung berapi', dialog.lstUnits)
dialog.pbnNext.click()
# select GRIDCODE
self.select_from_list_widget('GRIDCODE', dialog.lstFields)
dialog.pbnNext.click()
unit = dialog.selected_unit()
default_classes = unit['classes']
unassigned_values = [] # no need to check actually, not save in file
assigned_values = {
'low': ['5.0'],
'medium': ['3.0', '4.0'],
'high': ['2.0']
}
dialog.populate_classified_values(
unassigned_values, assigned_values, default_classes)
dialog.pbnNext.click()
source = 'Source'
source_scale = 'Source Scale'
source_url = 'Source Url'
source_date = 'Source Date'
dialog.leSource.setText(source)
dialog.leSource_scale.setText(source_scale)
dialog.leSource_url.setText(source_url)
dialog.leSource_date.setText(source_date)
dialog.pbnNext.click() # next
dialog.pbnNext.click() # finish
# noinspection PyTypeChecker
dialog = WizardDialog(PARENT, IFACE)
dialog.set_keywords_creation_mode(layer)
# step 1 of 7 - select category
self.check_current_text('ancaman', dialog.lstCategories)
# Click Next
dialog.pbnNext.click()
# step 2 of 7 - select subcategory
# noinspection PyTypeChecker
self.check_current_text('gunung berapi', dialog.lstSubcategories)
# Click Next
dialog.pbnNext.click()
# step 3 of 7 - select volcano units
self.check_current_text('Kategori gunung berapi', dialog.lstUnits)
# Click Next
dialog.pbnNext.click()
# step 4 of 7 - select field
self.check_current_text('GRIDCODE', dialog.lstFields)
# Click Next
dialog.pbnNext.click()
for index in range(dialog.lstUniqueValues.count()):
message = ('%s Should be in unassigned values' %
dialog.lstUniqueValues.item(index).text())
self.assertIn(
dialog.lstUniqueValues.item(index).text(),
unassigned_values,
message)
real_assigned_values = dialog.selected_mapping()
self.assertDictEqual(real_assigned_values, assigned_values)
# Click Next
dialog.pbnNext.click()
# step 6 of 7 - enter source
message = ('Invalid Next button state in step 6! Disabled while '
#.........这里部分代码省略.........
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:101,代码来源:test_wizard_dialog_locale.py
示例11: test_existing_complex_keywords
def test_existing_complex_keywords(self):
"""Test for existing complex keywords in wizard in locale mode."""
from safe.gui.tools.wizard_dialog import WizardDialog
from safe.test.utilities import clone_shp_layer, remove_vector_temp_file
layer = clone_shp_layer(name="tsunami_polygon", include_keywords=True, source_directory="")
from safe.test.utilities import get_qgis_app
# Get QGis app handle
# noinspection PyPep8Naming
_, _, IFACE, PARENT = get_qgis_app()
# noinspection PyTypeChecker
dialog = WizardDialog(PARENT, IFACE)
dialog.set_keywords_creation_mode(layer)
# select hazard
self.select_from_list_widget("ancaman", dialog.lstCategories)
dialog.pbnNext.click()
# select volcano
self.select_from_list_widget("gunung berapi", dialog.lstSubcategories)
dialog.pbnNext.click()
# select volcano categorical unit
self.select_from_list_widget("Kategori gunung berapi", dialog.lstUnits)
dialog.pbnNext.click()
# select GRIDCODE
self.select_from_list_widget("GRIDCODE", dialog.lstFields)
dialog.pbnNext.click()
unit = dialog.selected_unit()
default_classes = unit["classes"]
unassigned_values = [] # no need to check actually, not save in file
assigned_values = {"low": ["5.0"], "medium": ["3.0", "4.0"], "high": ["2.0"]}
dialog.populate_classified_values(unassigned_values, assigned_values, default_classes)
dialog.pbnNext.click()
source = "Source"
source_scale = "Source Scale"
source_url = "Source Url"
source_date = QDateTime.fromString("06-12-2015 12:30", "dd-MM-yyyy HH:mm")
dialog.leSource.setText(source)
dialog.leSource_scale.setText(source_scale)
dialog.leSource_url.setText(source_url)
dialog.leSource_date.seDateTime(source_date)
dialog.pbnNext.click() # next
dialog.pbnNext.click() # finish
# noinspection PyTypeChecker
dialog = WizardDialog(PARENT, IFACE)
dialog.set_keywords_creation_mode(layer)
# step 1 of 7 - select category
self.check_current_text("ancaman", dialog.lstCategories)
# Click Next
dialog.pbnNext.click()
# step 2 of 7 - select subcategory
# noinspection PyTypeChecker
self.check_current_text("gunung berapi", dialog.lstSubcategories)
# Click Next
dialog.pbnNext.click()
# step 3 of 7 - select volcano units
self.check_current_text("Kategori gunung berapi", dialog.lstUnits)
# Click Next
dialog.pbnNext.click()
# step 4 of 7 - select field
self.check_current_text("GRIDCODE", dialog.lstFields)
# Click Next
dialog.pbnNext.click()
for index in range(dialog.lstUniqueValues.count()):
message = "%s Should be in unassigned values" % dialog.lstUniqueValues.item(index).text()
self.assertIn(dialog.lstUniqueValues.item(index).text(), unassigned_values, message)
real_assigned_values = dialog.selected_mapping()
self.assertDictEqual(real_assigned_values, assigned_values)
# Click Next
dialog.pbnNext.click()
# step 6 of 7 - enter source
message = "Invalid Next button state in step 6! Disabled while " "source is optional"
self.assertTrue(dialog.pbnNext.isEnabled(), message)
message = "Source should be %s" % source
self.assertEqual(dialog.leSource.text(), source, message)
message = "Source Url should be %s" % source_url
self.assertEqual(dialog.leSource_url.text(), source_url, message)
message = "Source Date should be %s" % source_date.toString("dd-MM-yyyy HH:mm")
self.assertEqual(dialog.leSource_date.dateTime(), source_date, message)
message = "Source Scale should be %s" % source_scale
#.........这里部分代码省略.........
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:101,代码来源:test_wizard_dialog_locale.py
注:本文中的safe.test.utilities.get_qgis_app函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论