Pan
Pan

Reputation: 1

geomfromtext insert in spatialite from retrived text

Attempting to build a data entry form, I would like to create geometry points from the longitude.get() and latitude.get() values. However, the pasted code below doesn't work, probably due to some syntax error from my side (I suspect that python reads som parts of the geofromtext as a string) but I don't know how to proceed otherwise.

Does anyone see my error?

I have tried to change the code as per the specification of the spatialite documentation but without success so far. I suspect some syntax error frpm my side.

Is there any obvious mistake?

Here is the relevant code:

 date = datetime.date(int(year.get()),int(month.get()), int(day.get()))
 narratif=T.get("1.0","end-1c")


 c.execute("""INSERT INTO Incidents
   (Geometry, Datestamp, Description, Place, Latitude, Longitude, Precision, Intimidation, Destruction, Burglary,
   Carjacking, Theft, Assault, Sexualassault, Abduction, Homicide, Shooting, Explosive,  Narrative)
   VALUES(GeomFromText('POINT(? ?)', 4326),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", (longitude.get(), latitude.get(), date, description.get(),place.get(),latitude.get(), longitude.get(), precision.get(), intimidation1.get(),destruction2.get(), burglary3.get(), carjacking4.get(), theft5.get(), assault6.get(), sexualassault7.get(), abduction8.get(), homicide9.get(), shooting10.get(), explosive11.get(), narratif))


 con.commit()

Upvotes: 0

Views: 446

Answers (1)

Pan
Pan

Reputation: 1

For ionformation, I was able to make it work with the following code:

def get():
    try:

        date = datetime.date(int(year.get()),int(month.get()), int(day.get()))
        narratif=T.get("1.0","end-1c")
        c.execute("""INSERT INTO Incidents
   (Datestamp, Description, Place, Latitude, Longitude, Precision, Interpretation, Wounded, Killed, Intimidation, Destruction, Burglary,
   Carjacking, Theft, Assault, Sexualassault, Abduction, Homicide, Shooting, Explosive, Indirectfire, Intercommunity, Narrative)
   VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", (date, description.get(),place.get(),latitude.get(), longitude.get(), precision.get(), interpretation.get(), wounded.get(), killed.get(), intimidation1.get(),destruction2.get(), burglary3.get(), carjacking4.get(), theft5.get(), assault6.get(), sexualassault7.get(), abduction8.get(), homicide9.get(), shooting10.get(), explosive11.get(), indirectfire12.get(), intercommunity13.get(), narratif ))
        c.execute('UPDATE Incidents SET Geometry=MakePoint(Longitude, Latitude, 4326) WHERE Incident_ID = (SELECT MAX(Incident_ID) FROM Incidents);')
        print("You just added an incident!")
        print(c.lastrowid)
        messagebox.showinfo("Incident added", "incident successfully added!")
    except:
        messagebox.showerror("No incident added", "Check for duplicates, empty fields or other sources of error") 
    con.commit()

Upvotes: 0

Related Questions