Changeset fbc3d47


Ignore:
Timestamp:
Sep 23, 2018, 9:54:41 AM (8 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
2eed0da
Parents:
6794274
Message:
  • Moved DEM to virtual memory file
  • Prefexid all temporary files with tmp_
  • Generating color-relief, hillshade and slope shade
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/python/bin/gnuboat-log-analyser

    r6794274 rfbc3d47  
    3232from gnuboat.datahandler import loghandler, logdataset
    3333
     34
     35colors = {
     36        0: "0 0 139",
     37        2: "30 144 255",
     38        6: "173 216 230",
     39        10: "240 248 255"
     40}
     41
    3442class CsvCallback:
    3543        def __init__(self, output_file):
    … …  
    5967
    6068def main(argv):
     69        global color
     70
    6171        input_file_path = None
    6272        output_directory = None
    … …  
    98108                logfiles = json.load(input_file)
    99109       
    100         source_data_layer = "corrected_joined_points"
    101         corrected_joined_point_cloud_file_path = "{}/{}.csv".format(output_directory, source_data_layer)
     110        source_data_layer = "tmp_corrected_joined_points"
     111        corrected_joined_point_cloud_file_path = os.path.join(output_directory, "{}.csv".format(source_data_layer))
    102112        try:
    103113                output_file = open(corrected_joined_point_cloud_file_path, 'w')
    … …  
    135145        output_file.close()
    136146
     147
     148        print("Creating output files")
    137149        # create ogr file info
    138         source_xml_file = os.path.join(output_directory, "ogr_input_file.vrt")
     150        source_xml_file = os.path.join(output_directory, "tmp_ogr_input_file.vrt")
    139151        try:
    140152                output_file = open(source_xml_file, 'wb')
    … …  
    166178                print("  extents (x_min, y_min, x_max, y_max): {}, {}, {}, {}".format(source_x_min, source_y_min, source_x_max, source_y_max))
    167179               
    168         # Create the destination data source
     180        # create the grid data
     181        gdal_file = "/vsimem/water_depth.tif"
    169182        tile_resolution = tile_width(target_zoomlevel)
    170183        target_x_res = int(tile_resolution["tile_size"] / tile_resolution["longitude"] * (source_x_max - source_x_min))
    171184        target_y_res = int(tile_resolution["tile_size"] / tile_resolution["latitude"] * (source_y_max - source_y_min))
    172         #print("target resolution x,y: {},{}".format(target_x_res, target_y_res))
    173         #print("pixel size x,y: {},{}".format((source_x_max - source_x_min)/target_x_res, (source_y_max - source_y_min)/target_y_res))
    174         #target_data = gdal.GetDriverByName('MEM').Create('', target_x_res, target_y_res, gdal.GDT_Byte)
    175         #target_data.SetGeoTransform((source_x_min, pixel_size, 0, source_y_max, 0, -pixel_size))
    176         #band = target_ds.GetRasterBand(1)
    177         #band.SetNoDataValue(NoData_value)
    178        
    179         # create the grid data
    180         gdal_file = os.path.join(output_directory, "water_depth.tif")
    181185        grid_options = gdal.GridOptions(outputType = gdal.GDT_Float32, format = "GTiff", width = target_x_res, height = target_y_res, outputSRS = "WGS84", noData = target_nodata_value, layers = source_data_layer)
    182186        gdal.Grid(gdal_file, source_xml_file, options = grid_options)
     187        print("  Created raster DEM in {}".format(gdal_file))
    183188       
    184189        # hillshade
    185190        gdal_file_hillshade  = os.path.join(output_directory, "water_depth_hillshade.tif")
    186         gdal.DEMProcessing(gdal_file_hillshade, gdal_file, "hillshade", options = gdal.DEMProcessingOptions(format = "GTiff"))
    187        
    188         # translate the data
    189         #gdal_file_translated = '/vsimem/translated.vrt'
    190         #gdal_file_translated = os.path.join(output_directory, "water_depth_translated.tif")
    191         #gdal.Translate(gdal_file_translated, gdal_file,
    192                 #options = gdal.TranslateOptions(width = target_x_res, height = target_y_res, outputSRS = 'EPSG:3857', noData = target_nodata_value)
    193         #)
    194 
    195         # creating pipeline
    196         #output_file_path = "{}/{}".format(output_directory, "water_depth.tif")
    197         #print("Creating Digital Terrain Model in {}".format(output_file_path))
    198         #pipeline = {"pipeline":[
    199                                 #{
    200                                         #"type": "readers.text",
    201                                         #"filename": corrected_joined_point_cloud_file_path
    202                                 #},
    203                                 #{
    204                                         #"type": "filters.pmf"
    205                                 #},
    206                                 #{
    207                                         #"type": "filters.range",
    208                                         #"limits": "Classification[2:2]"
    209                                 #},
    210                                 #{
    211                                         #"type": "writers.text",
    212                                         #"order":"X,Y,Z",
    213                                         #"keep_unspecified":"false",
    214                                         #"filename":"outputfile.txt"
    215                                 #}
    216                                 ##{
    217                                         ##"type": "writers.gdal",
    218                                         ##"filename": output_file_path,
    219                                         ##"output_type": "min",
    220                                         ##"gdaldriver": "GTiff",
    221                                         ##"resolution": 0.01
    222                                         ###"grid_dist_x": 1.0,
    223                                         ###"grid_dist_y": 1.0
    224                                 ##}
    225                         #]}
    226         #pdal_pipeline = pdal.Pipeline(json.dumps(pipeline))
    227         #pdal_pipeline.validate()
    228         #pdal_pipeline.set_loglevel(8)
    229         #count = pdal_pipeline.execute()
    230         #metadata = pdal_pipeline.get_metadata()
    231         #log = pdal_pipeline.get_(log)
    232        
    233         #print(metadata)
    234         #print(log)
    235        
    236         #ds_in = gdal.Open(gdal_file)
    237         #band_in = ds_in.GetRasterBand(band)
     191        gdal.DEMProcessing(gdal_file_hillshade, gdal_file, "hillshade", options = gdal.DEMProcessingOptions(format = "GTiff", zFactor = -1))
     192        print("  Created hillshade in {}".format(gdal_file_hillshade))
     193       
     194        # color relief
     195        gdal_file_color_relief = os.path.join(output_directory, "water_depth_color_relief.tif")
     196        gdal_file_color_relief_config = os.path.join(output_directory, "tmp_water_depth_color_relief_config.txt")
     197        with open(gdal_file_color_relief_config, 'w') as color_config:
     198                for depth in colors:
     199                        color_config.write("{} {}\n".format(depth, colors[depth]))
     200        gdal.DEMProcessing(gdal_file_color_relief, gdal_file, "color-relief", options = gdal.DEMProcessingOptions(format = "GTiff", colorFilename = gdal_file_color_relief_config))
     201        print("  Created color relief in {}".format(gdal_file_color_relief))
     202       
     203        # slope shade
     204        gdal_file_slope_shade_tmp = "/vsimem/tmp_water_depth_slope_shade.tif"
     205        gdal_file_slope_shade = os.path.join(output_directory, "water_depth_slope_shade.tif")
     206        gdal_file_slope_shade_config = os.path.join(output_directory, "tmp_water_depth_slope_shade_config.txt")
     207        with open(gdal_file_slope_shade_config, 'w') as shade_config:
     208                shade_config.write("0 255 255 255\n")
     209                shade_config.write("90 0 0 0\n")
     210        gdal.DEMProcessing(gdal_file_slope_shade_tmp, gdal_file, "slope", options = gdal.DEMProcessingOptions(format = "GTiff"))
     211        gdal.DEMProcessing(gdal_file_slope_shade, gdal_file_slope_shade_tmp, "color-relief", options = gdal.DEMProcessingOptions(format = "GTiff", colorFilename = gdal_file_slope_shade_config))
     212        print("  Created slope shade in {}".format(gdal_file_slope_shade))
    238213
    239214        sys.exit(0)
Note: See TracChangeset for help on using the changeset viewer.