示例#1
0
    def _vrtinit(self, gdalobj, cachedir=None):
        # Build the virtual dataset filename
        if cachedir is None:
            cachedir = self._get_cachedir(gdalobj)

        if not os.path.isdir(cachedir):
            os.makedirs(cachedir)

        vrtfilename = os.path.join(cachedir, 'virtual-dataset.vrt')

        # Create the virtual dataset
        # @TODO: check 'openshared'
        vrtdataset = None
        if os.path.exists(vrtfilename):
            # @TODO: check if opening the dataset in update mode
            #        (gdal.GA_Update) is a better solution
            vrtdataset = gdal.Open(vrtfilename, gdal.GA_Update)

        if vrtdataset is None:
            # Handle both non existing self.vrtfilename and errors in opening
            # existing self.vrtfilename
            if gdalobj.GetDriver().ShortName.upper() == 'VRT':
                gdalsupport.safe_vrt_copy(gdalobj, vrtfilename)
                vrtdataset = gdal.Open(vrtfilename, gdal.GA_Update)
            else:
                driver = gdal.GetDriverByName('VRT')
                vrtdataset = driver.CreateCopy(vrtfilename, gdalobj)

        if vrtdataset is None:
            raise ValueError('unable to open the GDAL virtual dataset: "%s"' %
                             os.path.basename(vrtfilename))
        return vrtfilename, vrtdataset
示例#2
0
    def test_relative_to_vrt(self):
        gdalsupport.safe_vrt_copy(self.srcfilename, self.dstfilename)

        xml = etree.parse(self.dstfilename)
        sources = list(xml.iter('SourceFilename'))
        self.assertGreater(len(sources), 0)
        for element in sources:
            # with self.subTest( XXX )
            relativeToVRT = element.get('relativeToVRT')
            self.assertTrue(relativeToVRT is not None)
            self.assertEqual(relativeToVRT, '0')
示例#3
0
 def test_copy_open(self):
     gdalsupport.safe_vrt_copy(self.srcfilename, self.dstfilename)
     ds = gdal.Open(self.dstfilename)
     self.assertTrue(ds is not None)
示例#4
0
 def test_copy_ds(self):
     self.assertFalse(os.path.exists(self.dstfilename))
     ds = gdal.Open(self.srcfilename)
     self.assertTrue(ds is not None)
     gdalsupport.safe_vrt_copy(ds, self.dstfilename)
     self.assertTrue(os.path.exists(self.dstfilename))
示例#5
0
 def test_copy_file(self):
     self.assertFalse(os.path.exists(self.dstfilename))
     gdalsupport.safe_vrt_copy(self.srcfilename, self.dstfilename)
     self.assertTrue(os.path.exists(self.dstfilename))