
    dfY                        d dl mZ esdev rddlmZ nd dlZ	 d dlZd Z
d Zd Zd	 Z G d
 de      ZddlmZ  G d de      Z ej&                  e       d Zd Zd Zd Zd Zd Z G d de      Zd Zd Zd:dZej<                  Zd Zd Z d Z!d;dZ"d<dZ#d Z$d  Z%d! Z&d" Z'd# Z(d$ Z)d dl*Z*d d%l+m,Z, d dl+mZ  ejZ                          e,j\                  e*j^                  e,j`                  e*jb                  e,jd                  e*jf                  e,jh                  e*jj                  e,jl                  e*jn                  e,jp                  e*jr                  e,jt                  e*jv                  e,jx                  e*jz                  e,j|                  e*j~                  e,j                  e*j                  e,j                  e*j                  e,j                  e*j                  e,j                  e*j                  e,j                  e*j                  iZHd=d'ZId( ZJd) ZKd* ZLd+ ZMd d dddddej                  ddd&dfd,ZOd>d-ZPd. ZQd d ddddddej                  ddd&dfd/ZRd d dd&ej                  ddfd0ZSd d ddddddej                  ddfd1ZTd d ej                  ddfd2ZUd3 ZVd4 ZW	 	 	 	 	 d?d5ZX	 	 d:d6ZYd@d7ZZd;d8Z[dAd9Z\y# e	$ r d dlZY w xY w)B    )version_info.   )_gdal_arrayNc                     	 d| j                   j                         z   }d| j                  j
                  d| j                  j                  d|dS # t        j                  $ r d}Y Kw xY w)Nz	proxy of  <r   z; z >)this__repr____builtin__	Exception	__class__
__module____name__)selfstrthiss     2/usr/lib/python3/dist-packages/osgeo/gdal_array.py
_swig_reprr      s_    		 2 2 44 "^^668O8OQXZZ    s   A A+*A+c                       fd}|S )Nc                     |dk(  r | ||       y |dk(  r| j                   j                  |       y t        | |      r.t        t	        t        |       |      t              r | ||       y t        d| z        )Nr
   thisownz(You cannot add instance attributes to %s)r
   ownhasattr
isinstancegetattrtypepropertyAttributeError)r   namevaluesets      r   set_instance_attrzE_swig_setattr_nondynamic_instance_variable.<locals>.set_instance_attr   si    6>dE"YIIMM% T4 ZT
D0I8%TdE" !Kd!RSS     )r!   r"   s   ` r   *_swig_setattr_nondynamic_instance_variabler%      s    T r#   c                       fd}|S )Nc                     t        | |      r%t        t        | |      t              s | ||       y t	        d| z        )Nz%You cannot add class attributes to %s)r   r   r   r   r   )clsr   r    r!   s      r   set_class_attrz?_swig_setattr_nondynamic_class_variable.<locals>.set_class_attr)   s:    3jd1CX&NT5! !H3!NOOr#   r$   )r!   r)   s   ` r   '_swig_setattr_nondynamic_class_variabler*   (   s    P
 r#   c                       fd}|S )zlClass decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclassc                 p     | j                   | j                  | j                  j                               S N)r   	__bases____dict__copy)r(   	metaclasss    r   wrapperz$_swig_add_metaclass.<locals>.wrapper3   s'    s}}cll6G6G6IJJr#   r$   )r1   r2   s   ` r   _swig_add_metaclassr3   1   s    KNr#   c                   4    e Zd ZdZ eej                        Zy)_SwigNonDynamicMetazKMeta class to enforce nondynamic attributes (no new attributes) for a classN)r   r   __qualname____doc__r*   r   __setattr__r$   r#   r   r5   r5   8   s    U9$:J:JKKr#   r5   gdalc                   Z    e Zd ZdZ ed d d      Zd ZeZe	j                  Zd Zd
