o d8@sddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZe ZddZddZddZd d ZdS) N)PolygoncCs t|dS)N)print)ar/filtrado_optimizado.pyholas rc Cs*t||}t|jj}t|jj}t|jj}t|jj} t|| f||f||f|| f|| fg} t || } z| j dd} Wn| d} | } | | dd} | j dd} Y| jdd} | jdd} | jd d } | jd d } |d |d|dddd} | jrdS| j| ddd| S)N)ZbyZgeometryg{Gz?)ruido)suelo)edificio) industrialZ2x2__.rz.shpzESRI Shapefilez EPSG:25830)ZdriverZcrs)lpreadroundheaderZx_maxZy_maxZx_minZy_minrgpdZ read_fileZdissolveZ make_validZ set_geometrybufferZassignrsplitemptyZto_file)entradasalidaarchivoshapeZtipoZlidarZ laspyxmaxZ laspyymaxZ laspyxminZ laspyyminZcuadrado_seleccionadoZ shape_2x2ZpolygonsZ pathshaperrr cortarshapes.    &     $rcCs|ddd}|ddd}||d|}||}g}||dd} ddd} d d d } d d |dddd} d d |dddd} d d |dddd}d d |dddd}d d |dddd}d d |dddd}d|d}|| || || |ddur|| || |ddur|||ddur|||||ddur||||t|}t|}|}|j}|j}|j }dS)Nrrrt1)filenametagzfilters.hag_nnZt1h)typer"zfilters.planefit8)r#Zknnzfilters.overlayZClassificationzo(Classification==4 || Classification==5 || Classification==6) && HeightAboveGround<=4 && HeightAboveGround>=0.6r )r#Z dimensionZ datasourcewhereZcolumnzClassification==3r zClassification==9r ze(Classification==3 || Classification==4 || Classification==5) && HeightAboveGround>=4 && PlaneFit>0.6zf(Classification==3 || Classification==4 || Classification==5) && HeightAboveGround>=4 && PlaneFit<=0.6rzClassification==6rz writers.las)r#r!) rappendjsondumpspdalZPipelineZexecutearraysmetadatalog)ZorigenrZdestinoZshape_inZ nombrearchivoZformator!ZinnZ jsonOverlayZin1ZhagZcoplanarZoverlayZoverlay2Zoverlay3Zoverlay4Z overlay4_2Zoverlay5ZwritersZpeticionZpipelinecountr+r,r-rrr pdal_overlay>s                       r/c Cszz t||WnYtdttjdd}|t|ddkr:d}|||t |WdS|t|ddkrVd}|||t |WdS||d7}||d7}d} t |D]d} zNt | d sxt | d rd || d }||t |d } t ||| |d} t ||| |d} t ||| |d} t ||| |d}| | | |g}t || ||Wqityt|tYqiw| rd|d}||t |dtttd}||t ||WdSdtttd}||t ||WdStyStdttjdd}t|tdtttd}||t ||YdSw)NZlog_cambiar_clasifz.txtwr/z2Path entrada mal especificado. Ha de acabar en "/"z1Path salida mal especificado. Ha de acabar en "/"Tz*.lasz*.lazz #####################z##################### Fvialembalsesedifsrz+ #################### No hay .las/.laz en z #################### z--- z seconds ---z --- z seconds --- Zlog_error_cambiar_clasif)osmkdiropenstrdatetimeZnowlenwritecloserlistdirfnmatchrr/ Exception tracebackZ print_excZ format_exctime start_time)rcodigorr2r3r4rfiler-Z nohaylasesrZpathshape2x2vialZpathshape2x2embalsesZpathshape2x2edifsZpathshape2x2industrialZshapessrrrcambiar_clasifs|            rE)ZnumpyZnpZlaspyrZ geopandasrr*r5r( subprocessr9r@rAr>Zshapely.geometryrrBrrr/rErrrrs"   p