shape file conversion to sqlite db with QT

144 views
Skip to first unread message

sailaja v

unread,
Sep 15, 2015, 8:40:23 AM9/15/15
to SpatiaLite Users
How to convert shape file(country in my case) to sqlite db to read the coordinates.And I need to run this across the os.Plz help me

a.fu...@lqt.it

unread,
Sep 15, 2015, 9:46:26 AM9/15/15
to spatiali...@googlegroups.com
Hi Sailaja,

your question is decisively too much vague and generic; giving a
simple answer to such a question is practically impossible.

I suggest you to start first by reading the Cookbook [1], so to
get a quick overall introduction to Spatial SQL.
Once you've completed this preliminary step you'll be probably
able to write some simple Spatial SQL query of your own, and then
you'll surely get a clearer comprehension of the real complexity
that your problem implies.

Feel absolutely free to post again about some specific technical
question; we'll be surely pleased to reply.

bye Sandro

[1] http://www.gaia-gis.it/gaia-sins/spatialite-cookbook/index.html

David Anderson

unread,
Sep 16, 2015, 7:30:25 PM9/16/15
to SpatiaLite Users
Sailaja,

There are any number of ways to get this done.  A few that I have used are:
1.  If you have a current version (10.1 or later) of ArcGIS you can create a spatialite database using Python, then use ArcCatalog to load the shapefile into the database.
2. Use GDAL/OGR, the swiss army knife of GIS format conversion
3. A python approach.  Use the spatialite extension with the SQLite module, then use one of the many open source Python libraries such as PyShp, then  write some code to read and write.
4. Use the spatialite gui which has a shapefile import function

I am sure there are many other methods on how to get a shapefile into spatialite.  It might be fun to create a list of ways to get this done.  Anyone else have a preferred method?

David

sailaja v

unread,
Sep 22, 2015, 6:21:38 AM9/22/15
to SpatiaLite Users
Thanks for your reply..Sure that I have read cookbook.
But still I am at initial phase only.

My system is 64bit windows 7 OS.I have placed all dlls in system32 and 64 folders unfortunately not able to load the spatialite dll into qt which I can read the shapefile data in my program.
My code is here:

    if (!sdb.open()) {
        qDebug() <<"Errorrrrrrrrrrrrr11111111";
    }
    QSqlQuery tSqlQuery(sdb);
    QVariant v = sdb.driver()->handle();
    if (!v.isValid() || qstrcmp(v.typeName(), "sqlite3*") != 0) {
        qDebug()<<"Cannot get a sqlite3 handle to the driver.";
    }
    sqlite3* handler = *static_cast<sqlite3**>(v.data());
    if (!handler) {
        qDebug()<<"Cannot get a sqlite3 handler.";
    }
    int ret = sqlite3_enable_load_extension(handler,1);
    if (ret != SQLITE_OK)
    {
        qDebug()<<"cannot load extension : \n";
        }
    if(sdb.isOpen())
    {
        if(!tSqlQuery.exec("SELECT load_extension('libspatialite-4.dll')"))
        {
            qDebug() << tSqlQuery.lastError();
        }
    }

displaying error: QSqlError("1", "Unable to execute statement", "no such function: load_extension").

Please suggest me any soln to fix this.

Noel Frankinet

unread,
Sep 22, 2015, 7:10:56 AM9/22/15
to spatiali...@googlegroups.com
Hello,

sqlite provided with Qt does probably not have extension loading enabled ?

Best,

--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spatialite-use...@googlegroups.com.
To post to this group, send email to spatiali...@googlegroups.com.
Visit this group at http://groups.google.com/group/spatialite-users.
For more options, visit https://groups.google.com/d/optout.



--
Noël Frankinet
Strategis sprl
0478/90.92.54

a.fu...@lqt.it

unread,
Sep 22, 2015, 7:13:27 AM9/22/15
to spatiali...@googlegroups.com
On Tue, 22 Sep 2015 03:21:38 -0700 (PDT), sailaja v wrote:
> error: QSqlError("1", "Unable to execute statement", "no such
> function: load_extension").
>
> Please suggest me any soln to fix this.
>

Hi Sailaja,

libsqlite3 comes in several different flavors depending
on your preferred binary distribution choices.

supporting or not the "load_extension" mechanism is optional:
sometimes system packagers choose to disable this feature
for security reason.
and this exactly is your case: your binary copy of libsqlite3
was clearly built by selectively disabling "load_extension",
so it's completely useless in order to support spatialite.

solution: get rid of this insane libsqlite3.
and duly build by yourself a standard and nicely updated
sqlite starting directly from the current version of
the source code.

https://www.sqlite.org/download.html
https://www.sqlite.org/2015/sqlite-autoconf-3081101.tar.gz

you could possibly find useful reading first these build notes:
http://www.gaia-gis.it/gaia-sins/mingw_how_to.html#libsqlite

bye Sandro

David Anderson

unread,
Sep 24, 2015, 7:32:55 PM9/24/15
to SpatiaLite Users
I have had luck in the past just swapping out the sqlite3.dll in the bad application with a sqlite3.dll that does have extension loading working.  Sandro quite generously provides the SQLite dll with the download package.  Another little trap to avoid is to make sure that the bits all lines up, ie 32 bit qt, with 32 bit SQLite with 32 bit spatialite.  or 64 bit,whichever you prefer.  While 2 out of 3 ain't bad it also won't work as I have found out.

Good luck with dll hell. 
Reply all
Reply to author
Forward
0 new messages