dZy	)
VirtualMemz'Proxy of C++ CPLVirtualMemShadow class.c                 6    | j                   j                         S r-   r
   r   )xs    r   <lambda>zVirtualMem.<lambda>A   s     r#   c                 8    | j                   j                  |      S r-   r>   )r?   vs     r   r@   zVirtualMem.<lambda>A   s    AFFJJqM r#   zThe membership flag)docc                     t        d      )NzNo constructor defined)r   )r   argskwargss      r   __init__zVirtualMem.__init__C   s    566r#   c                 ,    t        j                  |       S )zGetAddr(VirtualMem self))r   VirtualMem_GetAddr)r   s    r   GetAddrzVirtualMem.GetAddrH   s    --d33r#   c                 2    t        j                  | |||      S )zKPin(VirtualMem self, size_t start_offset=0, size_t nsize=0, int bWriteOp=0))r   VirtualMem_Pin)r   start_offsetnsizebWriteOps       r   PinzVirtualMem.PinL   s    ))$eXNNr#   N)r   r   r   )r   r   r6   r7   r   r   rG   r   r   r   delete_VirtualMem__swig_destroy__rJ   rP   r$   r#   r   r<   r<   >   s7    2-/IOdeG7H"444Or#   r<   c                  *    t        j                         S )zGetUseExceptions() -> int)r   GetUseExceptionsr$   r#   r   rT   rT   S   s    ''))r#   c                  *    t        j                         S )z_GetExceptionsLocal() -> int)r   _GetExceptionsLocalr$   r#   r   rV   rV   W   s    **,,r#   c                 ,    t        j                  |       S )z_SetExceptionsLocal(int bVal))r   _SetExceptionsLocal)bVals    r   rX   rX   [   s    **400r#   c                  *    t        j                         S )z_UseExceptions())r   _UseExceptionsr$   r#   r   r[   r[   _   s    %%''r#   c                  *    t        j                         S )z_DontUseExceptions())r   _DontUseExceptionsr$   r#   r   r]   r]   c   s    ))++r#   c                  *    t        j                         S )z+_UserHasSpecifiedIfUsingExceptions() -> int)r   "_UserHasSpecifiedIfUsingExceptionsr$   r#   r   r_   r_   g   s    99;;r#   c                   $    e Zd ZdZddZd Zd Zy)ExceptionMgra  
    Context manager to manage Python Exception state
    for GDAL/OGR/OSR/GNM.

    Separate exception state is maintained for each
    module (gdal, ogr, etc), and this class appears independently
    in all of them. This is built in top of calls to the older
    UseExceptions()/DontUseExceptions() functions.

    Example::

        >>> print(gdal.GetUseExceptions())
        0
        >>> with gdal.ExceptionMgr():
        ...     # Exceptions are now in use
        ...     print(gdal.GetUseExceptions())
        1
        >>>
        >>> # Exception state has now been restored
        >>> print(gdal.GetUseExceptions())
        0

    c                     || _         y)zK
        Save whether or not this context will be using exceptions
        N)requestedUseExceptions)r   useExceptionss     r   rG   zExceptionMgr.__init__   s     '4#r#   c                     t               | _        t        | j                         t        j
                  dk(  r&	 ddlm} |r|j                  | j                         yyy# t        $ r d}Y -w xY w)z
        On context entry, save the current GDAL exception state, and
        set it to the state requested for the context

        
osgeo.gdalr   
gdal_arrayN)	rV   currentUseExceptionsrX   rc   ra   r   r   rh   ImportError)r   rh   s     r   	__enter__zExceptionMgr.__enter__   sl     %8$9!D778""l2"( ..t/J/JK  3  "!
"s   A A-,A-c                     t        | j                         t        j                  dk(  r&	 ddlm} |r|j                  | j                         yyy# t        $ r d}Y -w xY w)zy
        On exit, restore the GDAL/OGR/OSR/GNM exception state which was
        current on entry to the context
        rf   r   rg   N)rX   ri   ra   r   r   rh   rj   )r   exc_typeexc_valexc_tbrh   s        r   __exit__zExceptionMgr.__exit__   sa    
 	D556""l2"( ..t/H/HI  3  "!
