Python: Developing Geoprocessing Tools

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right so uh yeah hey good afternoon I'm Dave I were going to shoot pricing analysis team I actually wear two hats I'm the lead Python lead product engineer and chief processing team but I'm also the doc lead we'd offer to share processing teams so I do a lot of both kind of my history of in it as read about 14 years I do in G processing Python like a large chunk of that this is kind of the this is my little universe this is the stuff that I do really you know almost every day so I hope I can over the course this session kind of bring to you you know the knowledge that I have and kind of help all of you kind of build better geoprocessing tools using Python how many people are building or creating some tools right now like I said okay so then one like completely new to this just like oh you heard about this okay that guy all right and and 20 other people who have we're involved enough all right so this session yeah is about kind of taking Python and building geoprocessing tools from it we have two different flavors of doing this and we'll kind of talk about both of those both script tools and working with some called Python toolboxes and you know we're not going to function or focus so much on kind of the internal guts of the tool this is going to be more about kind of the experience of it right the kind of the surrounding pieces and the little bits of stuff that we need to kind of make sure we get right the car inside the tool but you know kind of what you put inside those tools well you know that's really up to you right it's a what you need to do now whatever tools are functionality you need to create all right so I don't know if this kind of projects the way while it is kind of this is a tool kind of the golden halo around it right this is kind of our our end result right we want to be able to build geoprocessing tool and kind of the advantage of that is we have this you know kind of large like geoprocessing framework right so you build a tool without you know a lot of crazy UI programming everything like that and you kind of just fit it in take advantage of all the framework that G pop to processing tools have around them so this is a little tool that I created last year it's not very sophisticated but in principle you know this is what you get right and there's kind of some extra parts of this so you know when you're interacting with that tool all right every time you go in and you change a value or click here and you click away you're triggering these kind of validation stages that's one chunk about what we're going to talk about today it's kind of making these little extra decisions that kind of make your tool work better and work smoother and then of course once you get you know someone's completed the arguments that they want parameters they want you just going to hit OK and you send it off to your source code right so there are just a few things I want to talk about specifically in that there's you know a few different things about how we kind of make that source play nice with kind of the front end of the tool and that'll be another part of things we'll talk about today so I'm not going to linger on this slide too much but it's one of kind of splashes up there's some kind of common things that you know pitfalls in sense that people can sometimes fall into when building the tool some of them may seem pretty obvious but you know you can ward off a lot of troubles by following some of these sort of basic principles the one that always kind of catches my eye and I find I've learned more than a few times is is this one here keeping the cost of validation to a minimum we'll talk about validation course but it's something you can really kind of go hog-wild on if you're inclined to but generally speaking right validation is something I want to keep to a minimum because that's a consistent time head for somebody interacting with your tool all right so we have two flavors that we have with geoprocessing Python based tools the are the golden oldies something called we call script tools and this is something that we originated way back at 9'o but it existed since then you know continuous improvements to that experience it's more of a kind of a wizard based approach for for building tools right after this little wizard and you populate your parameters and all these little pieces the parameters the validation and your source code kind of live in this kind of discombobulated sense right it's functional and it works but there may be more developer oriented which I think problem with good chunk of us are here Python toolboxes is maybe a better experience it's place where all those pieces you know the defining a parameter dealing with validation code all of that is you know this in Python code the point I want to make here though is really kind of this last one is that no matter you know how or where you build your tools and oh hey you can build a model too if you want right the end result really should be you know there won't be a you won't look at a tool and be like oh well that's obviously this tool right it's you know you're going through different experiences to really create the same end so whichever you want to go with you know it's that's up to you the end result will be you know not discernible to sort of the average user just interacting with your tool now I just want to highlight this slide quickly when we talk about validation later there's this very subtle difference between Python toolboxes and script tools and but I don't like double present kind of this information so you can see on script tools and validation the parameter values come in as properties on the class and over in Python tool boxes that are passed in his arguments but otherwise all this validation stuff and I'll get to that more in a few minutes the theory the the mechanics of it all virtually the same okay so parameters are really kind of the lifeblood of how all this tool stuff works right you you create our parameters that kind of gives us a presentation of how the tool dialogue is going to work right each burn seems like data type it's going to go a long way to kind of defining what the controls are that you see parameters kind of control how the values come through and how they get picked up and used by your source code right it's kind of everything flows through the parameters so data types a big one there's 100 and last time I checked hundred three or four different data types which seems like a lot but most of them are kind of small like nish uses for specific geoprocessing tool in the box most of the time you're probably going to be working within a small subset of like ten to fifteen different data types so pretty straightforward things you know like the scaler things like you know strings and boolean was you know various numeric values and then you know our own kind of data data source base data try things like feature classes rosters these sorts of things Direction parameter type also important one thing notice parameter type of derived that is really just something that it's like a return bound from a function right where it's not something that you're going to have on the dialog but it's still a parameter it's a value that is going to be computed inside your source and then push back through a derived parameter okay all right so anyone recognize where we are here is a few detail in the map oh yeah all right so there's a Lake Tahoe Carson City right over here Reno's up just above the top I have a tool here this is the DM of that local area so one of my colleagues actually came up with a few tools a few years ago and I'm kind of just borrowing from what she created her name is Linda Beall she created this tool that essentially takes like a DM I'm going to kind of step through this tool and we'll come back talk about what's going on so take a DDM I'm specify and output this little thing here I don't note that you can see that just because scratch gdb my point is not really to draw attention to that other than it's kind of like a shortcut for putting a workspace in so instead of having to browse to it I can just type this percent main percent thing all right let's run this so what this little tool does is it creates basically like a Swiss style hillshade off of this de M if I'm lucky this will take ten seconds if I'm not so lucky might take 25 all right no all right so slowly comes in all right so you know creates kind of an interesting visual appeal right kind of makes me want to go skiing right all right so what is this tool about so just to kind of refresh a few of you and maybe not been through this too much you know I have an existing tool box right here but if I wanted to create you know a new one right it's just a new tool Bob tried the toolbox hoop is really just the like the delivery mechanism right is the container of my tools and if I have an existing toolbox and now I can always add one or more all right you can like create a model if you want we could add additional tools through this and that's going to step you through this wizard now I'm not going to go through that too much let's look at what this tool is the wizard looks really basically the same thing as what we're seeing here you know there's a few little property or general source I'm going to focus most of our attention today kind of on the parameters of validation and then well actually what's inside these kind of files here all right so we're defining a parameters kind of usually like three big things and I think I'm you're always going to kind of watch for than a few extra spec datatype we kind of discussed already one key thing of data types though is you know when you got a tool there's usually kind of two experiences you kind of want to watch for right you want kind of the interactive experience where someone can pick a layer but then typically also you know they can pick data source somewhere on disk right so usually for inputs we're talking about you know the layers of raster layers feature layers table views not you know raster datasets feature classes table try if you want the layer as the input now a few other things you can do in here Hill some data types will have the ability to kind of fill it's kind of a very general like exclude this but not that kind of scenario right so this particular tool I don't want it running off of like shapefiles and I now creating into a file workspace so I block that off if you get into cases like this one you know where you know I've raster based output the hillshade really doesn't look anything meaningful if I just dump it into the map by default so I can apply symbology to that so in script tools we just manage that with later files right so as we layer file you created independently right maybe ran the tool once create a layer file off of that with the symbology Lake and then you just kind of reference it down here now one that I don't have in here and I'm just going to kind of hack this a little bit just to kind of show so sometimes you can have parameter dependencies between different parameters where there's sort of like a natural relationship between two different things right you have like like a data source right like a feature class and then you want to pick fields from that for each plot so say if I switch this over to field all right I could do this obtained from what am i doing I'm forgetting something but normally you'd be able to click on here and get associated with that input all right now that was a script tool most of the rest of the the workshop I'm going to focus more on Python toolboxes not because I'm trying to like plug one over the other just because I find it kind of easier to show that the code elements and we can kind of refresh and get to things a little bit faster so I created it essentially like an exact duplicate of that tool and actually but before I do that let me just this the effective source between her behind both of those tools is this little file here that I created so like I said right Linda was kind of the one who did this originally it's based off of some work this guy now if we go into the bottom big thing here using right he's receiving the arguments from that tool right you run the tool however you run it right the you're running at the model dialog you're running it from code right we can get the parameters using something called get primers text or there's actual equivalent function called get parameter this is a function that I like to use or well and see this line here it's kind of a little strategy I like to use quite a bit it's kind of a way of just grabbing all the parameters at once right basically looking at how many parameters there are and kind of doing this at comprehension to pull them all into one now just because I have just some dry parameters on it too although I got to be a little careful so this is just dropping those off after this it's really just you know a little function that I wrote I'm passing all those arguments in to that and there's nothing really crazy you're fancy in here it's really just a kind of a series of spatial analyst tools kind of run those in order to create the output and then I'm just passing them back out of the function all right because this is a tool drive parameters though I use set parameters tax right so typically set parameters tected not functionally I have to use that much it only applies when you have dry write it's a way of sending those values back up to the tool that's kind of what makes them add to map that kind of what helps make model builder work as well now the Python toolbox side of it right here so python toolbox is right or just a different way of creating Python based tools but there's a little bit a more structure right in the in a classic TV X file and all that's kind of just handled and you go through the UI and kind of just do all that stuff and Python toolbox it's kind of a structured part of the code so every Python toolbox needs to have this toolbox class right that's kind of the bare minimum you have to have in here for to be recognized properly and then inside that or below that you would have one or more tool closets and if you haven't been through this experience before it's not a big deal to get started it's really just coming up here doing new Python toolbox and all stubbed out all that stuff or you're right so don't worry about you know like how a tool class looks in particular and then you can get that pretty quickly and easily so then inside this you have method called get parameter info and this is where you define your parameters we do that using these art PI parameter objects typically you know 90% of them the parameters I'm going to create again you just have these five properties set and that's it right so name label and the big three ones I mentioned earlier you know datatype direction and required now this one I flattened I flagged this one because I almost goofed on this one earlier so this is my output workspace but I instinctively kind of just call the direction of output and the one thing to remember about defining parameters is output is that if you have your geoprocessing setting over at your output and over at your output alright so I didn't want it to nuke a folder right it's not I'm passing it as input even though things are going into it so we call it an output but it's not really an output you got that probably not a.m. be careful about what you call input and output most of this kind of follows the same pattern down here this is kind of a strategy I use when I have like files that are extra to the Python toolbox so right I had layer files and I needed to create my symbology so I just leveraged pythons file attribute here and then kind of worked from that to find one of my layer file is so just like in a script tool where I actually put the full path in here here I just kind of do it on this kind of relative strategy now at the end of all that the only key is you got to grab all those parameters back up or turn them back as a list all right once you've got that that kind of is what defines kind of your initial experience with the tool all right so I kind of like to think of validation as kind of being two different things at the same time you know we went through there and kind of defined these parameters right just by kind of defining that you sort of get what I call kind of this basic or like free validation right the data type itself just kind of gives you certain behaviors right if it's a you know feature layer you can't take a tape well that you can't take a table right there's this kind of these built-in behaviors that you get for that you don't have to code for those right the data type itself and other characteristics just so the parameter definition are going to do that kind of stuff for you so right now like these does the input exist right the data type we talked about you know if we have a filter applied to that does the the input or the value respect that filter but then there's the second part which is more of kind of the additional rules this is more of now more the coding side of it now this is where we get into come to these kind of more detailed behaviors I guess so where you want to have interaction between parameters like you have you know this parameter over here and it's an input and you want to calculate something based on that and stick it in a different parameter right or you know this parameter if it's set that that value will enable this parameter kind of those kind of relationships you know putting in kind of more stringent errors right if you know you don't want this situation to apply you then want to put in a parameter error on the dialog that happens and it's also kind of a place where we can make tools work better in model building now when we break down validation it really kind of comes down to this this kind of subset of things so I kind of like this to see it it's really usually about well the values right so there's parameter objects that we deal with had some of these key properties so you look at value or the values text it's just you know one does it have a value you know what is that value and you can use things like describe describe and get more data properties now one note about the scribe under if anyone's ever been trapped by this describe is is a nice function because in some ways when you're working with a script tool you know our Python tool looks tool you may be say you're using that tool in model builder the describe might get called on dated it doesn't actually exist yet right you have this chain of tools validations getting fired well you know nothing's actually run that data set you're describing does it have now it doesn't actually exist right so describe candles that case a little bit better for you some other functions like you know they like list fields don't have that characteristic built to it so the scribe is kind of the heavy lifting function that we use in validation code we also look at altered quite a bit and then has been validated as well so really it's kind of what juggling these properties as well as describe to make it flow so here's kind of a couple examples kind of highlight some of these cases a little bit the first one is kind of this scenario where we have one input and we're calculating sort of a default based on that for another parameter right so we start off this by checking whether the primers of value right so this isn't going to the rest of the code right doesn't get fired if you know someone hasn't actually populate of that parameter yet this is a good check to have in this case because what I'm going to do right is I'm calculating a value and I want to stick it over in this other parameter I don't want to have someone actually physically type in their own value and then you know immediately stomp on it right so altered is a property that we can use to guard against those kind of situations and then after that right I'm just describing the data and then applying the value back onto the parameter now actually see right here I have a comment on this but I'll wait until the next flight on it this is actually a better strategy than that right there the parameter value thing okay now the other thing that validations sometimes well has a lot of value to me for is you'll get into situations where you got some kind of data scenario situation but there really isn't like a data type that matches you know perfectly with that so I tend to use and abuse a string data type a lot for those kind of situations right because string by definition right it's either and as a value or doesn't have a value right there's not a lot of fancy checking going on there right so you know I can put in and evaluate it and Tara gate it in any way I want without having any other data type in a validation kind of getting in my way so the reason this little bit of code came up I wrote a tool few years ago and what I had was this little simple like G or SS fee I think it was a USGS kind of earthquake thing actually that I was using and essentially I wanted to do someone that the pack in the URL for that and then Tara gated but a one who wanted to do was they would put that in my string parameter and then I'd had another parameter that was essentially look kind of like a Gutfeld picker like a drop-down you know or actually know this with a multi-value so you could pick multiple fields right now that relationship now doesn't really exist right so I have this string parameter I pack in a URL all right it reads it and I read it through this module called feed parser right beep Irish or just little third-party library and it can read in this feet so all it does is kind of reads that feed and then kind of pulls through and looks at the attributes in that feed and then at the end here I'm creating a filter list right so that will then populate a list of all most fields that someone could pick and choose from all right so another thing what followed that exactly but I wanted to say is that string parameters are referring data types are a really useful thing for kind of you know adding those extra bits in there when you don't have a date that really fits for what you need now one thing about parameters and parameter values so you can see in kind of the upper part of this code right I'm accessing you know parameter 0 dot right the parameters are right this is a zero-based indexing so if this is some kind of data source like strictly like a like a layer in particular this hit is a look at the time hit and getting the dot value all right it's not as noticeable in arcmap but it's definitely there in arcmap and more pronounced than pro so we added or changed slightly at ten for one and then pro one one so that you can describe the parameter object directly so instead of you know doing this you know hitting dot value actually once twice you know hitting that a little bit of a lag you know I can just hit the parameter itself and kind of bypass that so it's a little strategy to kind of minimize the hit of your validation caused but that's that the dot value hit is really only for like data source right layers if you're just doing strings numbers whatever else simple stuff on same thing now we kind of have these trio of validation steps there is this update parameters which we just talked about and then there's this internal validation stage and then that's followed by update messages the order is kind of important and well this is the reason why so in update messages we're mostly dealing well with messages right sometimes and I make this mistake myself sometimes too is that you're doing all this handling and update parameters and then you start playing up the messages as well if you're doing if the message is an update parameter the internal validation stage come after that essentially is going to kind of unvalidated revalidate your stuff so you might actually make a correct looking call on the messages but it's going to disappear on you before you even saw it so make sure you get that the messages type handling in the actual date messages now I kind of two scenarios here typically you're going to have more the topcase or what we're doing is just evaluating different parameters and what their values are and saying oh this is an error or this isn't an error right so this little bit of cocaine from a tool I wrote that had it was a long value and I was tricked one option would have minutes was slow this right and it would have been like I used it both as like a percentage range and as like a six number right so it's kind of trying to juggle maybe being too smart so what this is doing is basically just looking at the numbers that I have and then evaluating them and then adding a message if it falls outside of my criteria right usually in something you're doing an update messages is you know pretty simple like hip checks now the other thing that you can do and I don't do this is often but late a situation came up about a year ago where somebody had a parameter that was essentially just a list of keywords right there's three or four keywords maybe they're trying to be too smart to but they wanted to be able to pass in like extra stuff that wasn't just in that keyword right normally a keyword parameter you well one of those keywords or not so what this did was I'm essentially just checking to see if this parameter has an error and it does have an error this is the likely error that it's going to be right that's a standard GP air you're going to get one you have a keyword that doesn't belong to the actual filter list so I'm just essentially then saying okay not an air anymore I'm just going to I'm going to convert it to a warning message instead so you'll still see a little bit of something on the dialog but it's kind of a way of now slipping in or bypassing the more the six rules that we have on the parameter itself now like I said the top case is usually where you're going to be when you're dealing with messages now the last part of a validation is kind of the model builder kind of scenario so when you're dealing in model builder right it's kind of an interesting premise where you have now you're going to chain a bunch of tools together right and alright it's kind of like a visual programming right that's what it is but you know you're connecting tools to write this is this one but if I connect the whole string of tools together you open any particular tool dialog it's going to have some kind of information somehow there about the data that's going to exist right like you're going to be able to pick fields you know certain characteristics of what the data is or kind of there well this kind of happens through the schema right so you know say and this is the case right here I have I had a tool that had my geometry was was lines and the input was points or the elbow is pointing sorry right input line output points and want to kind of make sure that subsequent tools know that's actually what's going to happen so what we do and this bit of code is from the Python toolbox we're creating a pram or dependency between those two parameters we clone the schema and then we simply kind of educate the schema that about what we're expecting to happen right so I'm changing the geometry over to point there's a number of rules about what the fields are going to look like and then I know you know I wrote this tool right there's going to be this extra field on there so I cleared a field object populate some stuff and then I pack it on to this additional fields all right so now even if this is you know like 207 out of a 22 chain you know any tool that happens to be after that and it's keeping those fields will see the field that I added all right so it's kind of a useful experience in kind of making your tool work well now I one caveat to all that you know friends of what you're doing your tools for right if you've got kind of your your tool and it's just for you know you and the guy next to you now maybe you don't worry about the the schema model builder experience too much but if you're creating a more generic tool you know you're definitely going to have people that are going to be using it in things like model builder then that becomes more important all right so I'm going to continue on kind of what we were working with before now right there's this tool here and this isn't a very you know complicated tool I just got four inputs but there's a couple of things that you know potentially can go wrong here you know this is actually going to be added or you can see on the side right that became part of my output name this is just a string parameter right somebody could be goofy you're just not thinking hard and right and they put in a bunch of characters that aren't going to work right and it's going to fall down somewhere right well I could guard against that but I hadn't yet right this is a you know Z factor right certain Z factors are okay or not right so you know negative five is no good right we want to guard against some of these kind of situations so I open two over here and right both script tools and Python toolboxes will have these two function Rises and update parameters and update messages you don't have to put anything in here you can leave them blank if you need to now so those two cases let's look at the prefix first so the prefix was that was parameter index two you know I don't always do this sometimes though in here right you get kind of confused about what parameters are actually which so I try to when I remember to actually kind of define it better not just all its parameter zero so let's assign it to that let's say the workspace is also something we're going to need now so eventually right I'm going to say if prefix has a value and the workspace has a value I'm going to call this function called validate a lame I'll table now the table name works really well for this all I need is a string which is my prefix and then a workspace which I have as well oh this is a pretty straightforward one we're going to just say my parameters two value is going to update based on that okay now come back to the front end and a little bit but the other thing I want to watch for is that that numeric value now there's one little catch here right so zero negative one you know any negative value or bad no value is actually okay right which kind of would become none right trouble there right if I'm just doing simple it check and I want of the value might not get what I want so I'm going to handle this as these primer tree yeah value as text because then you know right I'm actually doing with rings all right right that's a easier check all right so I'm just going to do I'm going to check if I have value it's not empty then I'm going to say right if look right make sure that that is not less than one and then it's just a matter of going out of my parameter and then adding new message all right and that could be whatever I want all right okay now I go back to my map now it's pretty easy to bring your changes back in in Python toolbox it's just a refresh all right so this is one place where I really like Python toolboxes over script tools just because if you build script tools you have more of this kind of bouncing around thing you can actually look at your your source code for the validation at the same time that you're kind of fiddling with the dialogue here you can you know conceivably put them up side by side and just kind of refresh when you need to see it all right so this is that updated tool now to get the behavior on this right actually also had to have folder or workspace already put in and then if I type in some rubbish again right okay and that triggers that validation just shorten that and then of course here right one is fine zero should be not fine though anyone see what I did wrong no they're all in trouble now now what did I do here ah okay all right now does it make any sense all right we've got that I come back in here come back to this fresh that and now I didn't make a other mistakes right okay so it's kind of really just that right you're evaluating values comparing them with something else right little hip check some of you create your error messages all right okay go back with a slide all right so inside the code it open to this point we mostly been looking at really kind of what this wraps around your code the few little things that we just got to keep in mind that kind of make the experience work so we get parameters which we saw a little bit of already we can use get parameter their parameters text Python toolbox very similar you're doing with the parameter objects directly though so it's about your values tags and then we sell the dry primer as well so the inside block kind of what I called the internals so there's some simple calls like you know add messages I had warning we also had something called a progressor which we'll look at briefly in a minute but the one thing I want to kind of train your attention on is how did how we can deal with cancellations this is something a little bit more recently them talked about kind of a dev summit very much so kind of the history of that history of this so by default and historically if you you cancel a tool kind of when it's in mid process right someone starts up your tool they type in some stuff hit OK right I realized oh oh right you know I was wrong right so cancel so what happens by default is that just really who cancel at the end of the current line that you're on in the code wherever it is but it's like a hard cancel all right you don't have any opportunity to kind of interact right it cancels and the tool finishes and it's done right you may be in the middle you made something you had all these intermediate data sets you might need be rolling something back you know any number of these little kinds of things you really have no option right the script you're just done but we can manage that with these two environments and I'm going to step back show how that works so I thought about just kind of make retrofitting this into an existing demo but I couldn't find a way to make it look that good so that didn't really fit so I have this kind of little funny tool that I great I wrote so what I'm going to do here I click this line so that's going to give me basically the existing default behavior I'll go and look at the common denominator button so what happens here starts running not really doing anything real in here right let's cancel it okay so this message here this is there's nothing meaningful here right this is just hard cancel thank you very much and you're done right we can do a little better than that if we come in here it's kind of managed by this setting all right so right by default we want well I default it's it's true we want to turn that off so I'm kind of managing through the parameter now you're not typically going to do this right if you're doing this canceling stuff you're just going to go up to the top and you're going to say arc I and V Auto canceling equals false but in here what happens is you know if something someone goes and canceled it what happens is this setting this gets flipped right nothing else right tool keep working and I'll keep doing its thing but I could then put in a check and say you know if that's been set to true now now okay now I can I'm looking forward I'm going to deal with it kind of on you know my time right in the way that I want so I set it up I'm just going to raise the keyboard interruption keyboard interrupt exception then I can do all the things I would normally do in my code right I can go in I could handle that hair I have a finally in this case because no exceptions happen and I would put any kind of cleanup type actions in there right so if I go back because I should see how this runs all right now if I run this and keep that off I don't let that run a little bit cancel all right so let's see now is now it's kind of on my schedule right that's my message and you clean up I wanted to do what happened right there and then you know at the end you'll get this sort of generic message but everything is here that's all mine right it's all my control if I wanted to roll back so you mean if oh well how do you roll back a process so well I've depend on what you're doing if you're like making like edits to like that kind of mean like you're you're you open some data source and you're making edits against it like a cursors yeah okay so we have I have a session actually in this room tomorrow the same time so there's a there's an editor class that we have you can open an editor on a workspace and then you basically manage those kinds of things so yeah that would be kind of a situation where you could do that there before you kind of we're at the mercy of whatever happened but yeah you could put in an editor you could handle it you could you know roll it back if you want it now we have had for several releases the ability to kind of encrypt your source if you a script tool right so honestly promotive is sometimes it's kind of a little hidden thing here but you can import your script and you go up and you can set a password right so you got something in your source code you wanted to protect it you know you don't want prying eyes on it right that's something you could do probably not toolboxes that was kind of one little difference we had well we have the option now for that as well so you get into scenarios where you want to encrypt that all right it's just a matter of right encrypt it put in some password and it'll basically encrypt it in place right if I go over and I think I had that open somewhere all right yeah right that's the measurement right it's no longer just that PYT files you can pull open right it's this stuff so it in you know we can do through the the UI if you want you can also we have a couple functions that'll do same thing so you want to encrypt or you want to decrypt tool box right you can reverse that pretty easily as well I can't help that it's my favorite default password I don't use it for real though all right so I go back and yeah that's heritage right so it's restored in back and I didn't actually run the tool but you know it's not going to impact right so it's not just encrypted and hitting with it it's an actual functional Python toolbox ID you can use and work with now one see where your time okay so right when we have a tool box in whichever one we choose scripting and traditional tool box or a Python toolbox this kind of get to this point where you know how do you kind of hand that off to somebody else right you have you know I guess they're all files right you could just take them get them up you could put them on a share somewhere someone can you know however they want to manage that I guess that's sort of up to them right you have some collection of extra tools you you know time you run a tool you could actually share that as a share the result from a tool you run you know all these things are okay but kind of awkward if it's like a toolbox you want to give to like a bunch of people and you kind of wanted you want to just be a like any other tool does right you don't want it as this kind of second-class tool box that sits over here and then got to find it and remember it so we have this experience where you can essentially bring in your toolbox and make it look like and behave well I'll say look like a regular toolbox right they already behave like a regular toolbox so let me step through kind of this process so I have I kind of took what I had kind of built up and I kind of put everything in this other folder and that is where is that it's over here so what I did is I took my toolbox and I kind of made a little package like a Python library around it now this is a pretty dumb with a library but so but it's got a good stuff in it so I called it just my demo and then right so it's a little Python package so I have this little in this file it doesn't do very much but you know you could put add more to this now inside here I nested inside this every folder toolbox folder this is all the stuff I had right this is a Python toolbox file you know these extra files here right these are XML to help information if I went through and created help right these files just kind of get auto-generated when you create your toolbox I'm still 91 and then right you see I have scripts right that was that file I called out to and I have the lair files a right so I got everything kind of packaged up it works pretty well just on its own now what I want to be able to do is create for someone you know basically hand this to them and you know have it be like a full system toolbox so we have a little function it's sort of hidden away a little bit but it's called arc pie under GP hidden away here I might never get it right so create toolbox for files okay and where is that file and way under hearing all right so if I populate or take that slide it over to this function all right it's going to go and generate some extra stuff for me that extra stuff find it under here all right it's kind of some of these extra supporting things right so basically it's creating like if one thing is I can arc PI wrapper around that right so we have tools other tools you call through our PI right there wrappers built around them well that's what this is and then there's some supporting help information that was created from what I had now I'm actually I'm going to drop this over here and drop it back in over top okay so then I have this little setup file go in here alright just was kind of a little python thing I know if you ever dealt with creating your own libraries this is kind of just some kind of boilerplate type stuff you do basically right I'm just kind of identifying the package and then all the extra parts to it so what happens now I can go now if you want they want stable this one this is pretty straight pretty simple what I could also do is like this one and I could just take this collection of information and I could just pop it into pythons site packages right I don't necessarily have to do this step but what I could do here all right so let's call a Python what we're going to do I'm going to run my little setup file and install it alright so does a little bit of stuff moves everything into place and actually I'm going to close that and it's open our fresh one so what happened there when I ran that it just takes everything I had and drops it under here all right so I'm at Python command line all right there's that package right I guess it's not at all right there it is now nice thing about that now when arcmap pops back open it always takes longer when you're watching what's up what version is this in and then note well I got my trust hey Bill here at the back when did we add that and - all right so now right the thing about this is anywhere I want to go looking firm tools you know there it is right just shows up like it says system toolbox right and no one asked to go look for and find it it's just it's just there up everything else in our toolbox windows same thing if I went into arc by alright doesn't have to be inside the output alright there's that toolbox module and there's tool alright so I could just use it from here as well so it's really kind of about like a big finishing touch for your toolbox ride you have tools you producing you got some clients somewhere maybe that you're handing these off to you this is kind of a way of just kind of sliding it in and and look you know easy to find and you know looks more seamless alright you know a little session later on who covers kind of that concept a bit and more and some other related topics so you want to follow up on that kind of new Python module side a little demo theater tomorrow but a little later in the afternoon ok talk about that now a couple little last considerations I kind of want to add I put in your mind so when we create these tool it's kind of want to nice things about the Python base stuff is that you don't have to worry about like maintaining different color bases for two different products right script tools and pilot alysha's create just a little bit of work you can put in both products and have them you just work right now that's top arcmap all that stuff python 2 pro is Python 3 and there's a few little things in here what you do you can just run this tool so there's an analyze tool for pro run that on your source code you can run out on toolboxes and it will flag anything that you know might be something you need to look at there is a setting that we have - it's off now at 1/4 by default right this is checked on what happened is every time you run when your tools it's going to do all that kind of check so that's a little bit of it well it can be a bit of a cost so I'd recommend is turning it off running this tool on your stuff first I'm just going to deal with it right up fine I haven't talked much about services so much there are some kind of special considerations or you know there's extra information about that there's another little demo theater that we have tomorrow you want to interested in that kind of information now I'm virtually at a time I'm a time to talk too much about this but I kind of want to just expose this idea to you that I mean Python does support bringing in stuff from other languages so you know you have some code that you've written in you know CEC puts class whatnot can use modules like C types and Python to kind of bring that in right you know I focused mostly on Python and the building the Python toolboxes the script tools is kind of building the experience but I mean you can doesn't have to be all Python right you can write it somewhere else and kind of bring it in use Python as the glue the glue language essentially to bring in these other pieces if you're interested there's a little repo here that we created I guess the boat year ago that kind of runs through a case and how you set that up all right I'm done if you have any comment you know they always have help thank you [Applause] [Music] [Applause]
Info
Channel: Esri Events
Views: 16,635
Rating: 4.932961 out of 5
Keywords: Esri, ArcGIS, GIS, Esri Events, geoprocessing tools, Python, script, geoprocessing
Id: nghtMu11BXM
Channel Id: undefined
Length: 59min 4sec (3544 seconds)
Published: Wed Mar 29 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.