5

I'm trying to create a spatialite file with the code snippet below. However the outDataSource object gets assigned NoneType and all subsequent (unshown) code fails.

I'm thinking the problem is with the spatialite installation for two reasons:

  1. When I choose 'ESRI Shapefile' as the driver and leave out the options=['SPATIALITE=yes'] the outDataSource is created correctly and all subsequent codes works as anticipated.
  2. When I leave the driver as 'SQLite' but take out the options=['SPATIALITE=yes'], the non-spatial sqlite tables are indeed created. So, any ideas on what I am missing or might have done incorrectly to establish the link between OGR and spatialite?

I'm developing on Spyder 2.3.0rc, with Python 2.7.7 32bits, Qt 4.8.6, PyQt4 (API v2) 4.10.4 on Windows, as delivered by the Anaconda-2.0.1-Windows-x86 executable. Additionally, the development comments at the end of the code describe the steps I took to install spatialite.

# standard modules
import os

# third party modules
from osgeo import ogr


##############################################################################
# create a new spatialite output file
##############################################################################

outputGridfn = os.path.join(os.getcwd(), 'grid.sqlite')
outDriver = ogr.GetDriverByName('SQLite')
outDataSource = outDriver.CreateDataSource(outputGridfn,
                                           options=['SPATIALITE=yes'])


##############################################################################
# Development notes
##############################################################################

# SPATIALITE functionality requires the following work
# Step 0: Download DLL's from
# latuviitta.org/documents/Spatialite_4.0_test_with_jre_1.6.zip
# Step 1: Unzip and copy the spatialite DLL into the Python DLL library

# Recompile the sqlite3 DLL from the amalgamation as follows
# Step 0: Add '#define SQLITE_ENABLE_RTREE' to the sqlite3.c file
# Step 1: gcc -c sqlite3.c
# Step 2: gcc -shared -o sqlite3.dll sqlite3.o
# Step 3: Place the DLL in the python DLL library

# Add libgeo-3-3-1.dll to python DLL library
  • 1
    Are you confident that your ogr build includes support for spatialite? Can you find ogrinfo command line tool, and try "ogrinfo --formats"? – BradHards Sep 11 '14 at 22:11
  • @BradHards i assume that command should list "SQLite (read/write)" vs (readonly) if ogr includes support? – fluidmotion Sep 12 '14 at 12:19
  • Mine says: "SQLite -vector- (rw+v): SQLite / Spatialite". I should really have asked for the output of "ogrinfo --format sqlite", which will tell you whether the SPATIALITE option is supported (it'll be in the CreationOptionsList, along with METADATA and INIT_WITH_EPSG options, if it is) – BradHards Sep 13 '14 at 3:31
  • 1
    is it strange that mine produces the same list of formats with or without the 'sqlite' appended to 'ogrinfo --formats' (--format is not accepted argument). Not listing of CreationOptions or anything else.. - not trying to highjack the question, but need to know as well. – fluidmotion Sep 13 '14 at 19:12
1

as @BradHards mentioned - it may be that the install of GDAL with anaconda is lacking support for spatialite. this google group thread indicates GDAL is a recent addition to the anaconda repo, possibly still with some issues. could try another distro - or go a more manual route reinstalling GDAL without conda.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.