示例#1
0
    def _reopen(self, gdalobj=None):
        if not gdalobj:
            # assume self._obj has already been set from caller
            gdalobj = self._obj
        else:
            self._obj = gdalobj

        if self.rowCount() > gdalobj.GetOverviewCount():
            _log.warning(
                'unable to reopen raster band: unexpected number of overviews')
            return

        if VISIBLE_OVERVIEW_ITEMS:
            levelsmap = dict(zip(gdalsupport.ovrLevels(gdalobj),
                                 range(gdalobj.GetOverviewCount())))

            oldlevelsmap = dict(zip(gdalsupport.ovrLevels(self._obj),
                                range(self._obj.GetOverviewCount())))

            toremove = []
            for level, index in oldlevelsmap.items():
                if level not in levelsmap:
                    #self.removeRow(index)
                    toremove.append(index)
                else:
                    item = self.GetOverview(index)
                    newindex = levelsmap[level]
                    item._reopen(gdalobj.GetOverview(newindex))

            for index in toremove:
                self.takeRow(index)

            for level, index in levelsmap.items():
                if level in oldlevelsmap:
                    continue

                ovr = gdalobj.GetOverview(index)
                item = OverviewItem(ovr)
                if not item.text():
                    text = 'Overview'
                    if QtWidgets.qApp is not None:
                        text = QtWidgets.qApp.tr(text)
                    description = '%s n. %d' % (text, index)
                    item.setText(description)
                    item.setToolTip(description)
                self.insertRow(index, item)

            # @TODO: complete
            #self.sortChildren(0, QtCore.Qt.AscendngOrder)

        self._obj = gdalobj
        self.model().itemChanged.emit(self)
示例#2
0
    def setItem(self, item):
        assert item.backend == 'gdalbackend'

        self.graphicsview.setUpdatesEnabled(False)
        try:
            self.reset()

            try:
                level = gdalsupport.ovrLevelForSize(item, self.OVRMAXSIZE)
                # @NOTE: use GREATER for overview level to ensure an overview
                #        size smaller than OVRMAXSIZE
                ovrindex = gdalsupport.ovrBestIndex(item, level, 'GREATER')
            except gdalsupport.MissingOvrError:
                _log.info('no overview available or available overviews are '
                          'too large')
                return

            scene = item.scene
            self.graphicsview.setScene(scene)
            self.graphicsview.setSceneRect(scene.sceneRect())

            if not self.graphicsview.autoscale:
                ovrlevel = gdalsupport.ovrLevels(item)[ovrindex]
                matrix = QtGui.QMatirx3x3(ovrlevel, 0, 0, ovrlevel, 0, 0)
                self.graphicsview.setMatrix(matrix)
            else:
                self.graphicsview.fitInView()

            self.updateMainViewBox()
        finally:
            self.graphicsview.setUpdatesEnabled(True)
            self.graphicsview.update()
示例#3
0
文件: helpers.py 项目: giumas/gsdview
    def target_levels(self, dataset):
        if self._band is not None:
            band = self._band
        else:
            band = dataset.GetRasterBand(1)

        oldlevels = []
        estep = 3
        threshold = 0.1

        if band.GetOverviewCount():
            oldlevels = gdalsupport.ovrLevels(band)
            if set(oldlevels).issuperset((2, 4)):
                estep = 2
                threshold = 1.1

        # @NOTE: use dataset for levels computation because the
        #        IMAGE_STRUCTURE metadata are not propagated from
        #        CachedDatasetItem to raster bands
        levels = gdalsupport.ovrComputeLevels(dataset,
                                              estep=estep,
                                              threshold=threshold)

        # @NOTE: the GDAL band info is configured to force recomputation of
        #        all levels checked
        if levels:
            levels.extend(oldlevels)
            levels.sort()

        return levels
示例#4
0
文件: core.py 项目: pierriko/gsdview
    def setItem(self, item):
        assert item.backend == 'gdalbackend'

        self.graphicsview.setUpdatesEnabled(False)
        try:
            self.reset()

            try:
                level = gdalsupport.ovrLevelForSize(item, self.OVRMAXSIZE)
                # @NOTE: use GREATER for overview level to ensure an overview
                #        size smaller than OVRMAXSIZE
                ovrindex = gdalsupport.ovrBestIndex(item, level, 'GREATER')
            except gdalsupport.MissingOvrError:
                logging.info('no overview available or available overviews '
                             'are too large')
                return

            scene = item.scene
            self.graphicsview.setScene(scene)
            self.graphicsview.setSceneRect(scene.sceneRect())

            if not self.graphicsview.autoscale:
                ovrlevel = gdalsupport.ovrLevels(item)[ovrindex]
                matrix = QtCore.QMatirx(ovrlevel, 0, 0, ovrlevel, 0, 0)
                self.graphicsview.setMatrix(matrix)
            else:
                self.graphicsview.fitInView()

            self.updateMainViewBox()
        finally:
            self.graphicsview.setUpdatesEnabled(True)
            self.graphicsview.update()
示例#5
0
文件: helpers.py 项目: jlbmdm/gsdview
    def target_levels(self, dataset):
        if self._band is not None:
            band = self._band
        else:
            band = dataset.GetRasterBand(1)

        oldlevels = []
        estep = 3
        threshold = 0.1

        if band.GetOverviewCount():
            oldlevels = gdalsupport.ovrLevels(band)
            if set(oldlevels).issuperset((2, 4)):
                estep = 2
                threshold = 1.1

        # @NOTE: use dataset for levels computation because the
        #        IMAGE_STRUCTURE metadata are not propagated from
        #        CachedDatasetItem to raster bands
        levels = gdalsupport.ovrComputeLevels(dataset, estep=estep, threshold=threshold)

        # @NOTE: the GDAL band info is configured to force recomputation of
        #        all levels checked
        if levels:
            levels.extend(oldlevels)
            levels.sort()

        return levels
示例#6
0
文件: gdalqt.py 项目: giumas/gsdview
    def _bestOvrLevel(band, levelOfDetail):
        ovrlevel = 1
        ovrindex = None

        if band.GetOverviewCount() > 0:
            if levelOfDetail <= 0:
                reqlevel = 1.
            else:
                reqlevel = 1. / levelOfDetail

            try:
                ovrindex = gdalsupport.ovrBestIndex(band, reqlevel)
            except gdalsupport.MissingOvrError:
                pass
            else:
                ovrlevel = gdalsupport.ovrLevels(band)[ovrindex]
                if abs(reqlevel - 1) < abs(reqlevel - ovrlevel):
                    ovrlevel = 1
                    ovrindex = None
                else:
                    band = band.GetOverview(ovrindex)
        return band, ovrlevel, ovrindex
示例#7
0
    def _bestOvrLevel(band, levelOfDetail):
        ovrlevel = 1
        ovrindex = None

        if band.GetOverviewCount() > 0:
            if levelOfDetail <= 0:
                reqlevel = 1.
            else:
                reqlevel = 1. / levelOfDetail

            try:
                ovrindex = gdalsupport.ovrBestIndex(band, reqlevel)
            except gdalsupport.MissingOvrError:
                pass
            else:
                ovrlevel = gdalsupport.ovrLevels(band)[ovrindex]
                if abs(reqlevel - 1) < abs(reqlevel - ovrlevel):
                    ovrlevel = 1
                    ovrindex = None
                else:
                    band = band.GetOverview(ovrindex)
        return band, ovrlevel, ovrindex