"s   A AAN)T)r   r   r6   r7   rG   rk   rp   r$   r#   r   ra   ra   k   s    .4L Jr#   ra   c                     	 ddl m}   | j                          	 ddl m} |j                          	 ddl m} |j                          	 ddl m} |j                          	 ddl m} |j                          y# t        $ r Y hw xY w# t        $ r Y `w xY w# t        $ r Y Xw xY w# t        $ r Y Pw xY w# t        $ r Y yw xY w)z Enable exceptions in all GDAL related modules (osgeo.gdal, osgeo.ogr, osgeo.osr, osgeo.gnm).
        Note: prior to GDAL 3.7, this only affected the calling moduler   r9   rg   ogrosrgnmN)r   r:   r[   rj   rh   rs   ru   rw   r:   rh   rs   ru   rw   s        r   UseExceptionsry      s     !!#'  
  
  
  
  W   A6 B B B# B2 6	BB	BB	B B #	B/.B/2	B>=B>c                     	 ddl m}   | j                          	 ddl m} |j                          	 ddl m} |j                          	 ddl m} |j                          	 ddl m} |j                          y# t        $ r Y hw xY w# t        $ r Y `w xY w# t        $ r Y Xw xY w# t        $ r Y Pw xY w# t        $ r Y yw xY w)z Disable exceptions in all GDAL related modules (osgeo.gdal, osgeo.ogr, osgeo.osr, osgeo.gnm).
        Note: prior to GDAL 3.7, this only affected the calling moduler   r9   rg   rr   rt   rv   N)r   r:   r]   rj   rh   rs   ru   rw   rx   s        r   DontUseExceptionsr|      s    ! %%'   '  
  
  
  
  rz   c                 0    t        j                  | ||      S )z\TermProgress_nocb(double dfProgress, char const * pszMessage=None, void * pData=None) -> int)r   TermProgress_nocb)
