quiz Flashcards
(17 cards)
The variable below stores a shapefile’s name. shp_name = “MO_DOT_2018_03_28.SHP”
Write a code line to extract the substring “2018_03_28” from shp_name using slicing.
v = shp_name[7:17]
The variable below stores a shapefile’s name.
shp_name = “MO_DOT_2018_03_28.SHP”
Write a code line to create a list of strings elements from shp_name with the _ character as the separator using the split function.
l = shp_name.split(‘_’)
what would be the fourth element in the list created by splitting “MO_DOT_2018_03_28.SHP” by _ character
03
what module in arcpy is used to work with cursors
Data Access
Which of the following is the default mode when opening a text file in Python?
Append. Read. Write. b and a.
Read
When using update and insert cursors, what do you have to do to avoid data lock situations?
Delete the cursor variable
You are copying shapefiles to a geodabase with the line below, where the a_fc variable represents a shapefile with the format “finaName.shp”, and the_gdb variable represents the full path and name of a geodatabase. A workspace has been defined and corresponds to the location of the a_fc shapefile. The line shown below needs a correction; write a second code line that shows the correction.
arcpy.CopyFeatures_management(a_fc, the_gdb + “\” + a_fc
arcpy.CopyFeatures_management(a_fc, the_gdb + “\” + a_fc.replace(“.shp”, “”)
Name the 3 types of cursors from the Data Access module in ArcPy.
Search, insert, update
You need to create a new feature class from an original feature class with 100,000 records; the new feature class should have only the records that satisfy an attribute criteria. What Python script option would you use from the list below as the most efficient?
Create a new feature class; use a search cursor to read all the fields with the criteria; and then use an insert cursor to add records to the new feature class. Do a select layer by attribute on the original feature class to select records by the criteria, followed by a copy features step to create the new feature class.
B
What is the main difference between an attribute table from a feature class and a standalone table when it comes to geometry?
Stand alone table doesn’t have geometry
s_cursor = arcpy.da.SearchCursor(fc, [“ID”, “SoilType”], q)
for s_row in s_cursor:
u_cursor = arcpy.da.UpdateCursor(table, [“soil_type”])
for u_row in u_cursor:
u_cursor.updateRow(u_row)
del u_row
For the above loop, what would you type if you wanted to set the value of the field soil_type equal to the value from the field SoilType?
u_row[0] = s_row[1]
s_cursor = arcpy.da.SearchCursor(fc, [“parcel_no”, “owner”, “type”], q)
for s_row in s_cursor:
u_cursor = arcpy.da.UpdateCursor(table, [“block”, “tract”, “par_no”])
for u_row in u_cursor:
u_cursor.updateRow(u_row)
del u_row
del u_cursor
In the update cursor for loop above, what would you type if you wanted to set the value of the field par_no equal to the value from the field parcel_no?
u_row[2] = s_row[0]
Choose the correct statement from the options below regarding a Join operation:
It is done in the hard drive, the field names change, and to keep the new field names and the join you must export the joined data to a new feature class. It is done in memory, the field names remain the same, and to keep the new field names and the join you must export the joined data to a new feature class. It is done in memory, the field names change, and the joined data in memory will be kept so there is no need to export the joined data to a new feature class to keep the new field names and the join. It is done in memory, the field names change, and to keep the new field names and the join you must export the joined data to a new feature class.
D
The Python code lines below will create the text file “file.csv”.
txt = open(r"d:\temp\file.csv", "w") txt.write("a, b, c\n") txt.write("d, e, f\n") txt.write("g, h, i\n") txt.close()
What variable represents the text file you are creating?
txt
The Python code lines below will create the text file “file.csv”.
txt = open(r"d:\temp\file.csv", "w") txt.write("a, b, c\n") txt.write("d, e, f\n") txt.write("g, h, i\n") txt.close()
What is the purpose of the \n characters
newline
The Python code lines below will create the text file “file.csv”.
txt = open(r"d:\temp\file.csv", "w") txt.write("a, b, c\n") txt.write("d, e, f\n") txt.write("g, h, i\n") txt.close()
after executing what is the third line in the file
g, h, i
The Python code lines below will create the text file “file.csv”.
txt = open(r"d:\temp\file.csv", "w") txt.write("a, b, c\n") txt.write("d, e, f\n") txt.write("g, h, i\n") txt.close()
if there is a preexisting file in the same folder with the same name, what will happen to it?
it will be overwritten