Python osgeo.gdal.AllRegister() Examples

The following are code examples for showing how to use osgeo.gdal.AllRegister(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: PostgreSQL-GeoPackage   Author: EOX-A   File: gpkg-pg_dump.py    (license) View Source Project 5 votes vote down vote up
def create_gpkg(
    gpkg_name, proj_string, size=(1, 1), geotransform=[0, 1, 0, 0, 0, -1],
    creation_options=None
):
    if os.path.exists("%s.gpkg" % gpkg_name):
        sys.stderr.write(
            "ERROR: SQLite GeoPackage '%s.gpkg' already exists.\n" % gpkg_name
        )
        sys.exit(1)

    gdal.AllRegister()
    drv = gdal.GetDriverByName("GPKG")
    try:
        gpkg = drv.Create(
            "%s.gpkg" % gpkg_name, size[0], size[1], 1, gdal.GDT_Byte,
            creation_options
        )

        proj = osr.SpatialReference()
        res = proj.SetWellKnownGeogCS(proj_string)
        if res != 0:
            if proj_string[0:4] == 'EPSG':
                proj.ImportFromEPSG(int(proj_string[5:]))
        gpkg.SetProjection(proj.ExportToWkt())
        gpkg.SetGeoTransform(geotransform)
        gpkg = None
    except Exception as e:
        sys.stderr.write(
            "ERROR: Cannot create SQLite GeoPackage '%s.gpkg'. "
            "Error message was: '%s'.\n" % (gpkg_name, e.message)
        )
        sys.exit(1) 
Example 2
Project: QGIS-applications   Author: liaduarte   File: GdalTools_utils.py    (license) View Source Project 5 votes vote down vote up
def long2ShortName(self, longName):
      if longName == '':
        return ''

      if self.dict_long2shortName.has_key(longName):
        return self.dict_long2shortName[longName]

      # first get the GDAL driver manager
      if gdal.GetDriverCount() == 0:
        gdal.AllRegister()

      shortName = ''

      # for each loaded GDAL driver
      for i in range(gdal.GetDriverCount()):
        driver = gdal.GetDriver(i)
        if driver == None:
          continue

        # if this is the driver we searched for then return its short name
        if FileFilter.getFilterName(driver.LongName) == longName:
          shortName = FileFilter.getFilterName(driver.ShortName)
          self.dict_long2shortName[longName] = shortName
          break

      return shortName

    # retrieve the raster format short name by using the file name extension 
Example 3
Project: landSurfaceTemperature   Author: miltonisaya   File: lst_tool.py    (license) View Source Project 5 votes vote down vote up
def getGdalRasterFormats(self):
        gdal.AllRegister()
        gdalRasters = ['GTiff']
        '''
        for i in range(0, gdal.GetDriverCount()):
            metadata = gdal.GetDriverCount()
            drv = gdal.GetDriver(i)
            drv_meta = drv.GetMetadata()
            if ('DMD_EXTENSION' in drv_meta):
                gdalRasters.append(drv.ShortName)
        '''
        return gdalRasters