dfProgress
pszMessagepDatas      r   r~   r~      s    ((ZGGr#   c                 .    t        j                  | |      S )zDOpenNumPyArray(PyArrayObject * psArray, bool binterleave) -> Dataset)r   OpenNumPyArray)psArraybinterleaves     r   r   r      s    %%g{;;r#   c                 ,    t        j                  |       S )zBOpenMultiDimensionalNumPyArray(PyArrayObject * psArray) -> Dataset)r   OpenMultiDimensionalNumPyArrayr   s    r   r   r      s    55g>>r#   c                 ,    t        j                  |       S )zBGetArrayFilename(PyArrayObject * psArray) -> retStringAndCPLFree *)r   GetArrayFilenamer   s    r   r   r      s    ''00r#   c                 @    t        j                  | |||||||||	|
      S )zBandRasterIONumPy(Band band, int bWrite, double xoff, double yoff, double xsize, double ysize, PyArrayObject * psArray, GDALDataType buf_type, GDALRIOResampleAlg resample_alg, GDALProgressFunc callback=0, void * callback_data=None) -> CPLErr)r   BandRasterIONumPy)bandbWritexoffyoffxsizeysizer   buf_typeresample_algcallbackcallback_datas              r   r   r      s6    ((vtT5%QXZbdprz  }J  K  Kr#   c                 D    t        j                  | |||||||||	|
||      S )a  DatasetIONumPy(Dataset ds, int bWrite, double xoff, double yoff, double xsize, double ysize, PyArrayObject * psArray, GDALDataType buf_type, GDALRIOResampleAlg resample_alg, GDALProgressFunc callback=0, void * callback_data=None, bool binterleave=True, int band_list=0) -> CPLErr)r   DatasetIONumPy)dsr   r   r   r   r   r   r   r   r   r   r   	band_lists                r   r   r      sC    %%b&$eUGU]_kmu  xE  GR  T]  ^  ^r#   c                 6    t        j                  | |||||      S )zMDArrayIONumPy(bool bWrite, GDALMDArrayHS * mdarray, PyArrayObject * psArray, int nDims1, int nDims3, GDALExtendedDataTypeHS * buffer_datatype) -> CPLErr)r   MDArrayIONumPy)r   mdarrayr   nDims1nDims3buffer_datatypes         r   r   r     s    %%fgwP_``r#   c                 4    t        j                  | ||||      S )zAddNumpyArrayToDict(PyObject * dict, ArrowSchema const * schemaField, ArrowArray const * arrayField, std::string const & osPrefix, PyObject * pointerArrayKeeper) -> bool)r   AddNumpyArrayToDict)dictschemaField
arrayFieldosPrefixpointerArrayKeepers        r   r   r     s    **4j(Tfggr#   c                 0    t        j                  | ||      S )zw_RecordBatchAsNumpy(VoidPtrAsLong recordBatchPtr, VoidPtrAsLong schemaPtr, PyObject * pointerArrayKeeper) -> PyObject *)r   _RecordBatchAsNumpy)recordBatchPtr	schemaPtrr   s      r   r   r   
  s    **>9FXYYr#   c                 ,    t        j                  |       S )z)VirtualMemGetArray(VirtualMem virtualmem))r   VirtualMemGetArray)
virtualmems    r   r   r     s    ))*55r#   c                 2    t        j                  | |||      S )zlRATValuesIONumPyWrite(RasterAttributeTable poRAT, int nField, int nStart, PyArrayObject * psArray) -> CPLErr)r   RATValuesIONumPyWrite)poRATnFieldnStartr   s       r   r   r     s    ,,UFFGLLr#   c                 2    t        j                  | |||      S )zcRATValuesIONumPyRead(RasterAttributeTable poRAT, int nField, int nStart, int nLength) -> PyObject *)r   RATValuesIONumPyRead)r   r   r   nLengths       r   r   r     s    ++E667KKr#   )	gdalconstr   c                     |j                         }|dk(  rd}n|dk(  rd}nt        d      t        | |      }|=|;t        |      j                  dk(  rt        j                  |      }|t        ||       |S )Nr   TpixelF"Interleave should be band or pixelstr)lower
ValueErrorr   r   r   r:   OpenCopyDatasetInfo)arrayprototype_ds
interleaver   s       r   	OpenArrayr   0  s    !!#JV
	w	
=>>	z	*B	~,2&&%/99\2L#L"-Ir#   c                    t        | t        j                  t        f      rI| t        j                  k(  rt
        j                  S t        j                         D ]  \  }}|| k(  s|c S  y 	 t        |    S # t        $ r Y y w xY wr-   )
r   numpydtyper   	complex64r   GDT_CFloat32codesitemsKeyError)codekeyr    s      r   	flip_coder   E  sz    $d+, 5??")))++- 	JC}
	 	; 		s   +A4 4	B ?B c                 n    t        | t        j                  t        f      st	        d      t        |       S )NzInput must be a type)r   r   r   r   	TypeErrorr   )numeric_types    r   NumericTypeCodeToGDALTypeCoder   V  s,    lU[[$$78.//\""r#   c                     t        |       S r-   )r   )	gdal_codes    r   GDALTypeCodeToNumericTypeCoder   [  s    Yr#   c                  f    t        j                         rt        t        j                               y r-   )r:   rT   RuntimeErrorGetLastErrorMsgr$   r#   r   _RaiseExceptionr   ^  s'    4//122 r#   c                     t        j                  |       }|&t        d| z   dz   t        j                         z         t	        ||||||||||	|
||      S )NzCan't open z

)	buf_xsize	buf_ysizer   r   r   r   r   r   )r:   r   r   r   DatasetReadAsArray)filenamer   r   r   r   r   r   r   r   r   r   r   r   r   s                 r   LoadFiler   b  sg    
 
