#import packages to create a geopackage
import geopandas as gpd
import pandas as pd
import glob

# for each file that starts with daily_SPEC_
daily_files = glob.glob('daily_SPEC_*.csv')
#sort the files
daily_files.sort()
#loop through each file
#create a geodataframe to store all the data
gdf = gpd.GeoDataFrame()

for file in daily_files:
    print('Reading', file)
    #read the file into a pandas dataframe
    df = pd.read_csv(file)
    #the latitude and longitude are stored in the 'Latitude' and 'Longitude' columns
    #create a geometry column
    df['geometry'] = gpd.points_from_xy(df.Longitude, df.Latitude)
    #create a geodataframe
    gdf1 = gpd.GeoDataFrame(df, geometry='geometry')
    #append the geodataframe to the main geodataframe using concat
    gdf = pd.concat([gdf, gdf1])


#save the geodataframe to a geopackage
gdf.to_file('daily_SPEC.gpkg', driver='GPKG')
print('Saved to daily_SPEC.gpkg')
