本文整理汇总了Python中Table.Table.addRecordList方法的典型用法代码示例。如果您正苦于以下问题:Python Table.addRecordList方法的具体用法?Python Table.addRecordList怎么用?Python Table.addRecordList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table.Table
的用法示例。
在下文中一共展示了Table.addRecordList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExportDataset
# 需要导入模块: from Table import Table [as 别名]
# 或者: from Table.Table import addRecordList [as 别名]
def ExportDataset(pathToDB, DBname,currentPath):
# connect to database
con = sqlite.connect(pathToDB+os.path.sep+DBname)
cur = con.cursor()
#create a table with notes
# "_id","lon","lat","altim","ts","description","text","form","style","isdirty"
notes = cur.execute("SELECT * FROM notes")
notesTable = Table(["_id","lon","lat","altim","ts","description","text","form","style","isdirty"])
notesTableFields = [QgsField("_id", QVariant.Int), QgsField("lon", QVariant.Double), QgsField("lat", QVariant.Double),QgsField("altim", QVariant.Double), \
QgsField("ts", QVariant.String),QgsField("description", QVariant.String), \
QgsField("form", QVariant.String),QgsField("style", QVariant.String), \
QgsField("isdirty", QVariant.Int)]
for note in notes:
note = convertToStringList(note)
notesTable.addRecordList(note)
vl = exportPointToTempVector(notesTable, layName='notes', fields = notesTableFields)
vl.loadNamedStyle(currentPath+'/styles/note_symb.qml')
# add to the TOC
QgsMapLayerRegistry.instance().addMapLayer(vl)
#create a table with image positions
images = cur.execute("SELECT * FROM images")
imagesTable = Table(["_id","lon","lat","altim","azim","imagedata_id","ts","text","note_id","isdirty"])
imagesTableFields = [QgsField("_id", QVariant.Int), QgsField("lon", QVariant.Double), QgsField("lat", QVariant.Double),QgsField("altim", QVariant.Double),QgsField("azim", QVariant.Double), \
QgsField("imagedata_id", QVariant.Int),QgsField("ts", QVariant.String),QgsField("text", QVariant.String), \
QgsField("note_id", QVariant.Int), QgsField("isdirty", QVariant.Int)]
for img in images:
img = convertToStringList(img)
imagesTable.addRecordList(img)
vl = exportPointToTempVector(imagesTable, layName='image positions', fields = imagesTableFields)
vl.loadNamedStyle(currentPath+'/styles/image_symb.qml')
# add Show Image Action
SIact = '# -*- coding: utf-8 -*-' + '\n'
SIact += ur'from PyQt4.QtCore import QUrl; from PyQt4.QtWebKit import QWebView; myWV = QWebView(None); '
SIact += 'myWV.setWindowTitle('+'"'+'[% "text" %]'+'"'+'); '
SIact += 'myWV.load(QUrl('
SIact += "ur'"+pathToDB+os.path.sep+'images'+os.path.sep+'[% "text" %]'+"'"+")); myWV.show()"
# SIact = pathToDB+'\images\[% "text" %]'
# actions.addAction(QgsAction.OpenUrl, "Show Image",SIact)
actions = vl.actions()
actions.addAction(QgsAction.GenericPython, "Show Image",SIact)
# add to the TOC
QgsMapLayerRegistry.instance().addMapLayer(vl)
#create a table with bookmarks
bookmarks = cur.execute("SELECT * FROM bookmarks")
bookmarksTable = Table(["_id","lon","lat","zoom","bnorth","bsouth","bwest","beast","text"])
bookmarksTableFields = [QgsField("_id", QVariant.Int), QgsField("lon", QVariant.Double), QgsField("lat", QVariant.Double), \
QgsField("zoom", QVariant.Double),QgsField("bnorth", QVariant.Double), \
QgsField("bsouth", QVariant.Double),QgsField("bwest", QVariant.Double), \
QgsField("beast", QVariant.Double),QgsField("text", QVariant.String)]
for bkm in bookmarks:
bkm = convertToStringList(bkm)
bookmarksTable.addRecordList(bkm)
vl = exportPointToTempVector(bookmarksTable, layName='bookmarks', fields = bookmarksTableFields)
vl.loadNamedStyle(currentPath+'/styles/bookmark_symb.qml')
# add to the TOC
QgsMapLayerRegistry.instance().addMapLayer(vl)
#create a new folder with images inside
if not os.path.isdir(pathToDB+os.path.sep+'images'):
os.makedirs(pathToDB+os.path.sep+'images')
# get the list of images
imgIDs = imagesTable.getColumn("_id")
imgNames = imagesTable.getColumn("text")
# loop in the list and get BLOB
i = 0
for imgID in imgIDs:
imgsData = cur.execute("SELECT * FROM imagedata WHERE _id = " + str(imgID))
imgName = imgNames[i]
#print imgID, imgName
for imgData in imgsData:
with open(pathToDB+os.path.sep+'images'+ os.path.sep + imgName, "wb") as output_file:
output_file.write(imgData[1])
i +=1
#create a table with logs
gpslogs = cur.execute("SELECT * FROM gpslogs")
gpslogsTable = Table(["_id","startts","endts","lengthm","isdirty","text"])
gpslogsTableFields = [QgsField("_id", QVariant.Int), QgsField("startts", QVariant.Double), QgsField("endts", QVariant.Double), \
QgsField("lengthm", QVariant.Double),QgsField("isdirty", QVariant.Int),QgsField("text", QVariant.String)]
# load the list of gpslogs
for l in gpslogs:
l = convertToStringList(l)
gpslogsTable.addRecordList(l)
# create layer
vl = QgsVectorLayer("LineString?crs=EPSG:4326", 'tracklogs', "memory")
pr = vl.dataProvider()
#.........这里部分代码省略.........