I have a csv file with some info and coordinates and I want to create a table in PostGIS with that CSV file. This is what I have so far:
import pandas as pd
import geopandas
from datetime import datetime
#import psycopg2
from geoalchemy2 import Geometry, WKTElement
from sqlalchemy import *
ruta=('csv_file')
df= pd.read_csv(ruta,sep=';')
df['Tiempo'] = df['Fecha'].map(str)+ " "+ df['Hora']
now = datetime.utcnow()
tiempos=[]
registro=[]
datetime_str = df["Tiempo"]
for i in datetime_str:
datetime_object = datetime.strptime(i,'%Y%m%d %H:%M:%S.%f')
check = now - datetime_object
check.total_seconds()
if (check.total_seconds() > 300):
registro.append(1)
else:
registro.append(0)
df['Ocurrencia']=registro
gdf=geopandas.GeoDataFrame(df, geometry=geopandas.points_from_xy(df.lng, df.lat))
this is the new geodataframe
#database connection
engine = create_engine('postgresql://postgres:postgres@localhost:5432/Rayos')
#conn = psycopg2.connect("dbname='Rayos' user='postgres' host='localhost'
#password='postgres'")
gdf.to_sql('table_name', engine, if_exists='append', index=False,
dtype={'geometry': Geometry('POINT', srid= 4326)})
this is the error:
#old error
ValueError: geometry (geometry(POINT,4326)) not a string
#new error
ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'Point'
I made some changes according to this post.What I'm doing wrong?
