4/18/2024 0 Comments Gdal convert webp to gif![]() ![]() To run this script, save it as raster_band_info.py (e.g., in C:\temp in Windows or ~/temp/ in Linux) and navigate to the script directory in a terminal interface (e.g., in P圜harm’s Terminal, Anaconda Prompt, or the Linux Terminal) using the cd command. argv ) < 3 : print ( """ ERROR: Provide two arguments: 1) the band number (int) and 2) input raster directory (str) """ ) how2use () main ( int ( sys. join ( get_color_bands ( band ))) except TypeError : print ( "ColorTable: None" ) if _name_ = '_main_' : # make standalone if len ( sys. GetNoDataValue ()) print ( "Band unit type: ", band. GetMaximum ()) print ( "No-data value: ", band. GetMinimum ()) print ( "Band maximum: ", band. GetColorEntryAsRGB ( c, entry ))) return color_bands def main ( band_number, input_file ): src, band = open_raster ( input_file ) print ( "Band minimum: ", band. GetColorEntry ( c ) if not entry : continue color_bands. GetCount ())) # iterate through color_table and append objects found to colors_bands list color_bands = for c in range ( 0, color_table. GetColorTable () if color_table is None : print ( "Band has no ColorTable." ) return None else : print ( "Found %i color definitions." % int ( color_table. exit ( 1 ) def get_color_bands ( raster_band ): """ :param raster_band: object :output: list of color bands used in raster_band """ # get ColorTable and return False if None color_table = raster_band. UseExceptions () def how2use (): # provide usage instructions for the script print ( """ $ raster_band_info.py input-raster """ ) # exit program if wrong input arguments provided sys. Returns the raster and raster band objects. Opens the raster band number stated in the optional band_number keyword argument with raster_band = raster.GetRasterBand(band_number) (the default value is 1). Opens the provided raster file_name embraced by try - except statements to inform if and why a potential error occurred while opening the raster. To access the raster band, the below-shown open_raster function:Įnables error and warning feedback with gdal.UseExceptions() (this step is vital when using gdal). One of the most important elements when dealing with raster data is the raster band, which takes on a similar data carrier role as GetLayer in shapefile handling. The following code block provides a function to open any raster specified with the file_name input argument. Raster data can be opened in Python code as an instance of gdal.Open("FILENAME"). Load raster # Open Existing Raster Data # Watch this section as a video on the channel on YouTube. Watch this section and the Python tutorials in video formats ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |