Download - Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

Transcript
Page 1: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

ModelBuilder,SelectionandPortabilityOurpurposehereistodevelopmorepracticewithmodelbuilder,andtoautomateportionsofyourworkClowtoeasemultiplerunsduringyourrunoffmitigationdevelopment.

Therewerethreemain“branches”intheexampleClowchartprovidedearlierinthesemester;onethatcalculatednetrainfall(red,below),onethatcalculatedinCiltration(green),andathirdthatcalculatedwatersheds(bluebelow).

WhileyoumayhaveoptedforadifferentworkClowthatthatembodiedinthisClowchart,yourapproachwilllikelyincludesomethingsimilartothethreebranches.Forexample,avector-onlyapproachcouldduplicatethesethreebranches,butsubstituteasetofoverlays,calculations,andrecodingsfortherasterconversionsandrasteralgebraontherightsideofthisClowchart.

Yourvariousmodelrunsinvolvemodifyinginputs,e.g.,canopy,buildingrooftypeorsurfacepermabilities,orwatershedpourpoints,andthenre-runningtheanalysis.

Thissortofrepeatanalysiscouldbegreatlyeasedbymodelswhichallowyoutochangethoseinputs,butrunthesamemodelstepsinamoreorlessautomatedfashion.

YourPreviousModelBuilderassignmentincorporatedthewatershedbranchintoamodel.

YourassignmentthisweekistowritemodelsforsomeversionofthenetrainfallbranchandtheinCiltrationbranch.

Page 2: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

In5iltrationBranchExampleTheobjectiveofthismodelistocreatealayerwithacolumnformaximuminCiltrationsrates,combiningbuildings,impervioussurface,andsoilslayers.

Inourproblem,itislikelywewillmodifyourpervioussurfacelayer,changingsomeoftheimpervioussurfacestopervioussurfaces,andmodifytheoriginalbuildingslayer,convertingsomeoftheClatroofstogreenroofs.

Therefore,wewantatleastthebuildingsandperviousnesslayersasaparameterthatcanbechangedwitheachrun.

Afewstartingassumptions:First,Iwon’tbemodifyingtheinitialsoilslayerbetweenmodelruns.I’llmakeitaparameter,becausethatprovidesmoreClexibilityforyourmaininputdata,butIdon’tneedto,socouldleaveitasaCixeddatasetsinceIwon’tbechanginganysoilspolygonsortabledatabetweenruns.Alsonotethatthesoilsdatahasalreadybeenclipped(belowleft),andapropertableitemforthemaximuminCiltrationratesforunderlyingsoilscreatedandwiththepropervalues,namedSoil_InCl,asshowninthetableatright.Thereareothercolumnsinthetable,hiddeninthisview.TheBuildingFootprintslayershasacolumnlistingrooftype.

IassumethemodiCiedbuildingfootprintslayerhasassignedaRoofvalueof“Green”fortheClatroofsconvertedtogreenroofs.

Page 3: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

ThelayerPerviousnesscontainsaCieldthatidentiCiesimpervioussurfaces:

OuroriginalClowchartshowedthebranchassomethinglikethis:

TheoriginalClowchartshowedusunioningthePerviousandBuildingFootprintslayer,herecalledBldPrv.However,asyou’vediscoveredinyouranalysis,thisunionresultsinanullorunassignedvaluesfortheTYPEcolumn,thevariablethatrecordsperviousstatus,forbuildingpolygonsintheunionoutput.ItalsoresultedinnullorunassignedoutputfortheRoofvalueinthepolygonsfromtheperviousnesslayer(seearrows,belowright).These

WeneedtoCixthis,aswewanttorecordthestatusofthesurfaceintoonecolumn.

Page 4: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

Here,I’llchoosetorecordtheroof’simperviousstatusintotheTYPEcolumn,touseinfurtherprocessing.Ineedtoassign“Impervious”totheTypecolumnforthepolygonswithpitchedorClatroofs,and“Pervious”totheTYPEcolumnforbuildingswithGreenroofs.

Whenprocessingmanually,youwouldmostlikelydothiswithaSelectbyAttributestool,andthenaCalculateFieldtool.Thissequencedoesn’tworkinModelBuilder,becausethecalculateCieldtool,whendonemanually,onlyoperatesonaselectedset,ifthereisone.ModelBuilderdoesn’tdothis.

Fortunately,wecanusesyntaxwithintheCalculateFieldtooltoselectwhilecalculating.

Ibuildmymodelbydraggingandconnectingtheappropriateinputsandcommand:IthenopentheCalculateFieldbubbleonmymodelcanvas,andindicatethe

Page 5: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

InputTable,FieldI’llbemodifying,enteringanexpressioninthewindowatthebottom.

TakecaretonotethatthisisanArcadeExpressionType(seearrowatright)

ThewindowatthebottomshowstheexpressionassignedtoTYPE.

Thisisaselection/assignment,withtheWhen(partsignifyingtheconditionalassignment.

The$feature.indicatesthatwewanttocyclethroughallthefeaturesintheinputtable.Thencomesthecondition;theCirstline$feature.TYPE==“Impervious”,“Impervious”,

isinterpretedas:whereveryouCindaTYPEvalueofImpervious,assignitavalueofImpervious.

Thecleverpartsstartatthethirdline,with$feature.Roof==“FLAT”,“Impervious”,

ThisallowsustoassignaTYPEvalueofImperviouswhenevertheRoofisFLAT.

Therestoftheexpressionissimilar,assigningvaluesbasedonasetofconditions.NotethatthereisaCinal“NotAssigned”Clag,ifnoneofourconditionsapplytoafeature.Alsonotethecommasfollowingeachcondition,andthegeneralsyntax.ModelBuilderisprettyunforgivingforerrorsinformatorcontent.

AfterrunningtheCalculateFieldcommand,IcheckandnotethattheTYPEcolumniscorrectlyassignedformypolygonsthatcamefromtheBuildingFootprintslayer,butarenowpartofmyunionedperviousnesslayer:

Page 6: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

OurClowchartshowsthenextstepasaunionofsoilswithourbuildingsandpreviouslayer:

WhenimplementedinModelBuilder,itlookssomethinglikethis:

Page 7: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

Afterrunningtheabovemodel,thetablefortheoutputcombinedsoils/buildings/perviousnesslayerlookssomethinglikethis,below:

Itisclosetowhatwewant,inthatwehaveourvarioustypescombined.However,theinCiltrationofimpervioussurfacesshouldbesettozero,astheyareimpervious.

Inaddition,theinCiltrationforgreenroofsshouldbesettotheirmaximumvalue.

Itisperhapssafesttocreateanewcolumn,andcalculatethemaximuminCiltrationintothatcolumn.IcandragtheAddFieldoperationontotheModelBuilderCanvas,andspecifytheinput,anewCieldandtype(InameditMaxIn5l,typedouble,precision12andscale5).

IcanthenuseCalculateFieldandaWhenconditionalassignmenttoassignthepropervaluestomyMaxInClvariable.ImightcreateanArcadeassignmentequationsomethinglikethis:

Rememberinthissyntax,itcheckseachrow,andifitisimpervious,itassignsandinCiltrationofzero.MypreviousprocessingensuresthisconvertsboththeimperviousroofsandlandsurfacetozeroinCiltration.ButsinceIhaven’tsetaninCiltrationrateforgreenroofs,Ineedtodothatnow(NotethattheCigureshouldread0.05ratherthan0.5forGreenroofs).Therestofthepolygonsareprevious,andgettheunderlyingsoilinCiltrationrates.

Page 8: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

ThereisonewrinklethatwemightCinddisconcerting.IfIlookattheinputtable,therearetwocolumnsnamedtype:

HowcanIbesurethatmyselectionwillworkonthecorrectcolumn.InthiscaseIwanttousetheleftTYPEcolumn,whichcontainsimperviousness,andnottheright,withcomesfromsoiltypes.

Nottoworry,Iamonlylookingatanalias.IfIopentheFieldsviewonthetable(rightclickonanycolumnandselectFields,nearthebottomofthedropdown),Iseethatthecolumnshavedistinctnames,TYPEandTYPE_1.TheUnioncommandcreatesthesedistinctFieldNames,andassignsaliases.TheArcadeexpressionreferencestheFieldNames,andnotthealiases.

Page 9: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

MyModelwillnowlooksomethinglikethis:

OnceIvalidate,run,andverifythemodel,IcannowcalculateanewmaximuminCiltrationlayerafteranymodiCicationoftheinputs.InthiscaseIcouldchangetheperviousnesstoconvertsomeofmyroadsorsidewalkstoperviouspavement,andchangeabuildingtohaveagreenroof,andthenre-runmymodelfairlysimply.Thiswouldgreatlyspeediterationthroughmymitigationdevelopment.

Ifthiswereastand-alonemodel,Iwouldprobablywanttomaketheoutputaparameter.However,thegoalistocreatealargermodelthatincorporatesmyentireworkClow.

OnceI’vecompletedthis“branch”ofmyoverallmodel,I’llhavetwoofmythreemainbranchescodiCiedinModelBuilder.Icouldthenmakeafullmodelbycompletingthethirdbranch,andafterdebugging,combineallthreebrancheswithan“overlay”ofsortsofthethreebranchlayers,eitherthroughconversion/rastercalculatororvectorunion/recode,andthentorasterorvectoraggregationfunctions.

Page 10: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

MakingaModelFlexibleYoumightnoticethatwhenyousaveamodel,theCilereferencesaresettotheinputvaluesyouusedwhendebugging,e.g.,ifaninputCilewasintheC:\users\classdatadirectory,withthename“elev_rast.tif,”thenthatwillbeincludedinthemodelspeciCicationwhenyousaveit.

Ifyouwanttousethemodelondifferentdata,inadifferentdirectory,youmayrunintoproblems,becausethemodelwilllookforexactlythesedata,inthespeciCieddirectory,whenyouwishtorunit.

Oneoptionistospecifyallinputandoutputdatasetsasparameters.Thismayworkinsomeinstances,butinothers,youmaynotwishtohavetospecifyalltheinputs.Inaddition,ifthereareintermediatedatasets,youdon’twanttohavetospecifyallofthem.

Acommonapproachistotakeadvantageofinlinesubstitution.Anytimeyouenclosetextin%symbols,themodelwillsubstituteaworkspacevariabledeCinedforthattext.Forexample,intheCigurebelow,mybasedataarestoredinageodatabasenamedData.gdb.IdeCineaworkspacedatalocationwiththenameDataWorkspace,andavalueofC:\Data.gdb.IfIplacethetoken%DataWorkspace%inmyModelBuildercode,itwillsubstitutethevalue,C:\Data.gdbwhenrunningthemodel.InthiswayIcanspecifyadifferentpathanddatasetformyinput.NotethatthedatasetsthemselvesmusthavethesamenamesasspeciCiedinthemodel,e.g.,Roads,Projected,intheexamplebelow.Icouldmakethesevariablesthatoneenterswhenrunningthemodel.

Inlinesubstitutionisoftenusedtoallowforworkingondifferentcomputers,wherethepathstoacommondatasetmaybedifferent.Itisalsooftenusedtospecifythescratch,orworkingdirectory,whereintermediatedataarestored.InlinesubstitutioncanmakeyourmodelsmuchmoreClexible.

Youwanttooptimizehowyoudivideinputsbetweenparametersandinlinesubstitution.Ifyouarealwaysworkinginthesameproject/database,onthesamecomputer,thenyouprobablydon’twanttomaketheselocationsasinlinesubstitutes.You’reenteringthesamethingswitheachrun,wastingtime.

Youlikelywanttouseinlinesubstitutionfortheworkingdirectories/paths,butnotmakethemparameters,ifyouswitchbetweenlocationsoften,butusethesame

Page 11: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

geodatabasedandCiles.Forexample,ifyouworkissplitmainlyintheSkok35labandahomeorofCicecomputer,you’lllikelyhavedifferentpathstoyourdataandscratchworkspacesonthetwodifferentcomputers,butusethesamegeodatabaseanddatalayernames.Youdon’twanttoaddinlinesubstitutionvariablesormostoftheinputfeatureclassesasparameters,becauseyou’llhavetoenterthemwitheachrun.Rather,youwoulduseinlinesubstitution,andeditthemodeltosetthedataorworkspacevariablesforthemodeloneachcomputer.Aslongasthedatausethesamenamingconvention,youcanmoveupdateddatabackandforth.Eachtimeyouswitchbetweencomputers,youcanjusteditthemodelonce,tomodifythevariableforyourdataworkspaceandyourscratchworkspace,andthendoyourruns.

Ifyouarechangingadatalayer,e.g.,addingpourpoints,youmaywishtomakethataparameter,andprobablynotaninlinesubstitution.Onlythosevalueswhichyouwhichtochangeregularlybetweenrunsshouldbeparameters.Acoupleofothernotesoninlinesubstitution:• Youshouldaddinlinesubstitutionvariablesafteryouhavewritten/debugged

yourmodel,atleastwhilelearning.TheValidate/RunsometimestripsupontheinlinesubstitutionwithintheModelBuilderEditor,eventhoughthemodelworksinamodelrunfromatoolbox.Yougetodderrorwarnings,sowhileyou’relearning,youthinkyou’vedonesomethingwrong,whensometimesyouhaven’t.

• Bepreparedforsomeofyourdataandoperationstobegreyedout,seeminglyincomplete,whenyouuseinlinesubstitutionvaluesasparameters.Theprogramdoesn’tknowwhattheyareuntilruntime,soitwilltellyouthatinputsareundeCinedorincorrect,forexample,sayingadatasetdoesn’texistbecauseadataworkspace(geodatabase)isavariable,deCinedatruntime.

• SometoolvaluesneedtobedeCinedasparameterswhenyouuseinlinesubstitutionthatdon’tneedtobeparameterswhenyouhard-wirethedatasource.Forexample,apourpointCieldhastobespeciCiedwhensnappingpourpoints.IfyoubuildyourmodelandindicateaCixedinputlayer,youhavetheopportunitytoalsoidentifythecolumnusedforidentiCication.IfyouhavethepourpointinputlayerdeCinedaspartofaninlinesubstitution,ModelBuilderdoesn’tknowwhatvaluesmightbeavailable,soitremainsundeCined.YouhavetosetitasaparametersoitcanbespeciCiedatruntime,oncetheinputdatalayerisknown.

Belowisamodelthatcontainsinlinesubstitution,and(perhapstoo)manyparametersfortheinputsandoutputs.ICirstcreatedthismodelasshownearlier,withoutanyinlinesubstitution,veriCieditworked,andthenintroducedvariablesforaninputdatabase(DataGDB)andscratchworkspace(ScratchGDB).This“broke”someofthepieces,andsoIhadtomodifythemodelabit,addingthepourpointCieldasaparameters.Thismodelassumeswe’llbemovingourmaindatabetweencomputers,andmostlymodifyingourpourpointlayerinthisbranch,asweaddnewraingardensforourproject.Thismeanswe’realwaysusingthesameinputDEM,soitdoesn’tneedtobeaparameter,andthatI’llbeworkingwiththeoutputvectorwatershedpolygons,soIdon’tneedtospecifytheoutputrasterwatershedsasa

Page 12: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

parameter.DifferentworkClowswouldlikelyhavedifferentmixesofparametersandinlinesubstitution.

IfIrightclickandopentheInputDEMbubble,IseethefollowingCigure:

Itshowsthatwe’reaccessingourstudyareaDEM,withthedatapathpre-pended.WhenIsetthisasaparameterduringamodelrun,itwillsubstitutethepathintothe%DataGDB%part.

Page 13: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

IfIhoverthecursoroveranoperation,itwilltemporarilydisplaytheinputvariables,herefortheFlowDirectionoperation:

Youcanseethattheinlinesubstitutionisinplaceforbothmyinputandoutputdatalayers.

Inthisinstance,IdecidedIdon’twanttosavemysnappedpourpointstomymaindatageodatabase,butrathertothescratchgeodatabase.Icouldhavedonethisforanyoftheintermediatelayers,itjustdependsonwhatIwanttosavewhere.IspeciCiedthisbyOpeningandtypingtheinlinevariable,%ScratchGDB%\SnapPPwhenspecifyingtheoutput,anditrecordedthatintothemodel.HoveringovertheSnapPPbubbleshowsthis:

OnceI’vespeciCiedtheinlineandparametervariables,Isavethemodel,andthenrunitfromtheCatalogToolbox.

Page 14: Model Builder, Selection and Portability · Model Builder, Selection and Portability Our purpose here is to develop more practice with model builder, and to automate ... , but run

ESPM5295 ModelBuilder,Assignment2

Yourassignment:Create2models(ofbothbranchesinthesamemodel),thatcalculate1. thepervious/building/soilcombinationbranchdescribedabove,appropriateto

yourworkClow,and,2. thecreationofanetrainfalllayer.Thissecondmodelwillbeabitmore

complicated,inthatIwantyoutostartwiththeinputPOINTSforyournewcanopyasoneofthelayers,asaparameter,alongwithyourexistingcanopy,buildingslayer,andgrossrainfalllayer(2.5or5cm)asinputs.Yourmodelneedsto

• bufferthepoints(perhapsbasedoncanopytype),• thenunionthenewcanopywiththeexistingcanopy• theneraseoutthecurrentbuildingsandcurrentcanopyfromyour

bufferednewcanopy(tocreateanewlayerthatallowsyoutocalculatecostofthenewcanopyareaonly)

• assignrainfallinterceptiontotheexpandedcanopylayer,• calculatenetrainfallfromthegrossrainfallpluscanopyinterception.

Turninpdfsofthemodelbuildergraphic,andthemodelsthemselves,intotheCanvassite.