I am converting excel to geojson file.I want to make the script generic ,so that excel file can be converted to geojson file.
My code as below:
import pandas as pd
import json
import sys
file1 = sys.argv[1]
col_1 = sys.argv[2]
col_2 = sys.argv[3]
import geopandas
excel_data_df = pd.read_excel(file1, sheet_name='ENR 5.4',header=None)
excel_data_df.columns = excel_data_df.loc[0:2].fillna('').apply(' '.join).str.strip()
excel_data_df.reset_index(drop=True, inplace=True)
df2= excel_data_df
df2 = df2.reset_index()
temp_data1= df2.loc[:,["col_1"]]
duplicate_cols = df2.columns[df2.columns.duplicated()]
df2.drop(columns=duplicate_cols, inplace=True)
df2['Date_and_time_stamp Mandatory'] = df2['Date_and_time_stamp Mandatory'].astype(str)
gdf = geopandas.GeoDataFrame(
df2, geometry=geopandas.points_from_xy(df2.col_1, df2.col_2))
with open('file13.geojson' , 'w') as file:
file.write(gdf.to_json())
I want to pass latitude and longitude column value to convert point for every excel file.Latitude and longitude column names are different in every excel.
So how to pass the latitude and longitude column to the script