Index: src/python/bin/gnuboat-log-analyser
===================================================================
--- src/python/bin/gnuboat-log-analyser	(revision ca02e8fc869eee73e0b302a16c19f8b668aba12b)
+++ src/python/bin/gnuboat-log-analyser	(revision cb89b0eba182879207d0dbcae83a824191ee67c8)
@@ -21,4 +21,5 @@
 import argparse
 import sys
+import math
 import json
 import csv
@@ -27,4 +28,5 @@
 import xml.etree.ElementTree as ET
 from osgeo import ogr
+from osgeo import gdal
 
 from gnuboat.datahandler import loghandler, logdataset
@@ -49,7 +51,18 @@
 		self._output_file.writerow({"X": dataset.latitude(), "Y": dataset.longitude(), "Z": water_depth})
 
+def tile_width(zoomlevel):
+	tile_size = 256
+	tiles = math.sqrt(tile_number(zoomlevel))
+	return {"longitude": 360.0/tiles, "latitude": 180.0/tiles}
+
+def tile_number(zoomlevel):
+	return 2**(zoomlevel*2)
+
 def main(argv):
 	input_file_path = None
 	output_directory = None
+	statistics = False
+	target_nodata_value = 0
+	target_zoomlevel = 18
 
 	parser = argparse.ArgumentParser(description='Generates the digital terrain model from gnuboat logfiles')
@@ -58,4 +71,6 @@
 	parser.add_argument('output_directory', metavar='output_directory', type=str,
 						help='Write the Digital Terrain Model into this directory (output)')
+	parser.add_argument('-s', '--statistics', dest='statistics', action='store_true',
+                        help='Print some statistics of the input and result datasets')
 	arguments = parser.parse_args(argv)
 
@@ -77,9 +92,13 @@
 	else:
 		output_directory = arguments.output_directory
+	
+	if arguments.statistics is not None:
+		statistics = arguments.statistics
 
 	with open(input_file_path, 'r') as input_file:
 		logfiles = json.load(input_file)
 	
-	corrected_joined_point_cloud_file_path = "{}/{}".format(output_directory, "corrected_joined_points.csv")
+	source_data_layer = "corrected_joined_points"
+	corrected_joined_point_cloud_file_path = "{}/{}.csv".format(output_directory, source_data_layer)
 	try:
 		output_file = open(corrected_joined_point_cloud_file_path, 'w')
@@ -89,5 +108,5 @@
 	output_file_csv = None
 	fields = ['X', 'Y', 'Z']
-	output_file_csv = csv.DictWriter(output_file, delimiter=' ', quotechar='"',
+	output_file_csv = csv.DictWriter(output_file, delimiter=',', quotechar='"',
 										fieldnames=fields)
 	output_file_csv.writeheader()
@@ -118,17 +137,14 @@
 
 	# create ogr file info
-	ogr_data_layer = "points"
-	ogr_xml_file = "{}/{}".format(output_directory, "ogr_input_file.xml")
+	source_xml_file = "{}/{}".format(output_directory, "ogr_input_file.vrt")
 	try:
-		output_file = open(ogr_xml_file, 'w')
+		output_file = open(source_xml_file, 'w')
 	except IOError as error:
 		print('ERROR: Could not open the output file for the ogr data source description: {}'.format(error))
 		sys.exit(4)
 	xml_data_source = ET.Element("OGRVRTDataSource")
-	xml_layer = ET.SubElement(xml_data_source, "OGRVRTLayer", {"name": ogr_data_layer})
+	xml_layer = ET.SubElement(xml_data_source, "OGRVRTLayer", {"name": source_data_layer})
 	xml_source = ET.SubElement(xml_layer, "SrcDataSource")
 	xml_source.text = corrected_joined_point_cloud_file_path
-	xml_source_layer = ET.SubElement(xml_layer, "SrcLayer")
-	xml_source_layer.text = ogr_data_layer
 	xml_geometry_type = ET.SubElement(xml_layer, "GeometryType")
 	xml_geometry_type.text = "wkbPoint"
@@ -142,6 +158,28 @@
 	# processing data with gdal
 	ogr.UseExceptions()
-	ogr_data_source = ogr.Open(ogr_xml_file)
-	ogr_layer = ogr_data_source.GetLayer(ogr_data_layer)
+	source_data = ogr.Open(source_xml_file)
+	source_layer = source_data.GetLayer(source_data_layer)
+	source_x_min, source_x_max, source_y_min, source_y_max = source_layer.GetExtent()
+	if statistics:
+		print("Source statistics:")
+		#print("  projection: {}".format(source_layer.GetProjection())
+		#print("  reference system: {}".format(source_data.GetAttrValue("geocs")))
+		print("  extents (x_min, y_min, x_max, y_max): {}, {}, {}, {}".format(source_x_min, source_y_min, source_x_max, source_y_max))
+		
+	# Create the destination data source
+	tile_resolution = tile_width(target_zoomlevel)
+	target_x_res = int(256 / tile_resolution["longitude"] * (source_x_max - source_x_min))
+	target_y_res = int(256 / tile_resolution["latitude"] * (source_y_max - source_y_min))
+	print("target x res {}".format(target_x_res))
+	print("target y res {}".format(target_y_res))
+	#target_data = gdal.GetDriverByName('MEM').Create('', target_x_res, target_y_res, gdal.GDT_Byte)
+	#target_data.SetGeoTransform((source_x_min, pixel_size, 0, source_y_max, 0, -pixel_size))
+	#band = target_ds.GetRasterBand(1)
+	#band.SetNoDataValue(NoData_value)
+	
+	# create the grid data
+	grid_options = gdal.GridOptions(format = "GTiff", width = target_x_res, height = target_y_res, outputSRS = "WGS84", noData = target_nodata_value, layers = source_data_layer)
+	#gdal.Grid("/tmp/test.tif", source_xml_file)
+	gdal.Grid("/tmp/test.tif", source_xml_file, options = grid_options)
 
 	# creating pipeline
