[Qgis-developer] Creating a Spatialite table (both geometric and geometryless) inside a C++ plugin

Martin Dobias wonder.sk at gmail.com
Thu Oct 13 15:43:24 EDT 2011


On Thu, Oct 13, 2011 at 4:21 AM, mmekuria <sailmcm at yahoo.com> wrote:
> I need help to create tables (both geometric and geometryless)  in my  C++
> plugin. I have a very big data set and it has been difficult to use either
> flat file (for the geometryless data) or shapefile (for the geometric data)
> and I do not want to use PostGIS since I will pass the data to a colleague
> far away who is not database proficient.
>
> Here is a piece of code that I scavenged from PyQGis Cookbooks manual and
> spatialite provider. But I do not see how to go about creating tables.

Several weeks ago a new functionality has been included into QGIS that
allows creation of new tables using one interface - look for
QgsVectorLayerImport class in core library. The disadvantage is that
it is not yet available in any release. Alternatively you could still
open a spatialite database with sqlite api and manually run the sql
query to create a table you need.

In case you need to also create new spatialite database at the same
time, there's no api for that (yet). You can either create it in QGIS
app manually (including the tables), if you insist on automatic
creation then you will need to create the spatialite database using
sqlite api - some inspiration may be found in
src/app/spatialite/qgsnewspatialitelayerdialog.cpp.

Martin


More information about the Qgis-developer mailing list