8138 ArcGIS 3 Review – Flashcards
Unlock all answers in this set
Unlock answersquestion
arcpy.AddMessage Method - informative message arcpy.AddWarning Method arcpy.AddError Method |
answer
What kind of error messages are there in arcpy? |
question
specific, non specific, licence checking |
answer
type of error checking: |
question
What kind of error messages are there in arcpy? |
answer
arcpy.AddMessage Method - informative message arcpy.AddWarning Method arcpy.AddError Method |
question
type of errors: |
answer
syntax, execution, errors you raise yourself |
question
How does GetMessages work?(index) |
answer
GetMessage(index) Returns a string of all messages from the last geoprocessing tool executed |
question
How does GetMessages work? (severity) |
answer
GetMessages(severity) You can filter messages based on error severity |
question
How does GetMessages work? |
answer
messages only, use 0 warnings only, use 1 errors only, use 2 |
question
How does a try statement work? |
answer
the try clause is executed, if no exception occurs, the except clause is skipped and execution of the try statement is finished. If an exception occurs during execution of the try clause, the rest of the clause is skipped. If it’s type matches the exception named after the except keyword, the except clause is executed, and then execution continues after the try statement. |
question
How do you check an extension in / out? |
answer
arcpy.CheckExtension() - to see if a license is available to be checked out arcpy.CheckOutExtension() - to retrieve, and lock, a license from the license manager arcpy.CheckInExtension() - to return a license to the license manager |
question
What is an arcpy class? (not python class) |
answer
It can be used to create objects, often referred to as an instance. SpatialReference and Extent are examples of arcpy classes, arcpy classes are often used as shortcuts to complete a geoprocessing tool parameters. arcpy includes several predefined classes, including SpatialReference, ValueTable, and Point. Once instantiated, its properties and methods may be used. Classes have one or more methods called constructors. A constructor is a method for initializing a new instance of a class. |
question
What is a method? |
answer
A piece of code that is called by name and that is associated with an object |
question
What is a function? |
answer
A piece of code that is called by name |
question
What is a class? |
answer
Collections of data and functions that can be used over and over |
question
How do you return a value for a function? |
answer
def test_value ( number ): if number == 1 : outputs = ' Value is 1 ' return outputs < == ?else: outputs = ' Value is not 1 ' return outputs < == ? Test = test_value (3) |
question
What is a python Class? |
answer
Collections of data and functions that can be used over and over - capitalized by convention, end line with a colon |
question
How do you create an instance of a Class? |
answer
By assigning a variable name to it. x = MyClass() To apply a function to the new instance, you must use a fully qualified name --instance.method() x.hello() If the method takes an argument, be sure to include all needed values. x.math(2,4) |
question
What can you do with the arcpy.mapping module? |
answer
Allows you to open and manipulate ArcMap map documents (.mxd) and layer files (.lyr). You can open map documents and layers; query and alter the contents; and print, export, or save a modified document. Allows for more than just batch processing manipulate maps, layouts, and layers through Python scripting Managing map documents and layers Printing, exporting, map automation and creation of map books Publication to ArcGIS Server |
question
How can you get a list of dataframes for selection? |
answer
The line of code below gets a python list. [0] gets the first data frame in the python list it finds that has Transportation in the name. |
question
If you have 3 data frames that have the word Transportation in it, it would grab the first one in the list. |
answer
df = arcpy.mapping.ListDataFrames(mxd, "Transportation*")[0] |
question
If you wanted the 2nd data frame, you would use: |
answer
df = arcpy.mapping.ListDataFrames(mxd, "Transportation*")[1] |
question
If you wanted "Transportation" only. An alternate approach: |
answer
for df in arcpy.mapping.ListDataFrames(mxd): if df.name == "Transportation": do something |
question
Code example from exam review: import arcpy mxd = arcpy.mapping.MapDocument(input.mxd”) df = arcpy.mapping.ListDataFrames(mxd) df.scale = 24000 df.rotation = 2.7 for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == “landuse”: lyr.visible = True lyr.showLabels = True lyr.saveACopy(“output.lyr”) mxd.save() del mxd -What is the name of the mxd? |
answer
“input.mxd” |
question
Code example from exam review: import arcpy mxd = arcpy.mapping.MapDocument(input.mxd”) df = arcpy.mapping.ListDataFrames(mxd) df.scale = 24000 df.rotation = 2.7 for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == “landuse”: lyr.visible = True lyr.showLabels = True lyr.saveACopy(“output.lyr”) mxd.save() del mxd -What does the “for” loop do? |
answer
“Checks for layer called landuse then turns on labels and visibility then saves a copy to output.lyr” |
question
Code example from exam review: import arcpy mxd = arcpy.mapping.MapDocument(input.mxd”) df = arcpy.mapping.ListDataFrames(mxd) df.scale = 24000 df.rotation = 2.7 for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == “landuse”: lyr.visible = True lyr.showLabels = True lyr.saveACopy(“output.lyr”) mxd.save() del mxd -What does “del” do? |
answer
“Releases memory storage of mxd” |
question
When can you use “CURRENT” in arcpy.mapping? |
answer
when you are working with ArcMap session only |
question
When you update some Map Frame parameters in arcpy, will the changes appear automatically? |
answer
“No, you need to update/refresh the screen: arcpy.RefreshActiveView() arcpy.RefreshContents() |
question
What is the purpose of [0]? |
answer
to get the first list element from the list generated by ListDataFrames: df = arcpy.mapping.ListDataFrames(MXD)[0] |
question
What is def __init__ ? |
answer
-always the first function / method -is a constructor, it runs when an instance of a class is created |
question
What is a widget in Tkinter? |
answer
Widgets include things like windows, buttons, menus, menu items, drop-down lists, scroll bars |
question
What is an event handler in Tkinter? |
answer
- Routine that does the work of the GUI... or a callback routine that handles input received in a script- code executed when an event occurs - binding associates this event handler with a widget.events include:etc. |
question
What is the purpose of packing? |
answer
To orientate button placement. The default is to "pack" buttons (widgets) one above the other Packing options are LEFT, RIGHT, TOP, and BOTTOM |
question
What is the difference between button and Button? |
answer
button is the "name" of the widget. Variable definition |
question
What is the difference between button and Button? |
answer
Button is a standard Tkinter class |
question
How do you define a global variable? |
answer
variable that can be pulled and used by different functions and methods |
question
What are different ways of assigning parameters to a button? |
answer
self.button1 = Button(self.myContainer) self.button1["text"] = "Hello World!" self.button1["background"] = "green" self.button1.pack() |
question
What are different ways of assigning parameters to a button? |
answer
self.button2 = Button(self.myContainer) self.button2.configure(text="Off to join the circus!") self.button2.configure(background="tan") self.button2.pack() |
question
What are different ways of assigning parameters to a button? |
answer
self.button3 = Button(self.myContainer) self.button3.configure(text="Join me?", background="cyan") self.button3.pack() |
question
What are different ways of assigning parameters to a button? |
answer
self.button4 = Button(self.myContainer1, text="Goodbye!", background="red") self.button4.pack() |
question
What is “binding” |
answer
"Binding" is the process of defining a connection or relationship between: a widget, an event, an "event handler" Events that can be bound: |
question
what are some events that can be bound? |
answer
The mouse is moved, with mouse button 1 being held down. Button 1 was released. Button 1 was double clicked. The mouse pointer entered the widget The user pressed the Enter key. The user pressed any key. |
question
Describe a listbox |
answer
The Listbox widget is a standard Tkinter widget used to display a list. A listbox can only contain text items, and all items must have the same font and colour. Depending on the widget configuration, the user can select one or more items from the list. |
question
What are some parameters of a listbox |
answer
parameters: listbox = Listbox(master, selectmode=SINGLE) SINGLE - (just a single choice. Default mode.) BROWSE (same as SINGLE, but the selection can be moved using the mouse) MULTIPLE (multiple items can be chosen, by clicking on them one at a time) EXTENDED (multiple ranges of items can be chosen, using the Shift + Control keys) |
question
How does a scrollbar work? |
answer
When the widget view is modified, the widget notifies the scrollbar by calling the set method. And when the user manipulates the scrollbar, the widget’s yview method is called with the appropriate arguments. |
question
What is an Entry widget? |
answer
Used to enter text strings User can only enter one line of text, to enter multiple lines you would have to use the Text widget |
question
How do you apply symbology to a feature class? A tool!!! |
answer
ApplySymbologyFromLayer_management (in_layer, in_symbology_layer) Note: - can only be applied to features of SAME geometry type - Input Layer Field name must be the same as that of the corresponding Symbology Layer Field |
question
What makes a good user interface? |
answer
Simple, Intuitive, respects common conventions, visually organized, native look |
question
What is the grid method? |
answer
Treats a frame as a table (a grid of rows and columns) |
question
Frame coordinates |
answer
Origin of each frame is in upper left corner (0,0) X coordinates increase to the right Y coordinates increase towards the bottom |
question
What are some grid parameters? |
answer
column, columnspan, ipadx, ipady, padx, pady, row, rowspan, sticky |
question
What are sticky parameters and how do they work? |
answer
Cardinal Directions (i.e. N, S, E, W, NE, etc) Can combine directions i.e. N + S > stretches widget out vertically across the cell i.e. E + W > stretches widget out horizontally across the cell |
question
Assigning a title to a Tkinter menu |
answer
define your title in your local variables: Title = “This is my fabulous whatever-you-wanna-call it” then below where you make an instance of your root: root = Tk() app.master.title(Title) app.mainloop() |
question
Adding an image (logo) to a Tkinter menu |
answer
PhotoImage(file = f) to place a logo or a full colour image in your frame Import “Photo Imaging Library (PIL)” for more format availability. Will convert automatically to make it Tkinter compatible |
question
What kind of layout elements can you select? |
answer
GraphicElement: groups of elements, inserted tables, graphs LegendElement: MapsurroundElement: North Arrow, scale text, and scale bar TextElement: inserted text, callouts, rectangle text, titles etc PictureElement: a raster or image that has been inserted into a page layout (logo) |
question
What kind of changes can you apply to layout elements? |
answer
- change elem position X/Y (note units are set as inches... so divide by 2.54 for cm) - can change string values of text elements - can add or remove items in the legend (partially through layer management) |
question
#This script clips all feature classes in a file geodatabase import arcpy # Create path variables sourceWorkspace == "C:DataLesson2PracticeExerciseUSA.gdb" targetWorkspace == "C:DataLesson2PracticeExerciseIowa.gdb" clipFeature == "C:DataLesson2PracticeExerciseIowa.gdbIowa" #all three of the above should only have just ONE = # Get a list of all feature classes in the USA folder arcpy.env.workspace = SourceWorkspace #should be sourceWorkspace featureClassList = arcpy.ListFeatureClasses() try: for featureClass in featureClassList # Loop through all USA feature classes outClipFeatureClass = targetWorkspace + "Iowa" + featureClass # Construct the output path #the above should be “Iowa” arcpy.Clip_analysis(featureClass, clipFeature, outClipFeatureClass) # Perform the clip and report what happened arcpy.AddMessage("Wrote clipped file " + outClipFeatureClass + ". ") except: arcpy.AddError("Could not clip feature classes") # Report if there was an error print arcpy.GetMessages() |
answer
find the errors |