o 3a7 @sddlmZmZmZmZddlmZddlmZ ddl m Z ddl m Z ddlmZddlmZmZmZmZGd d d e ZGd d d eZd S))byrefc_doublec_intc_void_p) GDALException)raster)GDALRasterBase)numpy) force_str)GDAL_COLOR_TYPESGDAL_INTEGER_TYPESGDAL_PIXEL_TYPESGDAL_TO_CTYPESc@seZdZdZddZddZeddZedd Zed d Z ed d Z dZ d#ddZ eddZ eddZeddZeddZeddZejddZd$ddZd$ddZd%d!d"Zd S)&GDALBandzQ Wrap a GDAL raster band, needs to be obtained from a GDALRaster object. cCs||_t|j||_dSN)sourcecapiget_ds_raster_band_ptr)selfrindexrE/usr/lib/python3/dist-packages/django/contrib/gis/gdal/raster/band.py__init__szGDALBand.__init__cCs|jd|_dS)z Call the flush method on the Band's parent raster and force a refresh of the statistics attribute when requested the next time. TN)r_flush_stats_refreshrrrrrs  zGDALBand._flushcCstt|jS)z< Return the description string of the band. )r rget_band_descriptionrrrrr descriptionszGDALBand.descriptioncC t|jS)z7 Width (X axis) in pixels of the band. )rget_band_xsizerrrrrwidth% zGDALBand.widthcCr )z8 Height (Y axis) in pixels of the band. )rget_band_ysizerrrrrheight,r#zGDALBand.heightcCs |j|jS)zA Return the total number of pixels in this band. )r"r%rrrr pixel_count3r#zGDALBand.pixel_countFc Csttttf\}}}}|jt|t|t|t|t|ttg}|s*|jr.tj}n d} |dt| tj }z|||j |j |j |j f} Wn t yVd} Ynwd|_| S)a Compute statistics on the pixel values of this band. The return value is a tuple with the following structure: (minimum, maximum, mean, standard deviation). If approximate=True, the statistics may be computed based on overviews or a subset of image tiles. If refresh=True, the statistics will be computed from the data directly, and the cache will be updated where applicable. For empty bands (where all pixel values are nodata), all statistics values are returned as None. For raster formats using Persistent Auxiliary Metadata (PAM) services, the statistics might be cached in an auxiliary file. T)NNNNF) rrrrrrrcompute_band_statisticsinsertget_band_statisticsvaluer) rrefresh approximatesminsmaxsmeansstd stats_argsfuncforceresultrrr statistics<s"  zGDALBand.statisticscC |dS)z? Return the minimum pixel value for this band. rr6rrrrminjr#z GDALBand.mincCr7)z? Return the maximum pixel value for this band. r r8rrrrmaxqr#z GDALBand.maxcCr7)zC Return the mean of all pixel values of this band. r'r8rrrrmeanxr#z GDALBand.meancCr7)zQ Return the standard deviation of all pixel values of this band. r8rrrrstdr#z GDALBand.stdcCs8t}t|j|}|sd}|S|tvrt|}|S)zQ Return the nodata value for this band, or None if it isn't set. N)rrget_band_nodata_valuerdatatyper int)r nodata_existsr+rrr nodata_values zGDALBand.nodata_valuecCsT|durtjs tdt|jnt|ttfstdt|j||dS)z5 Set the nodata value for this band. Nz-GDAL >= 2.1 required to delete nodata values.z%Nodata value must be numeric or None.) rdelete_band_nodata_value ValueErrorr isinstancer@floatset_band_nodata_valuer)rr+rrrrBs cCt|j}|r t|}|S)z? Return the GDAL Pixel Datatype for this band. )rget_band_datatyperr)r as_stringdtyperrrr?s zGDALBand.datatypecCrH)z3Return the GDAL color interpretation for this band.)rget_band_color_interprr )rrJcolorrrr color_interps zGDALBand.color_interpNc Csd|pd}|p|j|d|j|df}|p|}tdd|Dr%td|d|jks3|d|jkr7tdt||d|d}|durOd}|}nd}t|ttfs`t rft|t j rf| |}n||}t |j||d|d|d|dt||d|d|dd |dur|rt|St rt j|t |d tt|St|S|dS) ae Read or writes pixel values for this band. Blocks of data can be accessed by specifying the width, height and offset of the desired block. The same specification can be used to update parts of a raster by providing an array of values. Allowed input data types are bytes, memoryview, list, tuple, and array. )rrrr css|]}|dkVqdS)rNr).0xrrr sz GDALBand.data..zOffset too big for this raster.zSize is larger than raster.N)rK)r"r%anyrDrr?rEbytes memoryviewr ndarrayfrom_buffer_copyrband_iorr frombufferrKreshapetuplereversedlistr) rdataoffsetsizeshape as_memoryview ctypes_array access_flag data_arrayrrrr]s<    z GDALBand.data)FF)F)NNNNF)__name__ __module__ __qualname____doc__rrpropertyrr"r%r&rr6r9r:r;r=rBsetterr?rNr]rrrrrs:     .        rcs4eZdZfddZddZddZddZZS) BandListcs||_tdSr)rsuperr)rr __class__rrrszBandList.__init__ccs,tdt|dD] }t|j|Vq dS)Nr )rangelenrr)ridxrrr__iter__szBandList.__iter__cCst|jjSr)rget_ds_raster_countrrrrrr__len__szBandList.__len__cCs.z t|j|dWStytd|w)Nr zUnable to get band index %d)rrr)rrrrr __getitem__s   zBandList.__getitem__)rerfrgrrrrtru __classcell__rrrmrrks  rkN)ctypesrrrrdjango.contrib.gis.gdal.errorr"django.contrib.gis.gdal.prototypesrr#django.contrib.gis.gdal.raster.baserdjango.contrib.gis.shortcutsr django.utils.encodingr constr r rrrr\rkrrrrs     _