8	B	zx/6t7K7K7MMNNb$eU(1YQY+7'/})3(13 3r#   c                     t        j                  |      }|t        d|z         |j                  |t	        | ||            S )NzCan't find driver )r:   GetDriverByNamer   
CreateCopyr   )	src_arrayr   format	prototyper   drivers         r   	SaveArrayr   r  sD    !!&)F~-f455XyIz'RSSr#   c                    | | S t        | d      rdt        | d      r| j                         rt        |       S t        | d      st        |       S t        |       }|t        |      k(  rt        |      }|S t        | d      rt        |       S | S )znConverts an object with a __int__ or __float__ method to the
       corresponding primitive type, or return x.__int__
is_integer	__float__)r   r   intfloat)r?   rets     r   _to_primitive_typer   y  s     	yq)1l#q6MK(q6M(Cc#h#hJ	K	 QxHr#   c                 >   || j                   }|| j                  }t        |      }t        |      }t        |      }t        |      }t        |      }t        |      }|"t        t	        d| j
                  dz               }|j                         }|dk(  r	d}d}d}d}n|dk(  r	d}d}d}d}nt        d	      t        |      }|dk(  ry|dk(  r)t        | j                  |d         |||||||||	|
|
      S |5||}||}|c| j                  |d         j                  }t	        d|      D ]6  }||   }|| j                  |      j                  k7  s't        j                  }8 t        |      }|!t        j                  }t        j                   }nt#        |      }|t        j$                  k(  rX| j                  d      }|j'                  d       |j)                  dd      dk(  rt        j*                  }|j'                  d       |r|||fn|||f}t        j,                  ||      }nt        |j.                        dk7  rt        d      |j.                  |   }|j.                  |   }|||k7  rt        d      |||k7  rt        d      |j.                  |   |k7  rt        d||fz        t#        |j0                  j2                        }|st        d      |||k7  rt        d      |}t5        | d|||||||	|
|||      dk7  rt7                y|S )zPure python implementation of reading a chunk of a GDAL file
    into a numpy array.  Used by the gdal.Dataset.ReadAsArray method.Nr   r   T   r   r   Fr   )r   r   r   buf_objr   r   r   	PIXELTYPEIMAGE_STRUCTURE
SIGNEDBYTEr      zArray should have 3 dimensions3Specified buf_xsize not consistent with array shape3Specified buf_ysize not consistent with array shape9Dimension %d of array should have size %d to store bands)0array does not have corresponding GDAL data type1Specified buf_type not consistent with array type)RasterXSizeRasterYSizer   listrangeRasterCountr   r   lenBandReadAsArrayGetRasterBandDataTyper   GDT_Float32r   r   float32r   GDT_Byte!_EnablePixelTypeSignedByteWarningGetMetadataItemint8emptyshaper   r   r   r   )r   r   r   	win_xsize	win_ysizer   r   r   r   r   r   r   r   r   xdimydimbanddimnbandsidx
band_indextypecoder   	buf_shapeshape_buf_xsizeshape_buf_ysizedatatypes                             r   r   r     sj    NN	NN	d#Dd#D"9-I"9-I"9-I"9-Iq"..1"456	!!#JV
	w	
=>>^F{{r//	!=tT9V_)2iRZ'.,8(0-:< 	< !I!I''	!5>>HQ' 5&s^
r//
;DDD(44H5
 1: ,,H}}H4X>Hy)))##A&D2259##K1BC|S ::22486@VY	2yR[]cFd	++ix8 w}}"=>>!---!--- Y/%ARSS Y/%ARSS==!V+X\cek[llmm01C1CDOPPH$8PQQb!T4Ixx )-012 	Nr#   c	                    t        |      }t        |      }|"t        t        d| j                  dz               }|j	                         }|dk(  r	d}d}	d}
