floodtools_create_wlevel1:
  CREATE TABLE IF NOT EXISTS wlevel (
    pk INTEGER PRIMARY KEY,
    h REAL,
    tanf TEXT,
    tend TEXT)

floodtools_create_wlevel2:
  SELECT AddGeometryColumn('wlevel','geom', {self.epsg},'POLYGON',2)

floodtools_create_wlevel3:
  SELECT CreateSpatialIndex('wlevel','geom')  

floodtools_create_velo1:
  PRAGMA table_list('velo')

floodtools_create_velo2:
  CREATE TABLE IF NOT EXISTS velo (
    pk INTEGER PRIMARY KEY,
    v REAL,
    tanf TEXT,
    tend TEXT)

floodtools_create_velo3:
  SELECT AddGeometryColumn('velo','geom', {self.epsg},'LINESTRING',2)

floodtools_create_velo4:
  SELECT CreateSpatialIndex('velo','geom')

floodtools_delete_wlevel:
  DELETE FROM wlevel  

floodtools_delete_velo:
  DELETE FROM velo

floodtools_velo_choice:
  PRAGMA table_info('result2d__velocity')  

floodtools_wlevel_choice:  
  PRAGMA table_info('result2d__topo_decimated')

floodtools_insert_wlevel:
  INSERT INTO wlevel (h, tanf, tend, geom)
  SELECT
    wl_{tstep} AS h,
    datetime(julianday('{starttime}') + {tstep} * {interval}) AS tanf,
    datetime(julianday('{starttime}') + {tstep + 1} * {interval}) AS tend,
    CastToXY(CastToPolygon(GEOMETRY)) AS geom
  FROM result2d__topo_decimated
  WHERE wl_{tstep} >= {self.min_w}

floodtools_insert_velo:
  INSERT INTO velo (v, tanf, tend, geom)
  SELECT
    v_{tstep} AS v,
    datetime(julianday('{starttime}') + {tstep} * {interval}) AS tanf,
    datetime(julianday('{starttime}') + {tstep + 1} * {interval}) AS tend,
    Makeline(
      Makepoint(x(GEOMETRY), 
                y(GEOMETRY), {self.epsg}), 
      MakePoint(x(GEOMETRY)+v_{tstep}*cos(v_dir_{tstep}/57.2958)*{self.faktor_v}, 
                y(GEOMETRY)+v_{tstep}*sin(v_dir_{tstep}/57.2958)*{self.faktor_v},
                {self.epsg})
    ) as geom
  FROM result2d__velocity
  WHERE v_{tstep} >= {self.min_v}