[Model.py 02]Modification for creating terrain matrix2.

Initialization

		self.ditch = []  # 定义一个沟渠的列表 可以初始化
        self.ditch_inside = [] #用于定义一个矩阵,让积水点不能在这个范围内初始化
        # 920
        '''
            at present, using different no to represent objects.
                river 1
                road 2
                wall 3
                indoor 4
                exits 5
                pillar 6
                ditch 7
        '''
        self.river_matrix = np.zeros((self.grid.width, self.grid.height))  # initializing river matrix
        self.road_matrix = np.zeros((self.grid.width, self.grid.height))  # initializing road matrix
        self.wall_matrix = np.zeros((self.grid.width, self.grid.height))  # initializing wall matrix
        self.indoor_matrix = np.zeros((self.grid.width, self.grid.height))  # initializing indoor matrix
        self.exits_matrix = np.zeros((self.grid.width, self.grid.height))  # initializing exits matrix
        self.pillar_matrix = np.zeros((self.grid.width, self.grid.height))  # initializing pillar matrix
        self.ditch_matrix = np.zeros((self.grid.width, self.grid.height))  # initializing ditch matrix
        self.terrain_matrix = np.zeros((self.grid.width, self.grid.height))  # initializing terrain matrix
        # 获取坐标文件
        road_positions_filename = f'./data/road.xlsx'
        wall_positions_filename = f'./data/east_station.xlsx'
        river_positions_filename = f'./data/river3.xlsx'

        # 获取偏移转化参数
        x_shifting, y_shifting, x_scale, y_scale = json_tools.read_shifting_scale()
        self.stream_pos = []  # 河流坐标
        self.stream_pos2=[] # added river coordinates

Modification in initial_position

        elif pos_type == "river":
            df = pd.read_excel(file_name)
            num = df['x1'].notna().sum()
            print(pos_type, "数量:", num)
            # 坐标变化
            for i in range(num):
                start_x, start_y = df['x1'][i], df['y1'][i]
                start_x += x_shifting
                start_x /= x_scale
                start_x = round(start_x)
                # align with roads
                start_x = start_x -38
                start_y += y_shifting
                start_y /= y_scale
                start_y = round(start_y)
                # align with roads
                start_y = start_y + 28
                self.stream_pos.append((start_x, start_y))
                if i>0:
                    '''
                        Applyiing 1 to self.river_matrix along the route 
                        from the start point(start0_x,start0_y) to end point (start_x,start_y) 
                    '''
                    self.apply_matrix_dots(start0_x, start0_y, start_x, start_y, 'river')
                start0_x,start0_y=start_x,start_y
            num2 = df['x2'].notna().sum()
            print(pos_type, "add 数量:", num2)
            # 坐标变化
            for i in range(num2):
                start_x, start_y = df['x2'][i], df['y2'][i]
                start_x += x_shifting
                start_x /= x_scale
                start_x = round(start_x)
                # align with roads
                start_x = start_x -38
                start_y += y_shifting
                start_y /= y_scale
                start_y = round(start_y)
                # align with roads
                start_y = start_y +28
                self.stream_pos2.append((start_x, start_y))
                if i>0:
                    '''
                        Applying 1 to self.river_matrix along the route 
                        from the start point(start0_x,start0_y) to end point (start_x,start_y) 
                    '''
                    self.apply_matrix_dots(start0_x,start0_y,start_x,start_y,'river')
                start0_x,start0_y=start_x,start_y

你可能感兴趣的:(python)