Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment you will be implementing a portion of a Geographic Information System (GIS). A GIS is a computer system used to organize, categorize,
In this assignment you will be implementing a portion of a Geographic Information System (GIS). A GIS is a computer system used to organize, categorize, and analyze geographical data in order to produce accurate depiction of the real world. The system uses multiple layers of information to achieve this task. The data layers are split into a grid and represented as a matrix with m rows and n columns where each entry in the matrix contains the type of land at that point on the map. An entry Aij is the ith row and jth column in our map matrix. We assume that A00 is the first element in our matrix. The graphic below will assist in visualizing the process: As seen in the previous example, our GIS utilizes 6 different data layers. We call these layers the map types as they classify regions of different land on our map. Thus, each entry in our map matrix can be one of the 6 map types. - Transportation (T) - Agricultural (A) - Residential (R) - Commercial (C) - Water (W) - Undeveloped land (U) Our GIS will store the map information as a list of lists. If we have a list named map, then map[i][] will store the map type at row i, column j. Each entry will contain a string that corresponds to 1 of the 6 possible map types listed above. The list representation of the map in Figure 1 is shown below: [[A,A,A,A,U,U,U,U],[A,A,A,A,U,R,R,R],[W,W,W,WT,T,T,T],[W,W,W,W,T,R,R,R],[C,C,U,U,T,R,U,U],[T,T,T,T,T,T,U,U],[U,U,U,U,T,R,U,U]] One usage of the system is to be able to easily identify whether or not a piece of land (entry in the map matrix) is deemed commercially buildable. A piece of land at Ai is deemed commercially buildable if the following conditions hold: - The entry at Al has map type U - The entry Aij is not on the edges of the map (the first and last rows and columns). - The entry Aij is not adjacent with an entry of map type R or map type A. Note that adjacent entries are entries to the top, bottom, left, and right of the current cell. Based on the criteria and the map representation of Figure 1 , it can be seen that A4,2 is commercially buildable and A1,4 is not commercially buildable. Additional Information (Important!) When using a 2D list, we can access elements around a specific index. Let's define a 332D list, x, seen below: If we define variables i, and j, to both equal 1 for example, then x[i][j] would be x[1][1], which in this 2D list is the integer 5 . We can access elements around this specific index by modifying our i and j variables. We can subtract or add 1 from i to access the elements above or below the original index. Addtionally, we can subtract or add 1 from j to access the elements to the left or right of the original index. To summarize: - x[i1][j] would access the element above the original index. which here is 2 - x[i+1][j] would access the element below the original index, which here is 8 - x[i][j1] would access the element left of the original index, which here is 4 - x[i][j+1] would access the element right of the original index, which here is 6 Be careful when accessing adjacent elements - if you try to access an element that doesn't exist, you might receive an unexpected output, or an error! For example: - x[i2][j] which is equivalent to x[1][1], would wrap around and give us the middle element in row 1, which here is the last row. - x[i][j+2] Would try to access the element at x[1][3], or in the nonexistent colum 3 , which would produce an error seen below! 2print(x[i][j+2]) IndexError: list index out of range Program Requirements (12 Marks) Your GIS system will be comprised of a set of functions used to analyze the information of any given map. In addition, you will be creating a function used to determine whether or not a piece of land is commercially buildable. The requirements of the system are given below. Please ensure that your functions have the EXACT naming as specified! Failure to do so will result in lost marks. 1. Define a function count_type(map_data, map_type): - map_data: A list of lists representing the data for a given map. - map_type: A string representing a map type ('T', 'A','R', 'C', 'W', or 'U') - Return: An integer representing the number of times map_type occurs in map_data. 2. Define a function classify_map(map_data): - map_data: A list of lists representing the data for a given map. - Return: A map classification according to the following rules: - The string Suburban if the number of 'R' cells is greater than 50% of all cells. - The string Farmland if the number of 'A' cells is greater than 50% of all cells. - The string Conservation if the number of 'U' cells plus the number of 'W' cells is greater than 50% of all cells. - The string City if the number of ' C ' cells is greater than 50% of all cells and the number of ' U ' cells plus the number of 'A' cells is between 10% and 20% of all cells (inclusive). - The string Mixed if none of the above criteria are met. (Hint, use your count_type function coupled with the fact that the total cells in map_data is given by m+n ) 3. Define a function isolate_type(map_data, map_type): - map_data: A list of lists representing the data for a given map. - map_type: A string representing a map type ('T, 'A', 'R', 'C', 'W', or 'U') - Return: A new list of lists that represent map_data as a matrix but all entries that are not equal to map_type are replaced with a string containing only a space (" "). (Hint, review the In-Lab Notebook Nested Loops to Process Lists of Lists demo on how to process 20 lists) 4. Define a function commercially_buildable(map_data, i,j) : - map_data: A list of lists representing the data for a given map. - I: An integer representing a given row in map_data. - j: An integer representing a given column in map_data. - Return: True if map_data[1][i] (AI ) is commercially buildable, otherwise False, according to the following rules from our background information: - First, ensure that the entry Aij is not at the edge of the map (the first and last rows and columns). If it is, retum False. (Hint, you will need to find the amount of rows and columns in the map for this step) - Ensure that the entry Aij has map type U, otherwise return False. - Ensure the entry Aij is not adjacent with an entry of map type R or map type A. Note that adjacent entries are entries to the top, bottom, left, and right of the current cell. (Hint, review the additional information section for this step) Implementation Please define all functions in the cell below N \#********************************************* \#******************************************** \# Write your classify_map function below: (4 marks) \#**************************************************** \#************************************************** \# Write your isolate type function below: (2 marks) \#**************************************************** \#*********************************************** \# Write your commercially_buildable function below: (2 marks) Unlike the other computing labs that required you to run main() to validate your code, these functions can act as stand-alone functions. You have been provided with some test cases, but you are encouraged to create more to thoroughly test your code. Important Run the cell where you implemented your functions first and ensure it outputs with no errors. Then, run the testing cell to verify that your code works correctly with the provided input. The following message should be printed after the testing cell is run: The number of U spaces in MAP =17 The number of T spaces in MAP2 =12 MAP Type = Mixed MAP2 Type = City Isolated MAP: U [1,1,1,1,1,U,1,1,1,11] [1,1,1,1,1,1,1,1,1,1,1] [1,1,1,1,1,1,1,1,1,1,11] [', ', 'U', 'U', ',', ', 'U', 'U'] [ ,,1,1,1,1,1,1,U,U] ['U', 'U', 'U', 'U', ', ', 'U', 'U'] Isolated MAP2: T [,,,,,,,,,, ['T', 'T', 'T', 'T', 'T', ', ' '] [1,,,,,,,T,,] [,,,,,,,,T,,] Is MAP commercially buildable at (4,2) : True Is MAP2 commercially buildable at (2,2) : False irrectness. The cell below is not graded, so feel free to modify the code as you wish! Dode Legibility (6 Marks) our code will be marked on commenting and code legibility. he mark breakdown is as follows: - 2 marks for using appropriate variable names that indicate what is being stored in that variable - 2 marks for leaving comments on major parts of your code such as where you read the file or calculate a summation - 2 marks for general legibility. The TA's should be able to understand your code without spending hours reading it. For example do not put your code in one very long line as this is hard for someone else reading your code to understand lest Plan Develop a test plan for your program. Your test plan should have at least three test cases: one normal case, one boundary case, and one abnormal case. You can test any function but you must test at least two different functions. Please use the following format for your test cases: Function: Input: Output: Expected Output: Pass/Fail: An example test case is shown below: Implement your testing plan in the cell below! DOUBLE CLICK TO EDIT THIS CELL. DO NOT DELETE QUOTATION MARKS Reflective Questions (6 Marks) 1. Which functions did you use a nested structure (nested loops, nested conditionals, etc) to implement the requirements? Would it have been possible to implement them without using a nested structure? Which functions did you not use a nested structure? Would it have been possible to implement them with a nested structure? 2. Suppose we wanted to create an additional map classification called 'Urban City' which is indicated by the number of 'R' cells plus the number of 'C' cells being between 60% and 80%. Can we do this? How might this affect our classify_map() function? 3. How many test cases would you need to confirm that your classify_map() function correctly identifies a "Farmland" map? Explain what your test cases would be. DOUBLE CLICK TO EDIT THIS CELL. DO NOT DELETE QUOTATION MARKS
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started