import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
import sys

def csv_to_shp(in_file: str, out_file: str, x_col: str = 'Lambert_X', y_col: str = 'Lambert_Y'):
    # 1. Load the interpolated CSV
    df = pd.read_csv(in_file, encoding='UTF-8', on_bad_lines='skip', delimiter=';')  # or 'cp1252' if needed

    # 3. Create geometry from X and Y
    geometry = [Point(xy) for xy in zip(df[x_col], df[y_col])]

    # 4. Create GeoDataFrame
    gdf = gpd.GeoDataFrame(df, geometry=geometry)

    # 5. Set CRS (Lambert 93 = EPSG:2154, common in France)
    gdf.set_crs(epsg=2154, inplace=True)

    # 6. Export to shapefile
    gdf.to_file(out_file)
    
csv_to_shp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])

