
    njM                         S SK r S SKJrJr  S rSrSrS rSS jrS r	S\SSSSSSSSSSS4S	 jr
\ R                  4S
 jr\S:X  a#  \ R                  " \" \ R                  5      5        gg)    N)gdalogr      c                     [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S	5        [        S
5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        g)Nz~Usage: ogrupdate.py -src name -dst name [-srclayer name] [-dstlayer name] [-matchfield name] [-update_only | -append_new_only]z{             [-compare_before_update] [-preserve_fid] [-select field_list] [-dry_run] [-progress] [-skip_failures] [-quiet] zYUpdate a target datasource with the features of a source datasource. Contrary to ogr2ogr,zcthis script tries to match features, based on FID or field value equality, between the datasources,zHto decide whether to create a new feature, or to update an existing one.zThere are 3 modes :za(default):        *update* features of the target layer that match features from the source layerzv                  and *append* new features from the source layer that do not match any feature from the target layer.zb-update_only:     *update* features of the target layer that match features from the source layer;zd                  do *not append* new features if a source feature has no match in the target layer.zi-append_new_only: do *not update* features of the target layer that match features from the source layer;zr                  *append* new features from the source layer that do not match any feature from the target layer.zOther options : zS * If -matchfield is *not* specified, the match criterion is based on FID equality.zl * When -compare_before_update is specified, a test on all fields of the matching source and target featureszZ   will be done before determining if an update of the target feature is really necessary.z\ * When -preserve_fid is specified, new features that are appended will try to reuse the FIDzP   of the source feature. Note: not all drivers do actually honour that request.zo * When -select is specified, only the list of fields specified will be updated. This option is only compatiblez   with -update_only.r   )print     Y/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/osgeo_utils/samples/ogrupdate.pyUsager   ,   s   	 	I 
 	F 
"I	c 
m 

TU	"I	
 	k 
 	A 
l 
n 
s 
| 
"I	
	] 
v 
d 
f 
Z 
y 

