def __init__(self, uri): """ Constructor for the GeoPackage DataStore. :param uri: A filepath which doesn't exist :type uri: QFileInfo, str .. versionadded:: 4.0 """ super(GeoPackage, self).__init__(uri) self.vector_driver = ogr.GetDriverByName('GPKG') self.raster_driver = gdal.GetDriverByName('GPKG') if isinstance(uri, QFileInfo): self._uri = uri elif isinstance(uri, str): self._uri = QFileInfo(uri) else: raise ErrorDataStore('Unknown type') if self.uri.exists(): raster_datasource = gdal.Open(self.uri.absoluteFilePath()) if raster_datasource is None: # Let's try if it's a vector one. vector_datasource = self.vector_driver.Open( self.uri.absoluteFilePath()) if vector_datasource is None: msg = 'The file is not a geopackage or it doesn\'t ' \ 'contain any layers.' raise ErrorDataStore(msg) else: path = self.uri.absoluteFilePath() # We need this variable to be created. The delete will create it. datasource = self.vector_driver.CreateDataSource(path) # NOQA del datasource
def __init__(self, uri): """ Constructor for the folder DataStore. :param uri: A directory object or the path to the folder :type uri: QDir, str .. versionadded:: 4.0 """ super(Folder, self).__init__(uri) self._default_vector_format = 'shp' if isinstance(uri, QDir): self._uri = uri elif isinstance(uri, basestring): self._uri = QDir(uri) else: raise ErrorDataStore('Unknown type')