How to use the gdal.GetLastErrorMsg function in GDAL

To help you get started, we’ve selected a few GDAL examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OSGeo / gdal / autotest / gcore / tiff_write.py View on Github external
old_accum = gdal.GetConfigOption( 'CPL_ACCUM_ERROR_MSG', 'OFF' )
    gdal.SetConfigOption( 'CPL_ACCUM_ERROR_MSG', 'ON' )
    gdal.ErrorReset()
    gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
        
    try:
        ds = gdal.Open('data/mandrilmini_12bitjpeg.tif')
        ds.GetRasterBand(1).ReadRaster(0,0,1,1)
    except:
        ds = None

    gdal.PopErrorHandler()
    gdal.SetConfigOption( 'CPL_ACCUM_ERROR_MSG', old_accum )
    
    if gdal.GetLastErrorMsg().find(
                   'Unsupported JPEG data precision 12') != -1:
        sys.stdout.write('(12bit jpeg not available) ... ')
        return 'skip'

    drv = gdal.GetDriverByName('GTiff')
    dst_ds = drv.CreateCopy( 'tmp/test_74.tif', ds,
                             options = ['COMPRESS=JPEG', 'NBITS=12',
                                        'JPEG_QUALITY=95',
                                        'PHOTOMETRIC=YCBCR'] )

    ds = None
    dst_ds = None

    dst_ds = gdal.Open( 'tmp/test_74.tif' )
    stats = dst_ds.GetRasterBand(1).GetStatistics( 0, 1 )
github OSGeo / gdal / pymod / osr.py View on Github external
"""
        #
        # NOTE: A special requirement of the Atlantis Peppers system is
        # that it needs to be able to instantiate a coordinate tranform
        # by just passing in a tuple with two SpatialReference objects.  We
        # assume this is the case if target is None.

        self._o = None
        if target is None:
            target = source[1]
            source = source[0]

        gdal.ErrorReset()
        self._o = _gdal.OCTNewCoordinateTransformation( source._o, target._o )
        if self._o is None or self._o == 'NULL':
            if len(gdal.GetLastErrorMsg()) > 0:
                raise ValueError, gdal.GetLastErrorMsg()
            else:
                raise ValueError, 'Failed to create coordinate transformation.'
github OSGeo / gdal / gdal / pymod / osr.py View on Github external
def GetUserInputAsWKT( user_def ):
    srs = SpatialReference()
    if srs.SetFromUserInput( user_def ) == 0:
        return srs.ExportToWkt()
    else:
        raise ValueError, gdal.GetLastErrorMsg()
github OSGeo / gdal / gdal / pymod / ogr.py View on Github external
def CopyLayer(self, src_layer, new_name, options = [] ):
        md_c = _gdal.ListToStringList( options )
        obj = _gdal.OGR_DS_CopyLayer( self._o, src_layer._o, new_name, md_c)
        _gdal.CSLDestroy(md_c)
        if obj is None and obj != 'NULL':
            raise OGRError, gdal.GetLastErrorMsg()
        else:
            return Layer( obj = obj )
github OSGeo / gdal / pymod / osr.py View on Github external
def GetUserInputAsWKT( user_def ):
    srs = SpatialReference()
    if srs.SetFromUserInput( user_def ) == 0:
        return srs.ExportToWkt()
    else:
        raise ValueError, gdal.GetLastErrorMsg()
github Esri / raster2gpkg / Desktop10.4.1 / python / osgeo / gdal_array.py View on Github external
def LoadFile( filename, xoff=0, yoff=0, xsize=None, ysize=None ):
    ds = gdal.Open( filename )
    if ds is None:
        raise ValueError("Can't open "+filename+"\n\n"+gdal.GetLastErrorMsg())

    return DatasetReadAsArray( ds, xoff, yoff, xsize, ysize )
github beiko-lab / gengis / bin / Lib / site-packages / osgeo / gdal_array.py View on Github external
def LoadFile( filename, xoff=0, yoff=0, xsize=None, ysize=None ):
    ds = gdal.Open( filename )
    if ds is None:
        raise ValueError("Can't open "+filename+"\n\n"+gdal.GetLastErrorMsg())

    return DatasetReadAsArray( ds, xoff, yoff, xsize, ysize )
github CivicSpleen / ambry / ambry / old / geo / sfschema.py View on Github external
str(c.name), c.python_type(c.default))
                        except:

                            raise

        else:
            raise Exception("Can only handle dict rows")

        if self.transform:
            geometry.Transform(self.transform)

        feature.SetGeometryDirectly(geometry)
        if self.layer.CreateFeature(feature) != 0:
            raise FeatureError(
                'Failed to add feature: {}: geometry={}'.format(
                    gdal.GetLastErrorMsg(),
                    geometry.ExportToWkt()))

        feature.Destroy()
github CivicSpleen / ambry / ambry / warehouse / extractors.py View on Github external
name = self.mangle_name(str(name))

                        feature.SetField(name, value)
                    except Exception:
                        raise
                    except NotImplementedError:
                        raise

            geometry = ogr.CreateGeometryFromWkt(row['_wkt'])

            feature.SetGeometryDirectly(geometry)
            if layer.CreateFeature(feature) != 0:
                import gdal
                raise Exception(
                    'Failed to add feature: {}: geometry={}'.format(gdal.GetLastErrorMsg(), geometry.ExportToWkt()))

            feature.Destroy()

        ds.SyncToDisk()
        ds.Release()

        return True, abs_dest