d}n|dk(  r	d}d}	d}
d}nt        d      t        |      dk(  r|0t        |j                        dk7  r#t        |j                        d	k7  rt        d
      t        |j                        d	k(  r%|j                  |   dk7  rt        d|z        ||   }t        | j                  |d         ||||||      S |t        |j                        d	k7  rt        d      |j                  |	   }|j                  |
   }||z   | j                  kD  s||z   | j                  kD  rt        d      |j                  |   t        |      k7  rt        d|t        |      fz        t        |j                  j                        }|sTt        j                   dd       |j#                  t$        j&                        }t        |j                  j                        }|st        d      t)        | d|||||||||||      }|dk7  r
t+                |S )zPure python implementation of writing a chunk of a GDAL file
    from a numpy array.  Used by the gdal.Dataset.WriteArray method.r   r   Tr   r   r   Fr   r   zexpected array of dim 2 or 3z)expected size of dimension %d should be 1)r   r   r   r   r   zexpected array of dim 31array larger than output file, or offset off edger   rh   force array to float64r   )r   r   r   r  r   r   r  r  BandWriteArrayr  r   r   r   r   r   r:   Debugastyper   float64r   r   )r   r   r   r   r   r   r   r   r   r  r  r  r   r   r  r   s                   r   DatasetWriteArrayr"    sf    d#Dd#Dq"..1"456	!!#JV
	w	
=>>
9~=S-2s5;;7G17L;<<u{{q {{7#q( !Lw!VWW'NEb..y|<##'d'/}N 	N
 }EKK(A-233KKEKKEt|bnn$r~~(ELMM{{7s9~-TX_adenaoWppqq,U[[-=-=>H 

<!9:U]]+01A1ABKLL
QdE5,-#Y0C axJr#   c                    || j                   }|| j                  }t        |      }t        |      }t        |      }t        |      }t        |      }t        |      }|||}||}|| j                  }t	        |      }|!t
        j                  }t        j                  }nt        |      }|t
        j                  k(  rG| j                  d       | j                  dd      dk(  rt        j                  }| j                  d       t        j                  ||g|      }nt        |j                         dvrt#        d	      t        |j                         d
k(  r|j                   d   }|j                   d   }n;|j                   d   dk7  rt#        d      |j                   d
   }|j                   d   }|||k7  rt#        d      |||k7  rt#        d      t        |j$                  j&                        }|st#        d      |||k7  rt#        d      |}t)        | d|||||||	|
|      dk7  rt+                y|S )zPure python implementation of reading a chunk of a GDAL file
    into a numpy array.  Used by the gdal.Band.ReadAsArray method.NFr   r   r   Tr   )r   r   z"expected array of dimension 2 or 3r   r   r   z,expected size of first dimension should be 0r   r   r   r   )XSizeYSizer   r  r   r   r  r   r  r   r  r	  r
  r  r  r  r  r   r   r   r   r   )r   r   r   r  r  r   r   r   r   r   r   r   r  r  r  r  s                   r   r  r  >  sC    JJ	JJ	d#Dd#D"9-I"9-I"9-I"9-I!I!I}}H0: ,,H}}H4X>Hy)))2259##K1BC|S ::2248++y)4HE w}}V+ABBw}}"%mmA.O%mmA.O}}Q1$ !OPP%mmA.O%mmA.O Y/%ARSS Y/%ARSS01C1CDOPPH$8PQQq$i (L(MSVWXNr#   c                 b   |t        |j                        dk7  rt        d      t        |      }t        |      }|j                  d   }|j                  d   }||z   | j                  kD  s||z   | j
                  kD  rt        d      t        |j                  j                        }	|	sTt        j                  dd       |j                  t        j                        }t        |j                  j                        }	|	st        d      t        | d||||||	|||      }
