本文整理汇总了Python中safe_qgis.report.map.Map类的典型用法代码示例。如果您正苦于以下问题:Python Map类的具体用法?Python Map怎么用?Python Map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_defaultTemplate
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)
示例2: createPDFReport
def createPDFReport(self, theTitle, theOutputDirectory, theImpactLayer,
theCount=0, theIndex=''):
"""Create PDF report from impact layer.
Create map & table report PDF based from theImpactLayer data.
:param theTitle: the report title.
:param theOutputDirectory: output directory
:param theImpactLayer: impact layer instance.
:param theCount: the number of as scenario has been run
:param theIndex: the index for the beginning of the file name
See also:
Dock.printMap()
"""
myMap = Map(self.iface)
# FIXME: check if theImpactLayer is the real impact layer...
myMap.setImpactLayer(theImpactLayer)
LOGGER.debug('Create Report: %s' % theTitle)
myMapPath, myTablePath = self.reportPath(
theOutputDirectory, theTitle, theCount, theIndex)
# create map pdf
myMap.printToPdf(myMapPath)
# create table report pdf
myHtmlRenderer = HtmlRenderer(myMap.pageDpi)
myKeywords = myMap.keywordIO.read_keywords(theImpactLayer)
myHtmlRenderer.printImpactTable(myKeywords, myTablePath)
LOGGER.debug("Report done %s %s" % (myMapPath, myTablePath))
示例3: test_get_map_title
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
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
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
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
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: Xtest_renderTemplate
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)
示例9: create_pdf
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))
示例10: create_pdf
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))
示例11: test_renderComposition
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
示例12: test_windowsDrawingArtifacts
def test_windowsDrawingArtifacts(self):
"""Test that windows rendering does not make artifacts"""
# sometimes spurious lines are drawn on the layout
LOGGER.info('Testing windowsDrawingArtifacts')
myPath = unique_filename(
prefix='artifacts',
suffix='.pdf',
dir=temp_dir('test'))
myMap = Map(IFACE)
setup_printer(myPath)
myMap.setup_composition()
myImage = QtGui.QImage(10, 10, QtGui.QImage.Format_RGB32)
myImage.setDotsPerMeterX(dpi_to_meters(300))
myImage.setDotsPerMeterY(dpi_to_meters(300))
#myImage.fill(QtGui.QColor(250, 250, 250))
# Look at the output, you will see antialiasing issues around some
# of the boxes drawn...
# myImage.fill(QtGui.QColor(200, 200, 200))
myImage.fill(200 + 200 * 256 + 200 * 256 * 256)
myFilename = os.path.join(temp_dir(), 'greyBox')
myImage.save(myFilename, 'PNG')
for i in range(10, 190, 10):
myPicture = QgsComposerPicture(myMap.composition)
myPicture.setPictureFile(myFilename)
if qgis_version() >= 10800: # 1.8 or newer
myPicture.setFrameEnabled(False)
else:
myPicture.setFrame(False)
myPicture.setItemPosition(i, # x
i, # y
10, # width
10) # height
myMap.composition.addItem(myPicture)
# Same drawing drawn directly as a pixmap
# noinspection PyCallByClass,PyTypeChecker,PyArgumentList
myPixmapItem = myMap.composition.addPixmap(
QtGui.QPixmap.fromImage(myImage))
myPixmapItem.setOffset(i, i + 20)
# Same drawing using our drawImage Helper
myWidthMM = 1
myMap.draw_image(myImage, myWidthMM, i, i + 40)
myImagePath, _, _ = myMap.render()
# when this test no longer matches our broken render hash
# we know the issue is fixed
myTolerance = 0
myFlag, myMessage = check_images(
'windowsArtifacts',
myImagePath,
myTolerance)
myMessage += ('\nWe want these images to match, if they do not '
'there may be rendering artifacts in windows.\n')
assert myFlag, myMessage
示例13: test_custom_logo
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)
示例14: test_printToPdf
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)
示例15: test_custom_logo
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)