Scenario The Fire Department of the City of Orlander needs a count of all the single-family homes and multifamily structures in each of the 44 fire response zones. The secretary in that...

Please complete the required scripts on the attached PDF.


Scenario The Fire Department of the City of Orlander needs a count of all the single-family homes and multifamily structures in each of the 44 fire response zones. The secretary in that department is trying to complete this task with a felt-tipped pen and an aerial photo. You see that she has already missed a few structures, misidentified a few, and is spending an inordinate amount of time on this project. As a new GIS Specialist, you are charged to write Python scripts that will be faster and more accurate. The Fire Department’s geodatabase contains a polygon feature class for each response zone, or box. The secretary has already added the fields to a portion of the feature classes, but the rest of the classes do not have these fields. Task One: You will write a script (geo_project1.py) to 1) add two fields to each box: one for the single family count (SFCount) and one for the multifamily count (MFCount), 2) count the single-family homes and multifamily structures falling within each box, and 3) print the counts for each box and write the counts into corresponding fields. Since the script will call some functions that will also be used by Task two, you will need to create a module (geo_functions.py) to maintain those functions. Task Two: The Fire Department will do periodic counts of other building types in a single box on an as needed basis. You will write another script (geo_project2.py) that gets a box number and a building code from the user to decide what box to work on and which building type to search for. The resulting building count will be stored in a new field with a predetermined name (below) and be displayed in the Python console. You will add additional functions in the geo_functions module for this task. Because the building count will differ as the city changes, it will be helpful to run this script to get fresh counts each time. Data The Fire Department geodatabase contains 44 feature classes representing the box zones. The fire box feature classes in the database are named as “FireBoxMap_” followed by the box number. The database also contains a building footprintsfeature class that carries a UseCode field. Strategy For Task One, you will list all fire boxes and use each box to count single-family homes and multifamily structures falling inside it. You need to use a loop to iterate over the boxes. For each box, you will perform three tasks: First, you will check existence of fields SFCount and MFCount. If any of them does not exist in the box feature class, you need to create the field. Second, you need to count the single-family homes falling in the box. To do so, 1) you need to use the MakeFeatureLayer() tool in the management module to create a feature layer object from the building footprint feature class. This tool requires an input feature class and a name of the output feature layer. For this project, you need to specify a where clause to define a specific building use code (1 or 2) when making the feature layer, so that when you use a box to select buildings in the next step, the specified type of buildings (SF or MF) will be selected. 2) You need to use the SelectLayerByLocation() tool in the management module. This tool allows you to specify an input feature layer (created in previous step), a spatial relationship (“HAVE_THEIR_CENTER_IN”), and a selecting feature class (a fire box). 3) Once desired buildings are selected in the building feature layer, you can run the GetCount() tool in the management module to get a count. Finally, to write the count into an appropriate field in the box, you need to create an update cursor to get the job done. To get started, you need to use a loop to iterate over the fire boxes in the main module (geo_project1.py). For each fire box, you may write all code that carry out necessary tasks under the loop. Once the script works, you can then gradually move portions of the code into functions and call these functions when specific tasks need to be performed in the main script. You may also start with creating and testing the functions. Once all functions are ready, you can call them in the main module to accomplish the tasks. You are required to create the following three functions in the geo_functions.py module for this part of the project. • FieldExists(fcname, fieldname): This function is intended to check if a field name (the second parameter) exists in the specified feature class (the first parameter). It should return a Boolean value (True or False). • CountBuildings(bldgfc, bldgcode, boxfc): This function is intended to count the number of buildings of a specified code (the second parameter) falling within a box feature class (the third parameter). Actions to perform by this function include making a feature layer object for the buildings feature class, executing SelectLayerByLocation tool to select buildings, and calling GetCount tool to get the count of the selected buildings in the feature layer. Finally, it should return a count number. • WriteBuildingCount(fcname, fieldname, count): This function is intended to write a count into the specified field of the specified feature class. For Task Two, the main actions for a specified box are the same as Task One, but you do not need to use a loop to iterate over all boxes. You will let the user to enter two arguments, one for a box number and the other for a building code. Please use the arcpy function GetParameterAsText() in the script to get the two required arguments from the user. Once the above three functions are created, the main actions of this task can be greatly simplified. However, since this part involves user inputs, validating user inputs to avoid crashing by exceptions is important. You will need to write three more functions in the geo_functions module: • ValidateInputs(boxnumber, buildingcode): This function must check the following and return a Boolean value True or False: 1) If argument boxnumber is not a number, return False 2) If it is a number, then check if it is between 0 and 43 (inclusive). If not, return False 3) If argument buildingcode is not a number, return False 4) If it is a number, then check if it is between 1 and 8 (inclusive). If not return False 5) Make a fire box feature class name based on the box number, e.g., "FireBoxMap_1". If the feature class does not exist, return False 6) Finally, if all the above checks pass (without returning False), return True • GetFieldName(buildingcode): Given a building code (argument), this function should return a field name for the count of buildings. The function will be called when creating a new field in the fire box feature class. For example, if argument buildingcode is 1, then the function will return “SFCount” (see table on Page 1). • GetBuildingType(buildingcode): Given a building code (argument), this function should return a building type as a string based on the table on Page 1. It will be called when printing out a building count in the Python console. For example, if argument buildingcode is 2, then the function will return “Multi- family” (see table on Page 1). Like Task One, you may start with writing all code in the main script (geo_project2.py). Once the script works, you can then move blocks of code into functions and call the functions in the main module. However, I suggest you to start with creating functions before writing the main script. Each function can be tested separated. With all functions created, the main code of geo_project2.py will substantially simplified: 1) set up an environment 2) get a box number and a building code using arcpy function GetParameterAsText() 3) validate the user inputs 4) create a fire box feature class name based on the user provided box number 5) create a field in the fire box feature class based on the building code (if the field does not exist) 6) call function CountBuildings() to count buildings of a specified code falling within the fire box 7) call function WriteBuildingCount() to write the building count into specified field of the fire box 8) print result in the Python console Submissions: • geo_project1.py • geo_project2.py • geo_functions.py • Make sure your scripts are fully documented and adequately commented
Dec 13, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here