- Timestamp:
- Jul 15, 2018, 5:52:06 PM (8 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 7b6d348
- Parents:
- ca02e8f
- File:
-
- 1 edited
-
src/python/bin/gnuboat-log-analyser (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/python/bin/gnuboat-log-analyser
rca02e8f rcb89b0e 21 21 import argparse 22 22 import sys 23 import math 23 24 import json 24 25 import csv … … 27 28 import xml.etree.ElementTree as ET 28 29 from osgeo import ogr 30 from osgeo import gdal 29 31 30 32 from gnuboat.datahandler import loghandler, logdataset … … 49 51 self._output_file.writerow({"X": dataset.latitude(), "Y": dataset.longitude(), "Z": water_depth}) 50 52 53 def tile_width(zoomlevel): 54 tile_size = 256 55 tiles = math.sqrt(tile_number(zoomlevel)) 56 return {"longitude": 360.0/tiles, "latitude": 180.0/tiles} 57 58 def tile_number(zoomlevel): 59 return 2**(zoomlevel*2) 60 51 61 def main(argv): 52 62 input_file_path = None 53 63 output_directory = None 64 statistics = False 65 target_nodata_value = 0 66 target_zoomlevel = 18 54 67 55 68 parser = argparse.ArgumentParser(description='Generates the digital terrain model from gnuboat logfiles') … … 58 71 parser.add_argument('output_directory', metavar='output_directory', type=str, 59 72 help='Write the Digital Terrain Model into this directory (output)') 73 parser.add_argument('-s', '--statistics', dest='statistics', action='store_true', 74 help='Print some statistics of the input and result datasets') 60 75 arguments = parser.parse_args(argv) 61 76 … … 77 92 else: 78 93 output_directory = arguments.output_directory 94 95 if arguments.statistics is not None: 96 statistics = arguments.statistics 79 97 80 98 with open(input_file_path, 'r') as input_file: 81 99 logfiles = json.load(input_file) 82 100 83 corrected_joined_point_cloud_file_path = "{}/{}".format(output_directory, "corrected_joined_points.csv") 101 source_data_layer = "corrected_joined_points" 102 corrected_joined_point_cloud_file_path = "{}/{}.csv".format(output_directory, source_data_layer) 84 103 try: 85 104 output_file = open(corrected_joined_point_cloud_file_path, 'w') … … 89 108 output_file_csv = None 90 109 fields = ['X', 'Y', 'Z'] 91 output_file_csv = csv.DictWriter(output_file, delimiter=' ', quotechar='"',110 output_file_csv = csv.DictWriter(output_file, delimiter=',', quotechar='"', 92 111 fieldnames=fields) 93 112 output_file_csv.writeheader() … … 118 137 119 138 # create ogr file info 120 ogr_data_layer = "points" 121 ogr_xml_file = "{}/{}".format(output_directory, "ogr_input_file.xml") 139 source_xml_file = "{}/{}".format(output_directory, "ogr_input_file.vrt") 122 140 try: 123 output_file = open( ogr_xml_file, 'w')141 output_file = open(source_xml_file, 'w') 124 142 except IOError as error: 125 143 print('ERROR: Could not open the output file for the ogr data source description: {}'.format(error)) 126 144 sys.exit(4) 127 145 xml_data_source = ET.Element("OGRVRTDataSource") 128 xml_layer = ET.SubElement(xml_data_source, "OGRVRTLayer", {"name": ogr_data_layer})146 xml_layer = ET.SubElement(xml_data_source, "OGRVRTLayer", {"name": source_data_layer}) 129 147 xml_source = ET.SubElement(xml_layer, "SrcDataSource") 130 148 xml_source.text = corrected_joined_point_cloud_file_path 131 xml_source_layer = ET.SubElement(xml_layer, "SrcLayer")132 xml_source_layer.text = ogr_data_layer133 149 xml_geometry_type = ET.SubElement(xml_layer, "GeometryType") 134 150 xml_geometry_type.text = "wkbPoint" … … 142 158 # processing data with gdal 143 159 ogr.UseExceptions() 144 ogr_data_source = ogr.Open(ogr_xml_file) 145 ogr_layer = ogr_data_source.GetLayer(ogr_data_layer) 160 source_data = ogr.Open(source_xml_file) 161 source_layer = source_data.GetLayer(source_data_layer) 162 source_x_min, source_x_max, source_y_min, source_y_max = source_layer.GetExtent() 163 if statistics: 164 print("Source statistics:") 165 #print(" projection: {}".format(source_layer.GetProjection()) 166 #print(" reference system: {}".format(source_data.GetAttrValue("geocs"))) 167 print(" extents (x_min, y_min, x_max, y_max): {}, {}, {}, {}".format(source_x_min, source_y_min, source_x_max, source_y_max)) 168 169 # Create the destination data source 170 tile_resolution = tile_width(target_zoomlevel) 171 target_x_res = int(256 / tile_resolution["longitude"] * (source_x_max - source_x_min)) 172 target_y_res = int(256 / tile_resolution["latitude"] * (source_y_max - source_y_min)) 173 print("target x res {}".format(target_x_res)) 174 print("target y res {}".format(target_y_res)) 175 #target_data = gdal.GetDriverByName('MEM').Create('', target_x_res, target_y_res, gdal.GDT_Byte) 176 #target_data.SetGeoTransform((source_x_min, pixel_size, 0, source_y_max, 0, -pixel_size)) 177 #band = target_ds.GetRasterBand(1) 178 #band.SetNoDataValue(NoData_value) 179 180 # create the grid data 181 grid_options = gdal.GridOptions(format = "GTiff", width = target_x_res, height = target_y_res, outputSRS = "WGS84", noData = target_nodata_value, layers = source_data_layer) 182 #gdal.Grid("/tmp/test.tif", source_xml_file) 183 gdal.Grid("/tmp/test.tif", source_xml_file, options = grid_options) 146 184 147 185 # creating pipeline
Note:
See TracChangeset
for help on using the changeset viewer.
