def raster_to_tin(input_terrain_raster):
    # read raster records
    raster_dataset = gdal.Open(input_terrain_raster)
    band = raster_dataset.GetRasterBand(1)
    a = band.ReadAsArray(0, 0, raster_dataset.RasterXSize,
                         raster_dataset.RasterYSize)

    # if the raster file is below sea level, the entire case study is lifted to the lowest point is at altitude 0
    if (a * (a > -1e3)).min() < 0:
        a -= (a * (a > -1e3)).min()

    (y_index, x_index) = np.nonzero(a >= 0)
    (upper_left_x, x_size, x_rotation, upper_left_y, y_rotation,
     y_size) = raster_dataset.GetGeoTransform()
    x_coords = x_index * x_size + upper_left_x + (x_size / 2
                                                  )  # add half the cell size
    y_coords = y_index * y_size + upper_left_y + (y_size / 2
                                                  )  # to centre the point

    elevation_mean = int(a[y_index, x_index].mean())

    raster_points = [(x, y, z)
                     for x, y, z in zip(x_coords, y_coords, a[y_index,
                                                              x_index])]

    tin_occface_list = construct.delaunay3d(raster_points)

    return elevation_mean, tin_occface_list
Exemple #2
0
    def generate_tin(self):
        (y_index, x_index) = np.nonzero(self.elevation_map >= 0)
        _x_coords = self.x_coords[x_index]
        _y_coords = self.y_coords[y_index]

        raster_points = [(x, y, z) for x, y, z in zip(
            _x_coords, _y_coords, self.elevation_map[y_index, x_index])]

        tin_occface_list = construct.delaunay3d(raster_points)

        return tin_occface_list
Exemple #3
0
def terrain_2d_to_3d(citygml_writer, input_terrain_raster):

    # read x, y, z coordinates of raster
    raster_points = raster_reader(input_terrain_raster)

    #create tin and triangulate
    tin_occface_list = construct.delaunay3d(raster_points)

    geometry_list = gml3dmodel.write_gml_triangle(tin_occface_list)
    citygml_writer.add_tin_relief("lod1", "terrain1", geometry_list)
    return tin_occface_list
def raster2tin(input_terrain_raster):

    # read raster records
    raster_dataset = gdal.Open(input_terrain_raster)
    band = raster_dataset.GetRasterBand(1)
    a = band.ReadAsArray(0, 0, raster_dataset.RasterXSize, raster_dataset.RasterYSize)
    (y_index, x_index) = np.nonzero(a >= 0)
    (upper_left_x, x_size, x_rotation, upper_left_y, y_rotation, y_size) = raster_dataset.GetGeoTransform()
    x_coords = x_index * x_size + upper_left_x + (x_size / 2)  # add half the cell size
    y_coords = y_index * y_size + upper_left_y + (y_size / 2)  # to centre the point

    elevation_mean = int(a[y_index, x_index].mean())

    raster_points = [(x, y, z) for x, y, z in zip(x_coords, y_coords, a[y_index, x_index])]

    tin_occface_list = construct.delaunay3d(raster_points)

    return elevation_mean, tin_occface_list