本文整理汇总了Python中safe_qgis.utilities_test.loadLayer函数的典型用法代码示例。如果您正苦于以下问题:Python loadLayer函数的具体用法?Python loadLayer怎么用?Python loadLayer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loadLayer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.keywordIO = KeywordIO()
myUri = QgsDataSourceURI()
myUri.setDatabase(os.path.join(TESTDATA, 'jk.sqlite'))
myUri.setDataSource('', 'osm_buildings', 'Geometry')
self.sqliteLayer = QgsVectorLayer(myUri.uri(), 'OSM Buildings',
'spatialite')
myHazardPath = os.path.join(HAZDATA, 'Shakemap_Padang_2009.asc')
self.fileRasterLayer, myType = loadLayer(myHazardPath,
theDirectory=None)
del myType
self.fileVectorLayer, myType = loadLayer('Padang_WGS84.shp')
del myType
self.expectedSqliteKeywords = {'category': 'exposure',
'datatype': 'OSM',
'subcategory': 'building'}
self.expectedVectorKeywords = {'category': 'exposure',
'datatype': 'itb',
'subcategory': 'structure'}
self.expectedRasterKeywords = {'category': 'hazard',
'source': 'USGS',
'subcategory': 'earthquake',
'unit': 'MMI',
'title': ('An earthquake in Padang '
'like in 2009')}
开发者ID:simod,项目名称:inasafe,代码行数:25,代码来源:test_keyword_io.py
示例2: Xtest_renderTable
def Xtest_renderTable(self):
"""Test that html renders nicely. Commented out for now until we work
out how to get webkit to do offscreen rendering nicely."""
myFilename = 'test_floodimpact.tif'
myLayer, myType = loadLayer(myFilename)
CANVAS.refresh()
del myType
myMessage = 'Layer is not valid: %s' % myFilename
assert myLayer.isValid(), myMessage
myMap = Map(IFACE)
myMap.setImpactLayer(myLayer)
myPixmap = myMap.renderImpactTable()
assert myPixmap is not None
myExpectedWidth = 500
myExpectedHeight = 300
myMessage = 'Invalid width - got %s expected %s' % (
myPixmap.width(),
myExpectedWidth)
assert myPixmap.width() == myExpectedWidth, myMessage
myMessage = 'Invalid height - got %s expected %s' % (
myPixmap.height(),
myExpectedHeight)
assert myPixmap.height() == myExpectedHeight
myPath = os.path.join(temp_dir(), 'renderImpactTable.png')
myPixmap.save(myPath, 'PNG')
myExpectedHash = 'c9164d5c2bb85c6081905456ab827f3e'
assertHashForFile(myExpectedHash, myPath)
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:27,代码来源:test_map.py
示例3: test_addClassToLegend
def test_addClassToLegend(self):
"""Test we can add a class to the map legend."""
myLayer, myType = loadLayer('test_shakeimpact.shp')
del myType
myMap = Map(IFACE)
myMap.setImpactLayer(myLayer)
myMap.legend = None
myColour = QtGui.QColor(12, 34, 126)
myMap.addClassToLegend(myColour,
theMin=None,
theMax=None,
theCategory=None,
theLabel='bar')
myMap.addClassToLegend(myColour,
theMin=None,
theMax=None,
theCategory=None,
theLabel='foo')
myPath = os.path.join(temp_dir(), 'addClassToLegend.png')
myMap.legend.save(myPath, 'PNG')
# As we have discovered, different versions of Qt and
# OS platforms cause different output, so hashes are a list
# of 'known good' renders.
myExpectedHashes = ['', # win
'67c0f45792318298664dd02cc0ac94c3', # ub12.04xiner
'ea0702782c2ed5d950c427fbe1743858', # ub11.04-64
'53e0ba1144e071ad41756595d29bf444', # ub12.04
'0681c3587305074bc9272f456fb4dd09', # ub12.04 xvfb
'a37443d70604bdc8c279576b424a158c', # ub12.04-64
# ub11.04-64 laptop
'944cee3eb9d916816b60ef41e8069683', # binary read
'de3ceb6547ffc6c557d031c0b7ee9e75', # wVistaSP2-32
'',
]
assertHashesForFile(myExpectedHashes, myPath)
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:35,代码来源:test_map.py
示例4: test_addSymbolToLegend
def test_addSymbolToLegend(self):
"""Test we can add a symbol to the legend."""
myLayer, _ = loadLayer('test_floodimpact.tif')
myMapLegend = MapLegend(myLayer)
mySymbol = QgsSymbol()
mySymbol.setColor(QtGui.QColor(12, 34, 56))
myMapLegend.addSymbolToLegend(mySymbol,
theMin=0,
# expect 2.0303 in legend
theMax=2.02030,
theCategory=None,
theLabel='Foo')
myPath = unique_filename(prefix='addSymbolToLegend',
suffix='.png',
dir=temp_dir('test'))
myMapLegend.getLegend().save(myPath, 'PNG')
LOGGER.debug(myPath)
# As we have discovered, different versions of Qt and
# OS platforms cause different output, so myControlImages is a list
# of 'known good' renders.
myTolerance = 0 # to allow for version number changes in disclaimer
myFlag, myMessage = checkImages('addSymbolToLegend.png',
myPath,
myTolerance)
myMessage += ('\nWe want these images to match, if they do already '
'copy the test image generated to create a new control '
'image.')
assert myFlag, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:29,代码来源:test_map_legend.py
示例5: test_getLegend
def test_getLegend(self):
"""Getting a legend for a generic layer works."""
LOGGER.debug('test_getLegend called')
myLayer, _ = loadLayer('test_shakeimpact.shp')
myMapLegend = MapLegend(myLayer)
assert myMapLegend.layer is not None
myLegend = myMapLegend.getLegend()
myPath = unique_filename(prefix='getLegend',
suffix='.png',
dir=temp_dir('test'))
myLegend.save(myPath, 'PNG')
LOGGER.debug(myPath)
# As we have discovered, different versions of Qt and
# OS platforms cause different output, so myControlImages is a list
# of 'known good' renders.
myTolerance = 0 # to allow for version number changes in disclaimer
myFlag, myMessage = checkImages('getLegend.png',
myPath,
myTolerance)
myMessage += ('\nWe want these images to match, if they do already '
'copy the test image generated to create a new control '
'image.')
assert myFlag, myMessage
LOGGER.debug('test_getLegend done')
开发者ID:maning,项目名称:inasafe,代码行数:26,代码来源:test_map_legend.py
示例6: loadLayers
def loadLayers(theLayerList, theClearFlag=True, theDataDirectory=TESTDATA):
"""Helper function to load layers as defined in a python list."""
# First unload any layers that may already be loaded
if theClearFlag:
for myLayer in QgsMapLayerRegistry.instance().mapLayers():
QgsMapLayerRegistry.instance().removeMapLayer(myLayer)
# Now go ahead and load our layers
myExposureLayerCount = 0
myHazardLayerCount = 0
myCanvasLayers = []
# Now create our new layers
for myFile in theLayerList:
myLayer, myType = loadLayer(myFile, theDataDirectory)
if myType == 'hazard':
myHazardLayerCount += 1
elif myType == 'exposure':
myExposureLayerCount += 1
# Add layer to the registry (that QGis knows about)
QgsMapLayerRegistry.instance().addMapLayer(myLayer)
# Create Map Canvas Layer Instance and add to list
myCanvasLayers.append(QgsMapCanvasLayer(myLayer))
# Quickly add any existing CANVAS layers to our list first
for myLayer in CANVAS.layers():
myCanvasLayers.append(QgsMapCanvasLayer(myLayer))
# now load all these layers in the CANVAS
CANVAS.setLayerSet(myCanvasLayers)
DOCK.getLayers()
# Add MCL's to the CANVAS
return myHazardLayerCount, myExposureLayerCount
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:35,代码来源:test_dock.py
示例7: test_printImpactTable
def test_printImpactTable(self):
"""Test that we can render html from impact table keywords."""
LOGGER.debug('InaSAFE HtmlRenderer testing printImpactTable')
myFilename = 'test_floodimpact.tif'
myLayer, _ = loadLayer(myFilename)
myMessage = 'Layer is not valid: %s' % myFilename
assert myLayer.isValid(), myMessage
myPageDpi = 300
myHtmlRenderer = HtmlRenderer(myPageDpi)
myPath = unique_filename(prefix='impactTable',
suffix='.pdf',
dir=temp_dir('test'))
myKeywordIO = KeywordIO()
myKeywords = myKeywordIO.readKeywords(myLayer)
myPath = myHtmlRenderer.printImpactTable(myKeywords,
theFilename=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
myExpectedSize = 20936 # as rendered on linux ub 12.04 64
myMessage = ('Expected rendered table pdf to be at least %s, got %s'
% (myExpectedSize, mySize))
assert mySize >= myExpectedSize, myMessage
开发者ID:jjdida25,项目名称:inasafe,代码行数:27,代码来源:test_html_renderer.py
示例8: test_addClassToLegend
def test_addClassToLegend(self):
"""Test we can add a class to the map legend."""
myLayer, _ = loadLayer('test_shakeimpact.shp')
myMapLegend = MapLegend(myLayer)
myColour = QtGui.QColor(12, 34, 126)
myMapLegend.addClassToLegend(myColour,
theMin=None,
theMax=None,
theCategory=None,
theLabel='bar')
myMapLegend.addClassToLegend(myColour,
theMin=None,
theMax=None,
theCategory=None,
theLabel='foo')
myPath = unique_filename(prefix='addClassToLegend',
suffix='.png',
dir=temp_dir('test'))
myMapLegend.getLegend().save(myPath, 'PNG')
LOGGER.debug(myPath)
# As we have discovered, different versions of Qt and
# OS platforms cause different output, so place any other possible
# variants in the safe_qgis/test_data/test_images/ dir e.g.
# addClassToLegend-variantUbuntu13.04.png
myTolerance = 0 # to allow for version number changes in disclaimer
myFlag, myMessage = checkImages('addClassToLegend.png',
myPath,
myTolerance)
myMessage += ('\nWe want these images to match, if they do already '
'copy the test image generated to create a new control '
'image.')
assert myFlag, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:32,代码来源:test_map_legend.py
示例9: 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, _ = loadLayer('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.setImpactLayer(myLayer)
myMap.composeMap()
myPath = unique_filename(prefix='mapPdfTest',
suffix='.pdf',
dir=temp_dir('test'))
myMap.printToPdf(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
myExpectedSize = 352798 # as rendered on linux ub 12.04 64
myMessage = 'Expected rendered map pdf to be at least %s, got %s' % (
myExpectedSize, mySize)
assert mySize >= myExpectedSize, myMessage
开发者ID:zzpwelkin,项目名称:inasafe,代码行数:29,代码来源:test_map.py
示例10: test_getVectorLegend
def test_getVectorLegend(self):
"""Getting a legend for a vector layer works."""
myLayer, _ = loadLayer('test_shakeimpact.shp')
myMapLegend = MapLegend(myLayer)
myImage = myMapLegend.getVectorLegend()
myPath = unique_filename(prefix='getVectorLegend',
suffix='.png',
dir=temp_dir('test'))
myImage.save(myPath, 'PNG')
LOGGER.debug(myPath)
# As we have discovered, different versions of Qt and
# OS platforms cause different output, so myControlImages is a list
# of 'known good' renders.
myControlImages = ['getVectorLegend.png',
'getVectorLegend-variantWindosVistaSP2-32.png',
'getVectorLegend-variantUB12.04-64.png',
'getVectorLegend-variantUB11.04-64.png',
'getVectorLegend-variantJenkins.png']
myTolerance = 0 # to allow for version number changes in disclaimer
myFlag, myMessage = checkImages(myControlImages,
myPath,
myTolerance)
myMessage += ('\nWe want these images to match, if they do already '
'copy the test image generated to create a new control image.')
assert myFlag, myMessage
开发者ID:simod,项目名称:inasafe,代码行数:25,代码来源:test_map_legend.py
示例11: test_addClassToLegend
def test_addClassToLegend(self):
"""Test we can add a class to the map legend."""
myLayer, _ = loadLayer('test_shakeimpact.shp')
myMapLegend = MapLegend(myLayer)
myColour = QtGui.QColor(12, 34, 126)
myMapLegend.addClassToLegend(myColour,
theMin=None,
theMax=None,
theCategory=None,
theLabel='bar')
myMapLegend.addClassToLegend(myColour,
theMin=None,
theMax=None,
theCategory=None,
theLabel='foo')
myPath = unique_filename(prefix='addClassToLegend',
suffix='.png',
dir=temp_dir('test'))
myMapLegend.getLegend().save(myPath, 'PNG')
LOGGER.debug(myPath)
# As we have discovered, different versions of Qt and
# OS platforms cause different output, so myControlImages is a list
# of 'known good' renders.
myControlImages = ['getClassToLegend.png',
'getClassToLegend-variantWindosVistaSP2-32.png',
'getClassToLegend-variantUB12.04-64.png',
'getClassToLegend-variantUB11.04-64.png',
'getClassToLegend-variantJenkins.png']
myTolerance = 0 # to allow for version number changes in disclaimer
myFlag, myMessage = checkImages(myControlImages,
myPath,
myTolerance)
myMessage += ('\nWe want these images to match, if they do already '
'copy the test image generated to create a new control image.')
assert myFlag, myMessage
开发者ID:simod,项目名称:inasafe,代码行数:35,代码来源:test_map_legend.py
示例12: test_getVectorLegend
def test_getVectorLegend(self):
"""Getting a legend for a vector layer works."""
myLayer, _ = loadLayer('test_shakeimpact.shp')
myMapLegend = MapLegend(
myLayer,
theLegendNotes='Thousand separator represented by \'.\'',
theLegendUnits='(people per cell)')
myImage = myMapLegend.getVectorLegend()
myPath = unique_filename(prefix='getVectorLegend',
suffix='.png',
dir=temp_dir('test'))
myImage.save(myPath, 'PNG')
print myMapLegend.legendUnits
print myMapLegend.legendNotes
print myPath
LOGGER.debug(myPath)
# As we have discovered, different versions of Qt and
# OS platforms cause different output, so myControlImages is a list
# of 'known good' renders.
myControlImages = ['getVectorLegend.png',
'getVectorLegend-variantWindowsVistaSP2-32.png',
'getVectorLegend-variantWindowsXPSP3-32.png',
'getVectorLegend-variantOSXml.png',
'getVectorLegend-variantUB12.04-64.png',
'getVectorLegend-variantUB11.04-64.png',
'getVectorLegend-variantLinuxMint-14-x86_64.png',
'getVectorLegend-variantWindows7-SP1-AMD64.png',
'getVectorLegend-variantJenkins.png']
myTolerance = 0 # to allow for version number changes in disclaimer
myFlag, myMessage = checkImages(myControlImages, myPath, myTolerance)
myMessage += ('\nWe want these images to match, if they do already '
'copy the test image generated to create a new control '
'image.')
assert myFlag, myMessage
开发者ID:jjdida25,项目名称:inasafe,代码行数:34,代码来源:test_map_legend.py
示例13: test_getMapTitle
def test_getMapTitle(self):
"""Getting the map title from the keywords"""
myLayer, _ = loadLayer('test_floodimpact.tif')
myMap = Map(IFACE)
myMap.setImpactLayer(myLayer)
myTitle = myMap.getMapTitle()
myExpectedTitle = 'Penduduk yang Mungkin dievakuasi'
myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
assert myTitle == myExpectedTitle, myMessage
开发者ID:zzpwelkin,项目名称:inasafe,代码行数:9,代码来源:test_map.py
示例14: 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, _ = loadLayer('population_padang_1.asc')
myMap = Map(IFACE)
myMap.setImpactLayer(myLayer)
myTitle = myMap.getMapTitle()
myExpectedTitle = None
myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
assert myTitle == myExpectedTitle, myMessage
开发者ID:zzpwelkin,项目名称:inasafe,代码行数:12,代码来源:test_map.py
示例15: test_renderComposition
def test_renderComposition(self):
"""Test making an image of the map only."""
LOGGER.info('Testing renderComposition')
myLayer, _ = loadLayer('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.setImpactLayer(myLayer)
myMap.composeMap()
myImagePath, myControlImage, myTargetArea = myMap.renderComposition()
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
myAcceptableImages = [
'renderComposition.png',
'renderComposition-variantUB12.04.png',
'renderComposition-variantUB12.10.png',
'renderComposition-variantOSXml.png',
'renderComposition-variantWindowsVistaSP2-32.png',
'renderComposition-variantJenkins.png',
'renderComposition-variantUB11.10-64.png',
'renderComposition-variantLinuxMint-14-x86_64.png',
'renderComposition-variantWindows7-SP1-AMD64.png',
'renderComposition-variantUB11.04-64.png']
# 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
print myImagePath
print myAcceptableImages
myFlag, myMessage = checkImages(myAcceptableImages,
myImagePath,
myTolerance)
assert myFlag, myMessage
开发者ID:rlbartolome,项目名称:inasafe,代码行数:51,代码来源:test_map.py
示例16: Xtest_renderTemplate
def Xtest_renderTemplate(self):
"""Test that load template works"""
# Use the template from our resources bundle
myInPath = ":/plugins/inasafe/basic.qpt"
myLayer, _ = loadLayer("test_shakeimpact.shp")
myCanvasLayer = QgsMapCanvasLayer(myLayer)
CANVAS.setLayerSet([myCanvasLayer])
myMap = Map(IFACE)
setJakartaGeoExtent()
myMap.setImpactLayer(myLayer)
myPath = unique_filename(prefix="outTemplate", suffix=".pdf", dir=temp_dir("test"))
LOGGER.debug(myPath)
myMap.renderTemplate(myInPath, myPath)
assert os.path.exists(myPath)
开发者ID:nadyaoktaviani,项目名称:inasafe,代码行数:15,代码来源:test_map.py
示例17: test_renderTemplate
def test_renderTemplate(self):
"""Test that load template works"""
#Use the template from our resources bundle
myInPath = ':/plugins/inasafe/basic.qpt'
myLayer, myType = loadLayer('test_shakeimpact.shp')
del myType
myCanvasLayer = QgsMapCanvasLayer(myLayer)
CANVAS.setLayerSet([myCanvasLayer])
myMap = Map(IFACE)
setJakartaGeoExtent()
myMap.setImpactLayer(myLayer)
myOutPath = os.path.join(temp_dir(), 'outTemplate.pdf')
if os.path.exists(myOutPath):
os.remove(myOutPath)
myMap.renderTemplate(myInPath, myOutPath)
assert os.path.exists(myOutPath)
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:17,代码来源:test_map.py
示例18: addSymbolToLegend
def addSymbolToLegend(self):
"""Test we can add a symbol to the legend."""
myLayer, myType = loadLayer('test_floodimpact.tif')
del myType
myMap = Map(IFACE)
myMap.setImpactLayer(myLayer)
myMap.legend = None
mySymbol = QgsSymbol()
mySymbol.setColor(QtGui.QColor(12, 34, 56))
myMap.addSymbolToLegend(mySymbol,
theMin=0,
theMax=2,
theCategory=None,
theLabel='Foo')
myPath = os.path.join(temp_dir(), 'addSymbolToLegend.png')
myMap.legend.save(myPath, 'PNG')
myExpectedHash = '1234'
assertHashForFile(myExpectedHash, myPath)
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:18,代码来源:test_map.py
示例19: test_inasafeMap
def test_inasafeMap(self):
"""Test making a pdf using the Map class."""
myLayer, myType = loadLayer('test_shakeimpact.shp')
del myType
myCanvasLayer = QgsMapCanvasLayer(myLayer)
CANVAS.setLayerSet([myCanvasLayer])
myMap = Map(IFACE)
myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
CANVAS.setExtent(myRect)
CANVAS.refresh()
myMap.setImpactLayer(myLayer)
myPath = os.path.join(temp_dir(), 'outCustom.pdf')
if os.path.exists(myPath):
os.remove(myPath)
myMap.makePdf(myPath)
assert os.path.exists(myPath)
# ,, note:: Template writing is experimental
myMap.writeTemplate(os.path.join(temp_dir(), 'template.qpt'))
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:18,代码来源:test_map.py
示例20: test_layerChanged
def test_layerChanged(self):
"""Test the metadata is updated as the user highlights different
QGIS layers. For inasafe outputs, the table of results should be shown
See also
https://github.com/AIFDR/inasafe/issues/58
"""
myLayer, myType = loadLayer('issue58.tif')
myMessage = ('Unexpected category for issue58.tif.\nGot:'
' %s\nExpected: undefined' % myType)
assert myType == 'undefined', myMessage
DOCK.layerChanged(myLayer)
DOCK.saveState()
myHtml = DOCK.state['report']
myExpectedString = '4229'
myMessage = "%s\nDoes not contain:\n%s" % (
myHtml,
myExpectedString)
assert myExpectedString in myHtml, myMessage
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:19,代码来源:test_dock.py
注:本文中的safe_qgis.utilities_test.loadLayer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论