o rB¶d”`ã@s´ddlZddlZddlmZddlZddlZddlZddlZddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlmZddlZe ¡Zdd„Zdd„Zdd „ZdS) éN)ÚPolygon)ÚgdalcCsZt d|¡ d¡}t| d¡dƒd}|d}t| d¡dƒd}|d}||||fS)Nú$[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]rú-éèéÐé)ÚreÚsearchÚgroupÚintÚsplit)ÚentradaÚrasterÚ coordenadasÚxminÚxmaxÚymaxÚymin©rú/FACIL_OPTIMO_DSM_regex_DAG.pyÚ get_boundss   rcCs*|d|g}|d|}t d|¡ d¡}t| d¡dƒd}|d}t| d¡dƒd} | d} t|d ƒ}t| d ƒ} |d |d } d d i} dddœ} d di}dddd|| dœ}| ddœ}| | ¡| | ¡| |¡| |¡| |¡t |¡}t   |¡}|  ¡}|j }|j }|j}dS)Nz*.Ú.rrrrrrédÚ output3x3ú_DSM.tifÚtypez filters.mergezfilters.expressionzÁ(((Classification == 3 || Classification == 4 || Classification == 5) && NumberOfReturns == 1) || ((Classification == 2 || Classification == 6) && (NumberOfReturns == 1 && ReturnNumber == 1)) ))rÚ expressionzfilters.delaunayzfilters.facerastergð?i˜)rÚ resolutionÚwidthÚheightÚorigin_xÚorigin_yzwriters.raster)Úfilenamer)r r r r r ÚstrÚappendÚjsonÚdumpsÚpdalÚPipelineÚexecuteÚarraysÚmetadataÚlog)ÚdirectoriorigenÚdirectoriodestinoÚformatoÚ rastertiffZjsonDSMÚarchivorrrrrÚdestinoÚmergerÚdelaunayÚ facerasterÚwritersÚpeticionÚpipelineÚcountr+r,r-rrrÚpdal_merge_and_DSM3x3-sL   ÿþÿú þ        r;c Csòz>tdttj ¡ƒddƒ}|t|ƒddkr,d}| |¡| ¡t|ƒWdSzt  d|¡t  d|¡Wnd }t|ƒ| |¡Yt j d |d |dd d t  d|¡}|D]‰}zqt  d|¡ d¡}t| d¡dƒd}|d} t| d¡dƒd} | d} d|d|}| |¡t|ƒ|D]‹} zit  d| ¡ d¡} t|  d¡dƒd}|d}t|  d¡dƒd}|d}t||ƒdkr t| |ƒdkr d|d| dd|dd}| |¡t|ƒt j d|d| d|dd d Wq£ty.d}t|ƒ| |¡t ¡| t ¡¡Yq£wz!| dd¡d}| dd¡d}td|dd|d||ƒWn4ty„t j d|d|dd d d|d}t|ƒ| |¡t ¡| t ¡¡YWqdwt d|d|d ¡}d!|d|d"}| |¡t||ƒ}td#|dƒtj||d$|d%d |d&d&d'}d||d(}| |¡t j d|d|dd d Wqdtyî| t ¡¡t ¡Yqdwz.t j d|d)|d d t d*¡t j d|d+|d d t j d,|d-d d WWdSty?d.}t|ƒ| |¡t ¡| t ¡¡YWdSwtyxtd/ttj ¡ƒddƒ}t ¡| t ¡¡d0tt ¡tƒd1}| |¡| ¡YdSw)2NZ log_DSM_crop_z.txtÚwrú/z2Path entrada mal especificado. Ha de acabar en "/"z ./temporalDSMz./temporalDSM2u Ya están creadas las carpetas zmv z* ./temporalDSMT)Úshellrrrrrz3x3 para archivo ./temporalDSMzVecino ./temporalDSMz movido a Ú zmv ./temporalDSMz ./temporalDSM2zError moviendo vecino/srzmv ./temporalDSM2z/* ./temporalDSMz error durante DSM 3x3 raster z sigo z /output3x3rz ./temporalDSM2z _DSM.tif z rastertiff z.tifÚGTiffz EPSG:25830)ÚformatÚ cropToCutlineÚ outputBoundsÚsrcSRSÚdstSRSz.tif z/*.laz i,z/* zrm zoutput*z$ problema reorganizando directorios Zlog_error_DSM_crop_z --- z seconds --- ) Úopenr$ÚdatetimeÚnowÚlenÚwriteÚcloseÚprintÚosÚmkdirÚ subprocessÚrunÚlistdirr r r r r ÚabsÚ ExceptionÚ tracebackÚ print_excÚ format_excÚrsplitr;rÚOpenrÚWarpÚtimeÚsleepÚ start_time)rÚsalidaÚcodigoÚfiler-Úarchivosr2rrrrrÚvecinoÚcoordenadasvecinoÚ xminvecinoÚ xmaxvecinoÚ ymaxvecinoÚ yminvecinor0r1Úinput_raster_originalÚboundsÚdsrrrÚ tifcortado`sÀ    $$ &€ ú"  ù     "ý  ú úrj)Ú geopandasÚgpdÚfnmatchÚshapely.geometryrÚ shapefilerMr&r(rTÚlaspyÚlpÚnumpyÚnprOrGrZÚsysr ÚosgeorÚcsvr\rr;rjrrrrÚs*   3