function [rtree_idx,timeGeoList]=read_timeGeo(rtree_idx,timeGeoList,directory)
   file_list=dir(fullfile(directory,'*.timeGeo'));
   for idx = 1:length(file_list)
       if isempty(timeGeoList)
           timeGeoList=[process_file(file_list(idx))];
       else
           timeGeoList(end+1)=process_file(file_list(idx));
       end
       rtree_idx.insert(int64(idx),timeGeoList(end).bb([1,3,2,4]))
   end
end

function timeGeo=process_file(fn_idx)

    fn=fullfile(fn_idx.folder,fn_idx.name);
    r=strsplit(fn_idx.name,"_");
    con=fileread(fn);
    timeGeo.data=str2num(con);
    timeGeo.lat=timeGeo.data(:,3);
    timeGeo.range=str2num(r{6})/10;
    timeGeo.lon=timeGeo.data(:,4);
    timeGeo.depth=timeGeo.data(:,5);
    timeGeo.yaw=timeGeo.data(:,6);
    timeGeo=get_convex_hull(timeGeo);
    timeGeo.hash=int64(keyHash(fn_idx.name));
    if timeGeo.hash < 1 
        fprint(".")
    end
end

function timeGeo=get_convex_hull(timeGeo)
% Get convex hull of image
   X=[];  Y=[];
   X0=[]; Y0=[];
   X1=[]; Y1=[];
   M=[];
   for idx=1:length(timeGeo.data) % für jede Zeile 
        [la0,lo0,d0]=getGeo(0.0,0.0,timeGeo.range,timeGeo.lat(idx),timeGeo.lon(idx),timeGeo.depth(idx),timeGeo.yaw(idx),0.0); % Anfang geodetic
        [la1,lo1,d1]=getGeo(1.0,0.0,timeGeo.range,timeGeo.lat(idx),timeGeo.lon(idx),timeGeo.depth(idx),timeGeo.yaw(idx),0.0); % Ende geodetic

        [x,y,z]=toECEF(timeGeo.lat(idx),timeGeo.lon(idx),timeGeo.depth(idx)); % Mitte ECRF
        [x0,y0,z0]=toECEF(la0,lo0,d0); % Anfang ECEF
        [x1,y1,z1]=toECEF(la1,lo1,d1); % Ende ECEF

        X=[X,x]; % x of center
        Y=[Y,y]; % y of center
        X0=[X0,x0];  % x of 0 side
        Y0=[Y0,y0];  % y of 0 side
        X1=[X1,x1];  % x of 1 side
        Y1=[Y1,y1];  % y of 1 side
        M=[M;x1,y1;x0,y0]; % fringe

        if size(M,1)>5
               [k,av]=convhull(M);
               M=M(k,:);
        end
   end
   timeGeo.M=M;
   timeGeo.poly=polyshape(M(:,1),M(:,2));
   [xlim,ylim]=boundingbox(timeGeo.poly);
   timeGeo.bb=[xlim',ylim'];
end