當前位置: 首頁>>代碼示例>>Python>>正文


Python Raster.get_bounding_box方法代碼示例

本文整理匯總了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))
開發者ID:codeforresilience,項目名稱:inasafe,代碼行數:14,代碼來源:test_raster.py

示例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))
開發者ID:cccs-ip,項目名稱:inasafe,代碼行數:18,代碼來源:test_raster.py

示例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'])
開發者ID:inasafe,項目名稱:floods,代碼行數:87,代碼來源:floodimpact.py


注:本文中的safe.storage.raster.Raster.get_bounding_box方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。