|
dk7  r
t                |
S )	z~Pure python implementation of writing a chunk of a GDAL file
    from a numpy array.  Used by the gdal.Band.WriteArray method.r   zexpected array of dim 2r   r   r  rh   r  r   )r  r  r   r   r$  r%  r   r   r   r:   r  r   r   r!  r   r   )r   r   r   r   r   r   r   r   r   r  r   s              r   r  r    s    }EKK(A-233d#Dd#DKKNEKKNEt|djj EDL4::$=LMM,U[[-=-=>H 

<!9:U]]+01A1ABKLL
D!T4"HlHmUC
axJr#   c                 l   | j                         }|t        j                  k(  rt        j                  | fS |t        j
                  k(  r| j                         }t        |      }|At        j                  }t        j                  j                  t        j                        } || fS t        j                  j                  t        |            } || fS |t        j                  k(  sJ g }g }g }| j                         D ]  }|j                  |j!                                t#        |j%                               \  }}||j%                         k7  rt'        d      |j                  |       |j                  |j)                                 t        j*                  |||| j-                         d      | fS )NzIncompatible datatype)namesformatsoffsetsitemsize)GetClassr:   GEDTC_STRINGr   bytes_GEDTC_NUMERICGetNumericDataTyper   r  ExtendedDataTypeCreater  r   GEDTC_COMPOUNDGetComponentsappendGetName _ExtendedDataTypeToNumPyDataTypeGetTyper   	GetOffsetr   GetSize)	dtklassr   r  r(  r)  r*  compsubdts	            r   r7  r7    s|   KKME!!!||R"""((*0:}}H&&--d.>.>?B | &&--.KH.UVB|D'''''EGG  " )T\\^$:4<<>J%DLLN"344x t~~'() ;;#*#*$&JJL2 3 577 7r#   c                 "    t        |       \  }}|S r-   )r7  )r;  r  _s      r   ExtendedDataTypeToNumPyDataTyperA    s    226KHaOr#   c                 
   |sdg| j                         z  }|s+| j                         D cg c]  }|j                          }}|sdg| j                         z  }|8|s| j                         }t	        |      \  }}t        j                  ||      }nKt        |j                  j                        }|st        d      t        j                  j                  |      }t        d| ||||      }	|	dk7  r
t                |S c c}w )Nr   r   r   r   F)GetDimensionCountGetDimensionsr:  GetDataTyper7  r   r  r   r   r   r   r:   r1  r2  r   r   )
r   array_start_idxcount
array_stepr   r   dimr  r  r   s
             r   MDArrayReadAsArrayrJ    s     # 9 9 ;;+2+@+@+BDC#++-DDS74466
%113O$D_$U!/++e8401C1CDOPP//66x@
/:
_C
axN' Es   D c                 2   |sdg| j                         z  }|sdg| j                         z  }| j                         }t        |      }|j                  |k7  rt	        |j                  j
                        }|sTt        j                  dd       |j                  t        j                        }t	        |j                  j
                        }|st        d      t        j                  j                  |      }t        d| ||||      }|dk7  r
t                |S )Nr   r   rh   r  r   T)rC  rE  rA  r   r   r   r:   r  r   r   r!  r   r1  r2  r   r   )r   r   rF  rH  r   r  r  r   s           r   MDArrayWriteArrayrL    s     # 9 9 ;;S74466
))+O.?H{{h01A1AB JJ|%=>LL/E4U[[5E5EFHOPP//66x@
w
O
\C
axJr#   c                    |t        d      t        |t        j                        st        j                  |      }|j
                  dk7  rt        d      ||j                  z   | j                         kD  rt        d      t        j                  |j                  t        j                        r |j                  t        j                        }nt        j                  |j                  t        j                        r |j                  t        j                        }nOt        j                  |j                  t        j                        r|j                  t               }nt        d      t#        | |||      }|dk7  r
t%                |S )z
    Pure Python implementation of writing a chunk of the RAT
    from a numpy array. Type of array is coerced to one of the types
    (int, double, string) supported. Called from RasterAttributeTable.WriteArray
    zExpected array of dim 1r   z1Array too big to fit into RAT from start positionz9Array not of a supported type (integer, double or string)r   )r   r   r   ndarrayr   ndimsizeGetRowCount
issubdtyper   integerr   int32floatingdouble	characterbytesr   r   )ratr   fieldstartr   s        r   RATWriteArrayr\    s    }233 eU]]+E"zzQ233

