geomfromtext从检索到的文本中插入spacespaceite

时间:2019-03-09 08:00:58

标签: python sqlite insert spatialite

尝试构建数据输入表单,我想从longitude.get()和latitude.get()值创建几何点。但是,下面粘贴的代码无法正常工作,可能是由于我这边的语法错误(我怀疑python会以字符串形式读取geofromtext的som部分),但我不知道如何进行其他操作。

有人看到我的错误吗?

我已经尝试根据spacespaceite文档的规范更改代码,但到目前为止没有成功。我怀疑我这边有语法错误frpm。

有明显的错误吗?

以下是相关代码:

 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()

1 个答案:

答案 0 :(得分:0)

对于离子形成,我能够使用以下代码进行工作:

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()