# -*- coding: utf-8 -*- # --------------------------------------------------------------------------- # podil.py - vypocita aku plochu (absolutnu a relativnu - %) ma nejaka polygonova vrstva v administrativnych jednotkach # --------------------------------------------------------------------------- # Import arcpy module import arcpy from arcpy import env # Script arguments, user dialog in_features = arcpy.GetParameterAsText(0) # polygony ktorych rozsah chceme zistit clip_features = arcpy.GetParameterAsText(1) # admin. jednotky Output_Feature_Class = arcpy.GetParameterAsText(2)+"\clip.shp" # súbor pre dočasné uloženie orezov # Set workspace env.workspace = clip_features rows = arcpy.UpdateCursor(clip_features) # iterator pre admin. jednotky # pridnie stlpcov do ktorych sa ulozi vysledok vypoctu #arcpy.AddField_management(clip_features,"p_abs","FLOAT") #arcpy.AddField_management(clip_features,"p_rel","FLOAT") # zistenie plochy orezov def total_area(infc): rws = arcpy.SearchCursor(infc) # iterator pre orezy area=0. for i in rws: # objekt sa moze skladat z viacerych polygonov, preto zistujem celkovu plochu pomocou for cyklu polygon=i.SHAPE a = polygon.getArea() area = area + a return area for row in rows: Feature = row.SHAPE #pristupujem ku geometrii jednotlivych jednotiek clip = arcpy.Clip_analysis(in_features, Feature, Output_Feature_Class, "") # orez tot_area = total_area(clip) # zistujem plochu orezu pomocou funkcie total_area (vid. vyssie) unit_area = Feature.getArea() # plocha admin. jednotky rel_area = (tot_area / unit_area)*100. # rel. plocha row.p_abs = float(tot_area) # zapis do atr. tabulky row.p_rel = float(rel_area) arcpy.Delete_management(Output_Feature_Class) # mazem orezy