
    njbN              $       &   S SK r S SKrS SKJrJr  S SKJr  S SKJrJ	r	J
r
Jr  S SKrS SKJrJrJr  S SKJr  S SKJrJr  S SKJr  S S	KJrJr  S S
KJr  S SKJrJ r J!r!J"r"J#r#J$r$  S SK%J&r&J'r'J(r(J)r)J*r*   " S S\5      r+ " S S\5      r,\\\RZ                  \+\ 4      r.SSSSSSSSSSS\R^                  S4S\&S\S\S\.S\\   S\\0   S\\1   S\\	\1      S\2S\2S\\3   S\2S \S!\S"\2S#\
\Rh                  \Rh                  \Rh                  4   4 S$ jjr5SS\R^                  S4S\&S\S\S\\0   S\\	\1      S%\\,   4S& jjr6S'\7S(\S)\S*\2S+\2S,\24S- jr8 " S. S/\5      r9\ Rt                  4S0 jr;\<S1:X  a#  \ Rz                  " \;" \ Rt                  5      5        gg)2    N)Enumauto)Real)OptionalSequenceTupleUnion)gdal	gdalconstosr)BandRasterIONumPy)	ArrayLikeArrayOrScalarLike)is_path_like)GDALArgumentParser
GDALScript))GDALTypeCodeAndNumericTypeCodeFromDataSet)OAMS_AXIS_ORDERAnySRSget_axis_order_from_gis_orderget_srsget_transformtransform_points)PathOrDSget_band_nums	get_bandsget_scales_and_offsetsopen_dsc                   >    \ rS rSr\" 5       r\" 5       r\" 5       rSrg)LocationInfoSRS?    N)	__name__
__module____qualname____firstlineno__r   	PixelLineSameAsDS_SRSSameAsDS_SRS_GeogCS__static_attributes__r"       `/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/osgeo_utils/samples/gdallocationinfo.pyr    r    ?   s    I6L&r+   r    c                   h    \ rS rSr\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r	\" 5       r
Srg)LocationInfoOutputE   r"   N)r#   r$   r%   r&   r   PixelLineValPixelLineValVerboseValOnlyXMLLifOnlyQuietr*   r"   r+   r,   r.   r.   E   s-    6L&fG
&CfGFEr+   r.   FTg      filename_or_dsxysrs
axis_orderopen_optionsovr_idx	band_numsinline_xy_replacementreturn_ovr_pixel_linetransform_round_digitsallow_xy_outside_extentpixel_offsetline_offset
quiet_modereturnc                 	   [        XS9n[        U 5      (       a  U OSnUc  [        SU S35      e[        U[        R
                  5      (       d  U/n[        U[        R
                  5      (       d  U/n[        U5      [        U5      :w  a#  [        S[        U5       S[        U5       35      e[        U5      n[        R                  n[        U[        R                  5      (       a  [        U[        R                  5      (       d,  [        R                  " UUS9n[        R                  " UUS9nSnUc  [        R                  nU[        R                  :w  Ga>  U[        R                  :w  a  UR                  5       nS n[        U[        R                   5      (       a  UnO:U[        R"                  :X  a  UR%                  5       nO	['        X4S	9n[)        UU5      nUbV  U(       d"  UR+                  5       nUR+                  5       nSn[-        UX5        U
b  UR/                  XS
9  UR/                  XS
9  UR1                  5       n[2        R4                  " U5      nUc  [        S5      eUS   US   U-  -   US   U-  -   US   US   U-  -   US   U-  -   p!SnUR6                  UR8                  nn[;        UXvS9nUS   R<                  US   R>                  nnU(       a
  UU-  UU-  4OSu  nn[        U5      n U U4n![A        U5      u    n"[        RB                  " U!U"S9n#U(       + =(       d    U(       + n$U$(       a  [        RD                  " US:  5      (       dZ  [        RD                  " UU:  5      (       d<  [        RD                  " US:  5      (       d  [        RD                  " UU:  5      (       a&  Sn%U(       d  [        U%5      eU(       d  [G        U%5        US:X  a  Un&OU	(       a  UU-  nUn&OUU-  n&US:X  a  Un'OU	(       a  UU-  nUn'OUU-  n'S=n(n)[A        U5      u  n*n+[        RB                  " U)U(/U+S9n,[I        [K        U&U'5      5       HM  u  n-u  n.n/[I        U5       H5  u  n0n1[M        U1SU.S-
  U/S-
  SSU,U*US S 5      S:X  d  M'  U,S   S   U#U0   U-'   M7     MO     [O        U5      u  n2n3n4U2(       a0  [I        [K        U3U45      5       H  u  n0u  n5n6U#U0   U5-  U6-   U#U0'   M     XU#4$ )Nr;    zCould not open .zlen(x)=z should be the same as len(y)=)dtypeT)r:   )outzFailed InvGeoTransform()r                  )r<   )rL   rL   )shaperJ   z-Passed coordinates are not in dataset extent!g      ?)(r   r   	Exception
isinstancer   __args__lennpfloat64ndarrayarrayr    r'   r(   GetSpatialRefr   CoordinateTransformationr)   CloneGeogCSr   r   copyr   roundGetGeoTransformr
   InvGeoTransformRasterXSizeRasterYSizer   XSizeYSizer   emptyanyprint	enumeratezipr   r   )7r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   resample_algrD   dsfilenamepoint_countrJ   ds_srsct
points_srsgeotransforminv_geotransformxsizeysizebands	ovr_xsize	ovr_ysize
pixel_fact	line_fact	bnd_countrQ   np_dtyperesultscheck_outsidemsgpixels_qlines_q	buf_xsize	buf_ysizebuf_typetypecodebuf_objidxpixellinebnd_idxband	is_scaledscalesoffsetsscaleoffsets7                                                          r,   gdallocationinfor   S   s   $ 
	;B!-n!=!=~2H	z/(1566a++,,Ca++,,C
1vQ'#a&)GAxPQQa&KJJEa$$Jq"**,E,EHHQe$HHQe$ $
{'' o'''/...%%'FB#s;;<</===!'!3!3!5J!(!DJ":v6~,AA,0) Q*)5GG2G:GG2G: ))+//=#677 Q"21"5"99<LQ<ORS<SSQ"21"5"99<LQ<ORS<SS  !%>>2>>5Eb)5E 8>>58>>yI29U	I-.v J	 E
I$EB2FHhhhU(3G"NA*A&AM
q1uU
++rvva!e}}qEz@R@R=&C. #JQ		Zz>A~		Yi-I	B2FHhhh	9-X>G'Hg(>?]eT&u-MGT!CK3J   )0
1 %# . @( "8!>Ivw(1#fg2F(G$G_eV&w/%7&@GG )H =r+   output_modec                    Uc  [         R                  nU[         R                  [         R                  4;   a  [	        SU S35      eU[         R                  :H  nU[         R
                  [         R                  [         R                  4;   n	U	(       + n
[        XS9n[        X5      n[        SUUUUUU
US.UD6u  pnUR                  UR                  pU[        R                  :H  nU	(       GaR  U[         R                  :X  a  [        S5        [!        [#        X5      5       GH  u  nu  nnU(       d  US:  d  UU:  d  US:  d  UU:  a  [        SU SU S	35        M=  U(       a  [%        U5      [%        U5      nnU[         R                  :X  a  [        S
U SU S35        [!        U5       H  u  nnUU   U   nU[         R
                  :X  a  [        U5        M/  U[         R                  :X  a  [        U SU SU 35        MX  U[         R                  :X  d  Mn  [        SU S35        [        SU 35        M     GM     U$ )NzSorry, output mode z5 is not implemented yet. you may use the c++ version.rG   )r6   r7   r8   r=   rj   r>   rD   zReport:r   z	Location  z is off this file!z  Location: (zP,zL)z  Band :z    Value: r"   )r.   r5   r3   r4   rR   r2   r0   r1   r   r   r   ra   rb   r
   GRIORA_NearestNeighbourrg   rh   ri   int)r6   r7   r8   r;   r=   rj   r   kwargsrD   
print_moder>   rk   r|   rs   rt   is_nearest_neighbourr   r   r   r   band_numvals                         r,   gdallocationinfo_utilr      s7    (..)--/A/I/IJJ!+.cd
 	
  2 8 88J""''..! J
 !+N		;Bb,I$ 	

!3	 	MA' >>2>>5'4+G+GG,@@@)"+CI"6C%AIE>!85=	%$/ABC'"%e*c$i4E"4"H"HHM%4&;<)29)=%GX!'*3/C"&8&@&@@c
$(:(G(GGqau56$(:(N(NNz34C512 *> #70 Nr+   rl   	longitudelatitudecoordtype_georefprint_xyprint_valuesc                    [         R                  " U [         R                  5      nUc  [        SU -  5      eU(       a  UnUnOn[        R
                  " 5       n	U	R                  UR                  5       5        U	R                  5       n
[        R                  " X5      nUR                  X5      u  pxnUR                  5       n[         R                  " U5      u  p[        US   US   U-  -   US   U-  -   5      n[        US   US   U-  -   US   U-  -   5      nU(       a  [        SUU4-  5        US:  d&  UUR                  :  d  US:  d  UUR                   :  a  [        S	5      eUR#                  UUSS5      nU(       aF  [%        UR&                  5      S:X  a  [        US   S   5        U$ U H  n[        US   S   5        M     U$ )
zk
val_at_coord is a simplified version of gdallocationinfo. It accepts a single point and has less options.
zCannot open %sr   rL   rM   rN   rO   rP   z
x=%d, y=%dz,Passed coordinates are not in dataset extent)r
   OpenGA_ReadOnlyrR   r   SpatialReferenceImportFromWktGetProjectionr\   r[   TransformPointr_   r`   r   rg   ra   rb   ReadAsArrayrU   rQ   )rl   r   r   r   r   r   rk   XYr9   
srsLatLongro   heightrq   successrr   r7   r8   resr   s                       r,   val_at_coordr   )  s    
8T--	.B	z(8344 ""$"**,-__&
))*:**9?v %%'L"&"6"6|"DWQ"21"5"99<LQ<ORS<SSTAQ"21"5"99<LQ<ORS<SSTAlaV#$1uR^^#q1uR^^0CFGG
..Aq!
$Csyy>Q#a&)
 J c!fQi   Jr+   c                   J   ^  \ rS rSrU 4S jrS\4S jrS\4S jrS r	Sr
U =r$ )GDALLocationInfoi]  c                 t   > [         TU ]  5         SU l        [        R                  " S5      U l        S U l        g )NzRaster query toolz            The gdallocationinfo utility provide a mechanism to query information about a pixel given its location
            in one of a variety of coordinate systems. Several reporting options are provided.)super__init__titletextwrapdedentdescriptioninteractive_mode)self	__class__s    r,   r   GDALLocationInfo.__init__^  s6    (
#??b

 !%r+   rE   c           	         U R                   nUR                  5       nUR                  SSSSS9  UR                  SSSSS9  UR                  S	S
SSS9  UR                  SSSSS9  UR                  SSSSS9  UR                  5       nUR                  SSS[        SS9  UR                  SSSSS9  UR                  SSSSS9  UR                  SSSSS9  UR                  S S!S"S#S9  UR                  S$S%SS&S9  UR                  S'S(S)[        S*S+S,9  UR                  S-S.S/[        S0S9  UR                  S1S2S3S4/[        S S5S69  UR                  S7S8S9S:S*S;9  UR                  S<S=[        S>S?9  UR                  S@SASB[
        SCSD9  U$ )ENz-xmlxml
store_truezGThe output report will be XML formatted for convenient post processing.)destactionhelpz-lifonlylifonlyzThe only output is filenames production from the LocationInfo request against the database (i.e. for identifying impacted file from VRT).z-valonlyvalonlyzXThe only output is the pixel values of the selected pixel on each of the selected bands.z-plbplbzmThe output will be a series of lines in the form of Pixel,Line,band0,band1... for each of the selected bands.z-quietquietzNo output will be printed.z-l_srsr9   srs_defz1The coordinate system of the input x, y location.)r   metavartyper   z-geolocgeoloczIIndicates input x,y points are in the georeferencing system of the image.z	-llgeolocllgeoloczmIndicates input x,y points are in the long, lat (geographic) based on the georeferencing system of the image.z-wgs84wgs84z/Indicates input x,y points are WGS84 long, lat.z-extent_strictrA   store_falsezzIf set, input points outside the raster extent will raise an exception, otherwise a warning will be issued (unless quiet).z-interprj   zXIf set, a Bilinear interpolation would be used, otherwise the NearestNeighbour sampling.z-br=   r   +zXSelects a band to query. Multiple bands can be listed. By default all bands are queried.)r   r   r   nargsr   z	-overviewr<   overview_levelzQuery the (overview_level)th overview (overview_level=1 is the 1st overview), instead of the base band. Note that the x,y location (if the coordinate system is pixel/line) must still be given with respect to the base band.z-axis_orderr:   gis	authorityzSX, Y Axis order: Traditional GIS, Authority complaint or otherwise utility default.)r   choicesr   defaultr   z-oor;   z
NAME=VALUEz&Dataset open option (format specific).)r   r   r   r   r6   rl   z'The source GDAL raster datasource name.)r   r   r   xyzx y*zseries of X Y pairs of location of target pixel. By default the coordinate system is pixel/line unless -l_srs, -wgs84 or -geoloc supplied.)r   r   r   r   )parseradd_mutually_exclusive_groupadd_argumentstrr   float)r   argvr   groups       r,   
get_parserGDALLocationInfo.get_parserh  s   335Z	 	 	
 	J	 	 	
 	k	 	 	
 	.	 	 	
 	-	 	 	
 335D 	 	
 	\	 	 	
 	?	 	 	
 	B	 	 	
 	* A	 	 	
 	k	 	 	
 	k 	 	
 	$M 	 	
 	K(f 	 	
 	 9 	 	
 	:	 	 	
 	G 	 	
 r+   c                    [        US   5      S:*  U l        U R                  (       dD  [        R                  " US   SS S2   5      US'   [        R                  " US   SS S2   5      US'   US   (       a  [        R
                  US'   O-US	   (       a  [        R                  US'   OUS
   (       a  SUS'   US   n[        U[        5      (       a  O[        U[        5      (       a  UR                  5       S:H  nONUc%  US   S L=(       a    US   [        R
                  :g  nO&[        U[        5      (       a  UnO[        SU 35      e[        U5      nX!S'   US   (       a  [        R                  US'   OUS   (       a  [        R                   US'   OmUS   (       a  [        R"                  US'   OOUS   (       a  [        R$                  US'   O1US   (       a  [        R&                  US'   O[        R(                  US'   US   (       a  [*        R,                  O[*        R.                  US'   US	 US	 US		 US
	 US	 US	 US	 US	 US	 U$ )Nr   rL   r   rM   r7   r8   r   r9   r   r   i  r:   r   zUnknown axis order r   r   r   r   r   r   rj   )rU   r   rV   rY   r    r(   r)   rS   r   r   lowerboolrR   r   r.   r3   r4   r2   r0   r5   r1   r
   GRIORA_Bilinearr   )r   r   r:   	gis_orders       r,   augment_kwargsGDALLocationInfo.augment_kwargs  s9    #F4L 1Q 6$$((6$<1#56F3K((6$<1#56F3K(+88F5MJ+??F5MG_ F5ML)
j/22*c**&,,.%7	#"5M5 5M_%A%AA  J--&	"5j\ BCC6yAJ)|%=$6$:$:F=!I$6$>$>F=!I$6$>$>F=!E]$6$C$CF=!G_$6$<$<F=!$6$J$JF=! n%   -- 	~ 4L8:7O5M995M7Or+   c                 8   U R                   (       a  US   [        R                  :H  n [        SU(       a  SOS S35      nUR	                  5       R                  SS5      n[        US   5      [        US   5      sUS	'   US
'   [        S0 UD6  Mh  [        S0 UD6$ )Nr9   zEnter z
pixel linezX Yz. values separated by space, and press Return.
r   rL   r   r7   r8   r"   )r   r    r'   inputstripsplitr   r   )r   r   is_pixel_liner   s       r,   doitGDALLocationInfo.doit.  s      "5M_-F-FFM]\F GE F XXZ%%c1-+0A<r!u(sVC[%//  )2622r+   )r   r   r   )r#   r$   r%   r&   r   r   r   dictr   r   r*   __classcell__)r   s   @r,   r   r   ]  s/    %E"4 EN= =~3 3r+   r   c                 4    [        5       R                  U 5      $ )N)r   main)r   s    r,   r   r   =  s    ""4((r+   __main__)>sysr   enumr   r   numbersr   typingr   r   r   r	   numpyrV   osgeor
   r   r   osgeo.gdal_arrayr    osgeo_utils.auxiliary.array_utilr   r   osgeo_utils.auxiliary.baser   #osgeo_utils.auxiliary.gdal_argparser   r    osgeo_utils.auxiliary.numpy_utilr   osgeo_utils.auxiliary.osr_utilr   r   r   r   r   r   osgeo_utils.auxiliary.utilr   r   r   r   r   r    r.   r[   CoordinateTransformationOrSRSr   r   r   r   r   rX   r   r   r   r   r   r   r   r#   exitr"   r+   r,   <module>r     s~  @     3 3  & & . I 3 N V  !d !  !)	#
&
&
?@!  *.,0#'!)-"'"'.2$(22!MMM M 
'	M
 )M 4.M c]M &M  M  M %UOM "M M M  !M" 2::rzz2::-.#Mh $()-2204CCC C 4.	C
 &C ,-CL111 1 	1
 1 1h]3z ]3@ hh ) zHHT#((^ r+   