!"	"Ir   c                 P
   S nS nS nS nS nSnSn	[         n
SnSnS nSnU (       d
  [        5       $ SnU[        U 5      :  Ga  X   nUS:X  a  US-   [        U 5      :  a  US-   nX   nGOqUS:X  a  US-   [        U 5      :  a  US-   nX   nGONUS:X  a  US-   [        U 5      :  a  US-   nX   nGO+US:X  a  US-   [        U 5      :  a  US-   nX   nGOUS:X  a  US-   [        U 5      :  a
  US-   nX   nOUS	:X  a  [        n
OUS
:X  a  [        n
OUS:X  a  SnOUS:X  a  Sn	OUS:X  a_  US-   [        U 5      :  aM  US-   nX   nUR                  S5      S:w  a  UR                  S5      nOUR                  S5      nUS   S:X  a  / nOUUS:X  a  SnOLUS:X  a  [        R                  nS nO3US:X  d  US:X  a  SnO$USS S:X  a  SnO[        SU-  5        [        5       $ US-   nU[        U 5      :  a  GM  Uc  [        S5        gUc  [        S5        g[        R                  " U5      nUc  [        SU-  5        g[        R                  " USS9nUc  [        SU-  5        gUc2  UR                  5       S:  a  [        S5        gUR                  S5      nOUR                  U5      nUc  [        S 5        gUR                  5       nUc8  UR                  5       S:  a  UR                  U5      nO#UR                  S5      nOUR                  U5      nUc  [        S!5        gUc5  UR                  [        R                   5      S:X  a  U(       d  [        S"5        Ub  U	(       a  [        S#5        Sn	Ub  U
[        :w  a  [        S$5        gS/nS/nS/nS/nU	(       Ga	  UR#                  5       nUR#                  5       nSnUR%                  5       UR%                  5       :X  a  Sn['        UR%                  5       5       H  nUR)                  U5      nUR)                  U5      nUR                  5       R+                  5       UR                  5       R+                  5       :w  a  SnUR-                  5       UR-                  5       :w  d  M  SnM     U(       d  U(       d  [        S%5        Sn	[/        UUUU
UU	UUUUUUUUU5      nU(       da  [        S&5        [        S'US   -  5        [        S(US   -  5        US   S:w  a  [        S)US   -  5        US   S:w  a  [        S*US   -  5        S nS nU$ )+NFr   z-srcr   z-dstz	-srclayerz	-dstlayerz-matchfieldz-update_onlyz-append_new_onlyz-preserve_fidTz-compare_before_updatez-select, r   z-dry_runz	-progressz-qz-quiet   z-skipzUnrecognized argument : %szMissing -srczMissing -dstz Cannot open source datasource %s)updatez%Cannot open destination datasource %szESource datasource has more than 1 layers. -srclayer must be specifiedzCannot open source layerzCannot open destination layerzZWarning: target layer does not advertise fast random read capability. Update might be slowz_Warning: -select and -compare_before_update are not compatible. Ignoring -compare_before_updatez,-select is only compatible with -update_onlyzC-compare_before_update ignored since layer definitions do not matchz	Summary :zFeatures updated  : %dzFeatures appended : %dzFailed updates    : %dzFailed inserts    : %d)DEFAULTr   lenUPDATE_ONLYAPPEND_ONLYfindsplitr   TermProgress_nocbr	   OpenGetLayerCountGetLayerGetLayerByNameGetNameTestCapabilityOLCRandomReadGetLayerDefnGetFieldCountrangeGetFieldDefnlowerGetTypeogrupdate_process) argvprogressprogress_argsrc_filenamedst_filenamesrc_layernamedst_layernamematchfieldnamepreserve_fidcompare_before_updateupdate_modequietskip_failurespapszSelFieldsdry_runiarg	pszSelectsrc_dsdst_ds	src_layer	dst_layerupdated_countinserted_countupdated_failedinserted_failedsrc_layer_defndst_layer_defnare_comparablesrc_fld_defndst_fld_defnrets                                    r   ogrupdate_analyse_argsrI   m   s   LLMMN L "KEMNGw	A
c$i-g&=QUSY.AA7LF]q1us4y0AA7LKAECI$5AA GMKAECI$5AA GMM!a!ec$i&7AA!WNN"%K&&%KO#L,,$(!I!a%#d)"3AAI~~c"b(!*!5!*!5a B&!#JGK,,HLD[C8OE1X  M.457NE] c$i-` nnXXl#F~0<?@XXl1-F~5DE!A%W OOA&	))-8	()%%'M!A%--m<I*I))-8	-. 	$$S%6%671<h	
 !&;m	
 !&!+%@ACMSNSNcO"//1"//1'')^-I-I-KK!N>779:-::1=-::1='')//1\5I5I5K5Q5Q5SS%*N'')\-A-A-CC%*N ; Y %*!
C$ k&q)99:&)::;!!*^A->>?1"*_Q-??@FFJr   c                     [        U R                  5       5       H,  nU R                  U5      nUR                  U5      nX4:w  d  M,    g   U R                  5       nUR                  5       nUc  Ub  gUb  Uc  gUb  Ub  UR	                  U5      $ g)NFT)r$   r#   GetFieldGetGeometryRefEquals)src_featdst_featr8   src_valdst_valsrc_geomdst_geoms          r   AreFeaturesEqualrT   9  s    8))+,##A&##A&	 -
 &&(H&&(HH0 0 4x((r   Fc                    U R                  5       nUR                  5       nUb  U R                  5       R                  U5      nUS:  a  [        S5        gU R                  5       R                  U5      R	                  5       nUR                  U5      nUS:  a  [        S5        gUR                  U5      R	                  5       nUbQ  UU4 HI  nU H@  nUR                  U5      nUS:  d  M  UU:X  a  [        SU-  5        O[        SU-  5            g   MK     Ub  U R                  5       nSnSnSnSnSnSn U R                  5       nUc  GOJUR                  5       n US-   nUb  U" US-  W-  SU5      S:w  a  gUGc  UR                  U 5      n!U!cz  U[        :X  a  Mg  [        R                  " U5      n!U!R                  U5        U(       a  U!R                  U 5        U(       a  SnOUR                  U!5      nUS:X  a  US-   nGOYUS-   nGORU[        :X  a  M  U!R                  5       n"U"U :X  d   eU(       a  [!        UU!5      (       a  GM  Ub  U H  nUR                  U5      n#UR                  U5      n$UR                  U$5      R	                  5       [        R"                  :X  a#  U!R%                  U$UR'                  U#5      5        My  UR                  U$5      R	                  5       [        R(                  :X  a#  U!R%                  U$UR+                  U#5      5        M  U!R%                  U$UR-                  U#5      5        M     O"U!R                  U5        U!R                  U"5        U(       a  SnOUR/                  U!5      nUS:X  a  US-   nGOUS-   nGOUR1                  5         WW:X  a<  U[        R"                  :X  a(  UR'                  W5      n%UR3                  S	UU%4-  5        OlUU:X  a<  U[        R(                  :X  a(  UR+                  W5      n%UR3                  S
UU%4-  5        O*UR-                  W5      n%UR3                  U< SU%< S35        UR                  5       n!U!c{  U[        :X  a  GM;  [        R                  " U5      n!U!R                  U5        U(       a  U!R                  U 5        U(       a  SnOUR                  U!5      nUS:X  a  US-   nGOUS-   nGO~U[        :X  a  GM  U(       a  [!        UU!5      (       a  GM  U!R                  5       n"Ub  U H  nUR                  U5      n#UR                  U5      n$UR                  U$5      R	                  5       [        R"                  :X  a#  U!R%                  U$UR'                  U#5      5        My  UR                  U$5      R	                  5       [        R(                  :X  a#  U!R%                  U$UR+                  U#5      5        M  U!R%                  U$UR-                  U#5      5        M     O"U!R                  U5        U!R                  U"5        U(       a  SnOUR/                  U!5      nUS:X  a  US-   nOUS-   nUS:w  a0  U(       d'  [4        R6                  " 5       S:X  a  [        S5        SnOSnGM_  U	b  [9        U	5      S:X  a  UU	S'   U
b  [9        U
5      S:X  a  UU
S'   Ub  [9        U5      S:X  a  UUS'   Ub  [9        U5      S:X  a  UUS'   U$ )Nr   z*Cannot find field to match in source layerr   z/Cannot find field to match in destination layerz&Cannot find field '%s' in source layerz+Cannot find field '%s' in destination layerg      ?r   z
%s = %.18gz%s = %dz = ''zKAn error occurred during feature insertion/update. Interrupting processing.)r"   GetFieldIndexr	   r%   r'   GetFeatureCountGetNextFeatureGetFID
GetFeaturer   r   FeatureSetFromSetFIDCreateFeaturer   rT   OFTRealSetFieldGetFieldAsDouble
OFTIntegerGetFieldAsIntegerGetFieldAsString
SetFeatureResetReadingSetAttributeFilterr   GetLastErrorMsgr   )&r=   r>   r0   r3   r1   r2   r6   r7   r5   updated_count_outupdated_failed_outinserted_count_outinserted_failed_outr*   r+   rC   rD   src_idxsrc_typedst_idxdst_type
layer_defn	fieldnameidxsrc_featurecountr?   r@   rA   rB   rH   iter_src_featurerN   src_fidrO   dst_fidfld_src_idxfld_dst_idxvals&                                         r   r(   r(   N  s   $ ++-N++-N!((*88HQ;>?))+88AIIK ..~>Q;CD!..w7??A!)>:J+	 ..y97!^3FRSKiWX , ; $446MNNO
C
++-//#+a/)C/2BBBU  ! ++G4H+-;;~6  *OOG,C#11(;C!8%3a%7N&5&9O+ #//+')))(-=h-Q-Q!-%3	&4&B&B9&M&4&B&B9&M*77DLLN"{{+ %-- +X-F-F{-S +77DLLN"~~. %-- +X-G-G-T %-- +X-F-F{-S% &4, $$X.OOG,C#..x8C!8$1A$5M%3a%7N ""$8#CKK(?//8,,\^S<Q-QRX%(cnn*D009,,Y.#9N-NO//8,,NC-PQ //1H+-;;~6  *OOG,C#11(;C!8%3a%7N&5&9O+ )-=h-Q-Q"//+!-%3	&4&B&B9&M&4&B&B9&M*77DLLN"{{+ %-- +X-F-F{-S +77DLLN"~~. %-- +X-G-G-T %-- +X-F-F{-S% &4, $$X.OOG,C#..x8C!8$1A$5M%3a%7N!8 '')R/3 { ~ $->)?1)D,!%#.@*AQ*F .1%#.@*AQ*F .1&3/B+Cq+H!0AJr   c                 J    [         R                  " U 5      n [        U SS  5      $ )Nr   )r   GeneralCmdLineProcessorrI   )r)   s    r   mainr~   3  s#    &&t,D!$qr(++r   __main__)NN)sysosgeor   r   r   r   r   r   rI   rT   r(   r)   r~   __name__exitr
   r   r   <module>r      s   @  
:BEX0 bJ hh ,
 zHHT#((^ r   