coo//LMMU]]3 U[[)			%++u~~	6U\\*			%++u	7U#TUU
UE5
9C
axJr#   c                 d    || j                         |z
  }t        | |||      }|
t                |S )z
    Pure Python implementation of reading a chunk of the RAT
    into a numpy array. Called from RasterAttributeTable.ReadAsArray
    )rQ  r   r   )rY  rZ  r[  lengthr   s        r   RATReadArrayr_  1  s:    
 ~"U*
sE5&
9C
{Jr#   c           	      J   |j                  | j                                | j                         }|dk7  r|j                  | j	                                |dk(  r|dk(  r|j                  |       y	|d   |d   |d   |d   |d   |d   g}|d   ||d   z  z   ||d   z  z   |d<   |d   ||d   z  z   ||d   z  z   |d<   |j                  |d   |d   |d   |d   |d   |d   f       y	| j                         dkD  r|dk(  r4|dk(  r/|j                  | j                         | j                                y	| j                         }g }|D ]  }t        j                         }	|j                  |	_        |j                  |	_        |j                  |	_        |j                  |z
  |	_        |j                   |z
  |	_        |j"                  |	_        |j$                  |	_        |j'                  |	        	 |j                  || j                                y	y	#  t)        d       Y y	xY w)
ac  
    Copy georeferencing information and metadata from one dataset to another.
    src: input dataset
    dst: output dataset - It can be a ROI -
    xoff, yoff:  dst's offset with respect to src in pixel/line.

    Notes: Destination dataset must have update access.  Certain formats
           do not support creation of geotransforms and/or gcps.

    )r   r   r   r   r   r   r   r   r   r         zFailed to set GCPsN)SetMetadataGetMetadataGetGeoTransformSetProjectionGetProjectionRefSetGeoTransformGetGCPCountSetGCPsGetGCPsGetGCPProjectionr:   GCPGCPXGCPYGCPZGCPPixelGCPLineInfoIdr5  print)
srcdstr   r   gtngtgcpsnew_gcpsgcpngcps
             r   r   r   >  s    OOCOO%&
 
			B	#..0119#B ? a5"Q%A1r!ube<CUT"Q%Z'$r!u*4CFUT"Q%Z'$r!u*4CFQQQQQQ PQ8 3 
	Q	AIDAIKKs';';'=>, ) ;;=DH 	&xxzHH	HH	HH	 #t 3"{{T1HH	&&%	&Hc&:&:&<=
 	*+s   1 H H")NN)r   N)r   NTr   )Nr   )GTiffNr   )NNNNN)r   )r   r   )]sysr   _swig_python_version_info__package__r   r   r   builtinsr   rj   r   r%   r*   r3   r   r5   r:   objectr<   VirtualMem_swigregisterrT   rV   rX   r[   r]   r_   ra   ry   r|   r~   TermProgressr   r   r   r   r   r   r   r   r   r   r   r   osgeor   AllRegisterr  uint8GDT_Int8r  
GDT_UInt16uint16	GDT_Int16int16
GDT_UInt32uint32	GDT_Int32rT  
GDT_UInt64uint64	GDT_Int64int64r  r  GDT_Float64r!  
GDT_CInt16r   
GDT_CInt32r   GDT_CFloat64
complex128r   r   r   r   r   r   GRIORA_NearestNeighbourr   r   r   r   r"  r  r  r7  rA  rJ  rL  r\  r_  r   r$   r#   r   <module>r     s   :#/"[
L$ L
 O O& $ # #J /*-1(,<:J6 :J~<@H ''<?1K^ahZ6ML       			U[[			UZZ			u||			ekk			u||			ekk			u||			ekk									u			u			%//			!1!1	3 *"#
 3 ATtd66$6	3 T& !"TTSW!%$($@$@ $DV!%	gT '(a $!'#'#?#?#4	EP  !qDD"dT4!%!=!=!FP &'Q $ < < "H7B
 +/ $%)*."&> +/%)<$L7]  s   J3 3	K ?K 