本文整理汇总了Python中safe.storage.raster.Raster.get_bounding_box方法的典型用法代码示例。如果您正苦于以下问题:Python Raster.get_bounding_box方法的具体用法?Python Raster.get_bounding_box怎么用?Python Raster.get_bounding_box使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.storage.raster.Raster
的用法示例。
在下文中一共展示了Raster.get_bounding_box方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_qgis_raster_layer_loading
# 需要导入模块: from safe.storage.raster import Raster [as 别名]
# 或者: from safe.storage.raster.Raster import get_bounding_box [as 别名]
def test_qgis_raster_layer_loading(self):
"""Test that reading from QgsRasterLayer works."""
# This line is the cause of the problem:
qgis_layer = QgsRasterLayer(RASTER_BASE + '.tif', 'test')
layer = Raster(data=qgis_layer)
qgis_extent = qgis_layer.dataProvider().extent()
qgis_extent = [qgis_extent.xMinimum(), qgis_extent.yMinimum(),
qgis_extent.xMaximum(), qgis_extent.yMaximum()]
layer_exent = layer.get_bounding_box()
self.assertListEqual(
layer_exent, qgis_extent,
'Expected %s extent, got %s' % (qgis_extent, layer_exent))
示例2: test_convert_to_qgis_raster_layer
# 需要导入模块: from safe.storage.raster import Raster [as 别名]
# 或者: from safe.storage.raster.Raster import get_bounding_box [as 别名]
def test_convert_to_qgis_raster_layer(self):
"""Test that converting to QgsVectorLayer works."""
if qgis_imported:
# Create vector layer
keywords = read_keywords(RASTER_BASE + '.keywords')
layer = Raster(data=RASTER_BASE + '.tif', keywords=keywords)
# Convert to QgsRasterLayer
qgis_layer = layer.as_qgis_native()
qgis_extent = qgis_layer.dataProvider().extent()
qgis_extent = [qgis_extent.xMinimum(), qgis_extent.yMinimum(),
qgis_extent.xMaximum(), qgis_extent.yMaximum()]
layer_exent = layer.get_bounding_box()
self.assertListEqual(
layer_exent, qgis_extent,
'Expected %s extent, got %s' % (qgis_extent, layer_exent))
示例3: start
# 需要导入模块: from safe.storage.raster import Raster [as 别名]
# 或者: from safe.storage.raster.Raster import get_bounding_box [as 别名]
def start(west,north,east,south, since, until=None, data_dir=None, population=None):
bbox = (west, north, east, south)
year, month, day = [int(x) for x in since.split('-')]
since = datetime.date(year, month, day)
if not isinstance(until, datetime.date):
year, month, day = [int(x) for x in until.split('-')]
until = datetime.date(year, month, day)
else:
until = until
# Make sure the inputs are divisible by 10.
for item in bbox:
msg = "%d is not divisible by 10." % item
assert int(item) % 10 == 0, msg
the_viewports = viewports(bbox)
the_timespan = timespan(since, until)
data_dir = os.path.abspath(data_dir)
if not os.path.exists(data_dir):
os.mkdir(data_dir)
print 'Downloading layers per day'
# Download the layers for the given viewport and timespan.
download(the_viewports, the_timespan, data_dir)
print 'Merging layers per day'
merged_files = merge(the_timespan, data_dir)
flood_filename = os.path.join(data_dir, 'flood_severity.tif')
if not os.path.exists(flood_filename):
if len(merged_files) > 0:
# Add all the pixels with a value higher than 3.
#accumulate(merged_files, flood_filename, threshold=3)
flooded = _flood_severity(merged_files)
flooded.write_to_file(flood_filename)
subprocess.call(['gdal_merge.py',
'-co', 'compress=packbits',
'-o', 'flood_severity_compressed.tif',
'-ot', 'Byte',
flood_filename], stdout=open(os.devnull, 'w'))
os.remove(flood_filename)
os.rename('flood_severity_compressed.tif', flood_filename)
else:
raise Exception('No merged files found for %s' % the_timespan)
population_file = os.path.join(data_dir, population)
population_object = Raster(population_file)
# get population bbox
pop_bbox = population_object.get_bounding_box()
# get resolutions and pick the best
pop_resolution = population_object.get_resolution()[0]
hazard_object = Raster(flood_filename)
hazard_resolution = hazard_object.get_resolution()[0]
hazard_bbox = hazard_object.get_bounding_box()
if pop_bbox[0] > bbox[0] and pop_bbox[1] > bbox[1] and pop_bbox[2] < bbox[2] and pop_bbox[3] < bbox[3]:
hazard_file = clip(flood_filename, pop_bbox, cellSize=pop_resolution)
exposure_layer = population_file
else:
hazard_file = clip(flood_filename, hazard_bbox, cellSize=pop_resolution)
exposure_layer = clip(population_file, hazard_bbox, cellSize=None)
basename, ext = os.path.splitext(hazard_file)
keywords_file = basename + '.keywords'
if not os.path.exists(keywords_file):
with open(keywords_file, 'w') as f:
f.write(FLOOD_KEYWORDS)
impact = calculate(hazard_file, exposure_layer)
impact.write_to_file('impact.tif')
count = impact.keywords['count']
pretty_date = until.strftime('%a %d, %b %Y')
print pretty_date, "|", "People affected: %s / %s" % (count, impact.keywords['total'])