本文整理汇总了Python中safe_qgis.report.map.Map.set_impact_layer方法的典型用法代码示例。如果您正苦于以下问题:Python Map.set_impact_layer方法的具体用法?Python Map.set_impact_layer怎么用?Python Map.set_impact_layer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe_qgis.report.map.Map
的用法示例。
在下文中一共展示了Map.set_impact_layer方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_renderComposition
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_renderComposition(self):
"""Test making an image of the map only."""
LOGGER.info("Testing renderComposition")
myLayer, _ = load_layer("test_shakeimpact.shp")
myCanvasLayer = QgsMapCanvasLayer(myLayer)
CANVAS.setLayerSet([myCanvasLayer])
myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
CANVAS.setExtent(myRect)
CANVAS.refresh()
myMap = Map(IFACE)
myMap.set_impact_layer(myLayer)
myMap.compose_map()
myImagePath, myControlImage, myTargetArea = myMap.render()
LOGGER.debug(myImagePath)
assert myControlImage is not None
myDimensions = [myTargetArea.left(), myTargetArea.top(), myTargetArea.bottom(), myTargetArea.right()]
myExpectedDimensions = [0.0, 0.0, 3507.0, 2480.0]
myMessage = "Expected target area to be %s, got %s" % (str(myExpectedDimensions), str(myDimensions))
assert myExpectedDimensions == myDimensions, myMessage
myMessage = "Rendered output does not exist"
assert os.path.exists(myImagePath), myMessage
# Beta version and version changes can introduce a few extra chars
# into the metadata section so we set a reasonable tolerance to cope
# with this.
myTolerance = 8000
myFlag, myMessage = check_images("renderComposition", myImagePath, myTolerance)
assert myFlag, myMessage
示例2: test_defaultTemplate
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_defaultTemplate(self):
"""Test that loading default template works"""
LOGGER.info('Testing defaultTemplate')
myLayer, _ = load_layer('test_shakeimpact.shp')
myCanvasLayer = QgsMapCanvasLayer(myLayer)
CANVAS.setLayerSet([myCanvasLayer])
myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
CANVAS.setExtent(myRect)
CANVAS.refresh()
myMap = Map(IFACE)
myMap.set_impact_layer(myLayer)
myPath = unique_filename(prefix='mapDefaultTemplateTest',
suffix='.pdf',
dir=temp_dir('test'))
myMap.make_pdf(myPath)
LOGGER.debug(myPath)
myMessage = 'Rendered output does not exist: %s' % myPath
assert os.path.exists(myPath), myMessage
# pdf rendering is non deterministic so we can't do a hash check
# test_renderComposition renders just the image instead of pdf
# so we hash check there and here we just do a basic minimum file
# size check.
mySize = os.stat(myPath).st_size
# Note: You should replace, not append the numbers for a given
# platform. Also note that this test will break every time the
# version number of InaSAFE changes so we should ultimately come up
# with a lower maintenance test strategy.
myExpectedSizes = [
400350, # Slackware64 14.0
]
myMessage = '%s\nExpected rendered map pdf to be in %s, got %s' % (
myPath, myExpectedSizes, mySize)
self.assertIn(mySize, myExpectedSizes, myMessage)
示例3: test_get_map_title
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_get_map_title(self):
"""Getting the map title from the keywords"""
layer, _ = load_layer('test_floodimpact.tif')
report = Map(IFACE)
report.set_impact_layer(layer)
title = report.map_title()
expected_title = 'Penduduk yang Mungkin dievakuasi'
message = 'Expected: %s\nGot:\n %s' % (expected_title, title)
assert title == expected_title, message
示例4: test_getMapTitle
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_getMapTitle(self):
"""Getting the map title from the keywords"""
myLayer, _ = load_layer('test_floodimpact.tif')
myMap = Map(IFACE)
myMap.set_impact_layer(myLayer)
myTitle = myMap.map_title()
myExpectedTitle = 'Penduduk yang Mungkin dievakuasi'
myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
assert myTitle == myExpectedTitle, myMessage
示例5: test_handle_missing_map_title
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_handle_missing_map_title(self):
"""Missing map title from the keywords fails gracefully"""
# TODO running OSM Buildngs with Pendudk Jakarta
# wasthrowing an error when requesting map title
# that this test wasnt replicating well
layer, _ = load_layer('population_padang_1.asc')
report = Map(IFACE)
report.set_impact_layer(layer)
title = report.map_title()
expected_title = None
message = 'Expected: %s\nGot:\n %s' % (expected_title, title)
assert title == expected_title, message
示例6: test_handleMissingMapTitle
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_handleMissingMapTitle(self):
"""Missing map title from the keywords fails gracefully"""
# TODO running OSM Buildngs with Pendudk Jakarta
# wasthrowing an error when requesting map title
# that this test wasnt replicating well
myLayer, _ = load_layer('population_padang_1.asc')
myMap = Map(IFACE)
myMap.set_impact_layer(myLayer)
myTitle = myMap.map_title()
myExpectedTitle = None
myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
assert myTitle == myExpectedTitle, myMessage
示例7: test_default_template
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_default_template(self):
"""Test that loading default template works"""
LOGGER.info('Testing default_template')
layer, _ = load_layer('test_shakeimpact.shp')
canvas_layer = QgsMapCanvasLayer(layer)
CANVAS.setLayerSet([canvas_layer])
rect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
CANVAS.setExtent(rect)
CANVAS.refresh()
report = Map(IFACE)
report.set_impact_layer(layer)
out_path = unique_filename(
prefix='mapDefaultTemplateTest',
suffix='.pdf',
dir=temp_dir('test'))
report.make_pdf(out_path)
LOGGER.debug(out_path)
message = 'Rendered output does not exist: %s' % out_path
self.assertTrue(os.path.exists(out_path), message)
# pdf rendering is non deterministic so we can't do a hash check
# test_renderComposition renders just the image instead of pdf
# so we hash check there and here we just do a basic minimum file
# size check.
out_size = os.stat(out_path).st_size
# Note: You should replace, not append the numbers for a given
# platform. Also note that this test will break every time the
# version number of InaSAFE changes so we should ultimately come up
# with a lower maintenance test strategy.
expected_sizes = [
405359, # Ubuntu 13.04_64
427172, # Ubuntu 13.10_64
468836, # Ubuntu 14.04_64 AG
431844, # Ubuntu 14.04_64 TS - pycharm
431873, # Ubuntu 14.04_64 TS - make - TODO why is this?
437994, # Ubuntu 14.04_64 MB - pycharm
431844, # Ubuntu 14.04_64 MB - make - TODO why is this?
434596, # Ubuntu 14.04_64 MB - pycharm
428339, # Ubuntu 14.04_64 MB - make - TODO why is this?
414589, # Slackware64 14.0
144542, # Linux Mint 14_64
148267, # Windows 7 32
150412, # Windows 7 64
448270, # UB 12.04 Jenkins
448241, # Travis
]
message = '%s\nExpected rendered map pdf to be in %s, got %s' % (
out_path, expected_sizes, out_size)
self.assertIn(out_size, expected_sizes, message)
示例8: test_custom_logo
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_custom_logo(self):
"""Test that setting user-defined logo works."""
LOGGER.info('Testing custom_logo')
layer, _ = load_layer('test_shakeimpact.shp')
canvas_layer = QgsMapCanvasLayer(layer)
CANVAS.setLayerSet([canvas_layer])
rect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
CANVAS.setExtent(rect)
CANVAS.refresh()
report = Map(IFACE)
report.set_impact_layer(layer)
report.set_organisation_logo(":/plugins/inasafe/logo-flower.png")
out_path = unique_filename(
prefix='mapCustomLogoTest', suffix='.pdf', dir=temp_dir('test'))
report.make_pdf(out_path)
LOGGER.debug(out_path)
message = 'Rendered output does not exist: %s' % out_path
self.assertTrue(os.path.exists(out_path), message)
# pdf rendering is non deterministic so we can't do a hash check
# test_renderComposition renders just the image instead of pdf
# so we hash check there and here we just do a basic minimum file
# size check.
out_size = os.stat(out_path).st_size
# Note: You should replace, not append the numbers for a given
# platform. Also note that this test will break every time the
# version number of InaSAFE changes so we should ultimately come up
# with a lower maintenance test strategy.
expected_sizes = [
402083, # Ubuntu 13.04_64
400563, # Ubuntu 13.10_64
450385, # Ubuntu 14.04_64 AG
413193, # Ubuntu 14.04_64 TS pycharm
416313, # Ubuntu 14.04_64 TS make - TODO why is this?
419483, # Ubuntu 14.04_64 MB pycharm
413193, # Ubuntu 14.04_64 MB make - TODO why is this?
419036, # Ubuntu 14.04_64 IS pycharm
412764, # Ubuntu 14.04_64 IS make - TODO why is this?
367934, # Slackware64 14.0
82263, # Linux Mint 14_64
85418, # Windows 7 32bit
88779, # Windows 7 64bit
436118, # Jenkins ub 12.04
432703, # Travis
]
message = '%s\nExpected rendered map pdf to be in %s, got %s' % (
out_path, expected_sizes, out_size)
self.assertIn(out_size, expected_sizes, message)
示例9: Xtest_renderTemplate
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def Xtest_renderTemplate(self):
"""Test that load template works"""
# Use the template from our resources bundle
myInPath = ":/plugins/inasafe/basic.qpt"
myLayer, _ = load_layer("test_shakeimpact.shp")
myCanvasLayer = QgsMapCanvasLayer(myLayer)
CANVAS.setLayerSet([myCanvasLayer])
myMap = Map(IFACE)
set_jakarta_extent()
myMap.set_impact_layer(myLayer)
myPath = unique_filename(prefix="outTemplate", suffix=".pdf", dir=temp_dir("test"))
LOGGER.debug(myPath)
myMap.render_template(myInPath, myPath)
assert os.path.exists(myPath)
示例10: create_pdf
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def create_pdf(
self,
title,
output_directory,
impact_layer,
count=0,
index=None):
"""Create PDF report from impact layer.
Create map & table report PDF based from impact_layer data.
:param title: Report title.
:type title: str
:param output_directory: Output directory.
:type output_directory: str
:param impact_layer: Impact layer instance.
:type impact_layer: QgsMapLayer
:param count: The number of scenarios that were run.
:type count: int
:param index: A sequential number to place at the beginning of the
file name.
:type index: int, None
See also:
Dock.printMap()
"""
inasafe_map = Map(self.iface)
# FIXME: check if impact_layer is the real impact layer...
inasafe_map.set_impact_layer(impact_layer)
LOGGER.debug('Create Report: %s' % title)
map_path, table_path = self.report_path(
output_directory, title, count, index)
# create map pdf
inasafe_map.make_pdf(map_path)
# create table report pdf
html_renderer = HtmlRenderer(inasafe_map.page_dpi)
keywords = inasafe_map.keyword_io.read_keywords(impact_layer)
html_renderer.print_impact_table(keywords, table_path)
LOGGER.debug("Report done %s %s" % (map_path, table_path))
示例11: create_pdf
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def create_pdf(self,
title,
output_directory,
impact_layer,
count=0,
index=''):
"""Create PDF report from impact layer.
Create map & table report PDF based from impact_layer data.
:param title: Report title.
:type title: str
:param output_directory: Output directory.
:type output_directory: str
:param impact_layer: Impact layer instance.
:type impact_layer: QgsMapLayer
:param count: The number of scenarios that were run.
:type count: int
:param index: The prefix for the beginning of the file name. Note we
need a better explanation of this param.
:type index: str
See also:
Dock.printMap()
"""
myMap = Map(self.iface)
# FIXME: check if impact_layer is the real impact layer...
myMap.set_impact_layer(impact_layer)
LOGGER.debug('Create Report: %s' % title)
myMapPath, myTablePath = self.report_path(
output_directory, title, count, index)
# create map pdf
myMap.make_pdf(myMapPath)
# create table report pdf
myHtmlRenderer = HtmlRenderer(myMap.pageDpi)
myKeywords = myMap.keywordIO.read_keywords(impact_layer)
myHtmlRenderer.printImpactTable(myKeywords, myTablePath)
LOGGER.debug("Report done %s %s" % (myMapPath, myTablePath))
示例12: test_printToPdf
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_printToPdf(self):
"""Test making a pdf of the map - this is the most typical use of map.
"""
LOGGER.info('Testing printToPdf')
myLayer, _ = load_layer('test_shakeimpact.shp')
myCanvasLayer = QgsMapCanvasLayer(myLayer)
CANVAS.setLayerSet([myCanvasLayer])
myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
CANVAS.setExtent(myRect)
CANVAS.refresh()
myMap = Map(IFACE)
myMap.set_impact_layer(myLayer)
myMap.compose_map()
myPath = unique_filename(prefix='mapPdfTest',
suffix='.pdf',
dir=temp_dir('test'))
myMap.make_pdf(myPath)
LOGGER.debug(myPath)
myMessage = 'Rendered output does not exist: %s' % myPath
assert os.path.exists(myPath), myMessage
# pdf rendering is non deterministic so we can't do a hash check
# test_renderComposition renders just the image instead of pdf
# so we hash check there and here we just do a basic minimum file
# size check.
mySize = os.stat(myPath).st_size
# Note: You should replace, not append the numbers for a given
# platform. Also note that this test will break every time the
# version number of InaSAFE changes so we should ultimately come up
# with a lower maintenance test strategy.
myExpectedSizes = [
441541, # as rendered on ub 13.04 post 17 May 2013
441563, # as rendered on ub 13.04 18 Jul 2013
447217, # Nadia Linux Mint 14
447144, # as rendered on Jenkins post 29 July 2013
447172, # Windows 7 SP1 AMD64
446839, # Windows 8 AMD64 post 27 Aug 2013
234138, # OSX 10.8
444421, # Slackware64 14.0
]
myMessage = '%s\nExpected rendered map pdf to be in %s, got %s' % (
myPath, myExpectedSizes, mySize)
self.assertIn(mySize, myExpectedSizes, myMessage)
示例13: test_custom_logo
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_custom_logo(self):
"""Test that setting user-defined logo works"""
LOGGER.info('Testing custom_logo')
layer, _ = load_layer('test_shakeimpact.shp')
canvas_layer = QgsMapCanvasLayer(layer)
CANVAS.setLayerSet([canvas_layer])
rect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
CANVAS.setExtent(rect)
CANVAS.refresh()
report = Map(IFACE)
report.set_impact_layer(layer)
report.set_logo(":/plugins/inasafe/logo-flower.png")
out_path = unique_filename(prefix='mapCustomLogoTest',
suffix='.pdf',
dir=temp_dir('test'))
report.make_pdf(out_path)
LOGGER.debug(out_path)
message = 'Rendered output does not exist: %s' % out_path
assert os.path.exists(out_path), message
# pdf rendering is non deterministic so we can't do a hash check
# test_renderComposition renders just the image instead of pdf
# so we hash check there and here we just do a basic minimum file
# size check.
out_size = os.stat(out_path).st_size
# Note: You should replace, not append the numbers for a given
# platform. Also note that this test will break every time the
# version number of InaSAFE changes so we should ultimately come up
# with a lower maintenance test strategy.
expected_sizes = [
402083, # Ubuntu 13.04_64
388095, # Slackware64 14.0
]
message = '%s\nExpected rendered map pdf to be in %s, got %s' % (
out_path, expected_sizes, out_size)
self.assertIn(out_size, expected_sizes, message)
示例14: test_printToPdf
# 需要导入模块: from safe_qgis.report.map import Map [as 别名]
# 或者: from safe_qgis.report.map.Map import set_impact_layer [as 别名]
def test_printToPdf(self):
"""Test making a pdf of the map - this is the most typical use of map.
"""
LOGGER.info('Testing printToPdf')
myLayer, _ = load_layer('test_shakeimpact.shp')
myCanvasLayer = QgsMapCanvasLayer(myLayer)
CANVAS.setLayerSet([myCanvasLayer])
myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
CANVAS.setExtent(myRect)
CANVAS.refresh()
myMap = Map(IFACE)
myMap.set_impact_layer(myLayer)
myMap.compose_map()
myPath = unique_filename(prefix='mapPdfTest',
suffix='.pdf',
dir=temp_dir('test'))
myMap.make_pdf(myPath)
LOGGER.debug(myPath)
myMessage = 'Rendered output does not exist: %s' % myPath
assert os.path.exists(myPath), myMessage
# pdf rendering is non deterministic so we can't do a hash check
# test_renderComposition renders just the image instead of pdf
# so we hash check there and here we just do a basic minimum file
# size check.
mySize = os.stat(myPath).st_size
myExpectedSizes = [
441541, # as rendered on ub 13.04 post 17 May 2013
441428, # as rendered on ub 13.04 5 Jul 2013
447217, # Nadia Linux Mint 14
447051, # as rendered on Jenkins post 24 April 2013
447138, # Windows 7 SP1 AMD64
233989, # OSX 10.8
]
myMessage = '%s\nExpected rendered map pdf to be in %s, got %s' % (
myPath, myExpectedSizes, mySize)
self.assertIn(mySize, myExpectedSizes, myMessage)