Skip to content

Commit

Permalink
feat(spatialite5): upgrade to spatialite version 5 and ensure RTTOPO …
Browse files Browse the repository at this point in the history
…is correctly installed. resolves #11. related #10
  • Loading branch information
missinglink committed Jul 15, 2019
1 parent b25482e commit 7e43a6b
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 11 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Dockerfile
.dockerignore
node_modules
tmp
build/tmp
package-lock.json
*.md
*.db
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
tmp
build/tmp
package-lock.json
*.db
*.db-journal
Expand Down
20 changes: 20 additions & 0 deletions build/rttopo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
REPO='https://git.osgeo.org/gitea/rttopo/librttopo.git'
BRANCH='master'

mkdir -p tmp
cd tmp

[[ -d "${RELEASE}" ]] || git clone "${REPO}"

cd 'librttopo'
git checkout "${BRANCH}"

make clean
./autogen.sh
./configure
make -j8
make check
make install

# /usr/local/include/
48 changes: 48 additions & 0 deletions build/spatialite-tools4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
HOST='http://www.gaia-gis.it/gaia-sins'
RELEASE='spatialite-tools-4.4.0-RC0'

mkdir -p tmp
cd tmp

[[ -f "${RELEASE}.tar.gz" ]] || curl -LO "${HOST}/${RELEASE}.tar.gz"
[[ -d "${RELEASE}" ]] || tar xvzf "${RELEASE}.tar.gz"

cd "${RELEASE}"
make clean

# build flags
export CPPFLAGS=""
export LDFLAGS=""

# location of spatialite
export LDFLAGS="${LDFLAGS} -L/usr/local/lib"

# location of sqlite
SQLITE3='/usr/local/opt/sqlite'
export CPPFLAGS="${CPPFLAGS} -I${SQLITE3}/include"
export LDFLAGS="${LDFLAGS} -L${SQLITE3}/lib"

# location of spatialite
SPATIALITE="$(pwd)/libspatialite-5.0.0-beta0"
export CPPFLAGS="${CPPFLAGS} -I${SQLITE3}/include"
export LDFLAGS="${LDFLAGS} -L${SQLITE3}/lib"

# # location of proj
# PROJ6='/usr/local/Cellar/proj/6.1.0'
# export CPPFLAGS="${CPPFLAGS} -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H" # required flag to use proj6
# export CPPFLAGS="${CPPFLAGS} -I${PROJ6}/include"
# export LDFLAGS="-L${PROJ6}/lib"

# location of libxml2
LIBXML2='/usr/local/Cellar/libxml2/2.9.9_2'
export CPPFLAGS="${CPPFLAGS} -I${LIBXML2}/include/libxml2"
export LDFLAGS="${LDFLAGS} -L${LIBXML2}/lib"

./configure --disable-dependency-tracking
make -j8

./spatialite -silent :memory: <<SQL
SELECT 'sqlite_version', sqlite_version();
SELECT 'spatialite_version', spatialite_version();
SQL
72 changes: 72 additions & 0 deletions build/spatialite5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
HOST='http://www.gaia-gis.it/gaia-sins/libspatialite-sources'
RELEASE='libspatialite-5.0.0-beta0'

mkdir -p tmp
cd tmp

[[ -f "${RELEASE}.tar.gz" ]] || curl -LO "${HOST}/${RELEASE}.tar.gz"
[[ -d "${RELEASE}" ]] || tar xvzf "${RELEASE}.tar.gz"

cd "${RELEASE}"
make clean

# build flags
export CPPFLAGS=""
export LDFLAGS=""

# location of sqlite
SQLITE3='/usr/local/opt/sqlite'
export CPPFLAGS="${CPPFLAGS} -I${SQLITE3}/include"
export LDFLAGS="${LDFLAGS} -L${SQLITE3}/lib"

# check sqlite was compiled with 'ENABLE_RTREE'
"${SQLITE3}/bin/sqlite3" :memory: 'PRAGMA compile_options' | grep -q ENABLE_RTREE
if [[ $? != 0 ]]; then
2>&1 echo 'sqlite3 was not compiled with the ENABLE_RTREE extension'
exit 1
fi

# check sqlite was compiled with 'ENABLE_COLUMN_METADATA'
"${SQLITE3}/bin/sqlite3" :memory: 'PRAGMA compile_options' | grep -q ENABLE_COLUMN_METADATA
if [[ $? != 0 ]]; then
2>&1 echo 'sqlite3 was not compiled with the ENABLE_COLUMN_METADATA extension'
exit 1
fi

# location of proj
PROJ6='/usr/local/Cellar/proj/6.1.0'
export CPPFLAGS="${CPPFLAGS} -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H" # required flag to use proj6
export CPPFLAGS="${CPPFLAGS} -I${PROJ6}/include"
export LDFLAGS="-L${PROJ6}/lib"

# location of libxml2
LIBXML2='/usr/local/Cellar/libxml2/2.9.9_2'
export CPPFLAGS="${CPPFLAGS} -I${LIBXML2}/include/libxml2"
export LDFLAGS="${LDFLAGS} -L${LIBXML2}/lib"

# # location of rttopo
# RTTOPO="$(pwd)/librttopo"
# export CPPFLAGS="${CPPFLAGS} -DGEOS_USE_ONLY_R_API" # required flag to use rttopo?
# export CPPFLAGS="${CPPFLAGS} -I${RTTOPO}/headers"
# export LDFLAGS="${LDFLAGS} -L${RTTOPO}/src"

./configure \
--disable-dependency-tracking \
--enable-rttopo=yes \
--enable-proj=yes \
--enable-geos=yes \
--enable-gcp=yes \
--enable-libxml2=yes

make -j8
make install

"${SQLITE3}/bin/sqlite3" :memory: <<SQL
SELECT 'sqlite_version', sqlite_version();
SELECT load_extension('./src/.libs/mod_spatialite.so');
SELECT 'spatialite_version', spatialite_version();
SELECT 'rttopo_version', rttopo_version();
SQL
36 changes: 32 additions & 4 deletions module/spatialite/InitExtension.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
const os = require('os')
const path = require('path')
const Sqlite = require('../../sqlite/Sqlite')

const EXTENSION_PATHS = [
path.resolve(__dirname, '../../build/', os.platform() + '-' + os.arch()),
path.resolve(__dirname, '../../build/tmp/libspatialite-5.0.0-beta0/src/.libs'),
process.env.SPATIALITE_EXTENSION_PATH,
''
]

const EXTENSION_INIT = [
'mod_spatialite',
'mod_spatialite.so',
'mod_spatialite.dylib',
'libspatialite.so',
'libspatialite.so.5',
'libspatialite.so',
process.env.SPATIALITE_EXTENSION_INIT
]

// load the spatialite extension
class InitExtension extends Sqlite {
load (db) {
for (let extpath of EXTENSION_PATHS) {
for (let extinit of EXTENSION_INIT) {
try {
db.loadExtension(path.join(extpath, extinit))
return true
} catch (e) { }
}
}
return false
}
create (db) {
try {
db.loadExtension('mod_spatialite')
} catch (e) {
this.error('LOAD EXTENSION', e)
if (!this.load(db)) {
this.error('LOAD EXTENSION')
process.exit(1) // fatal error
}
}
Expand Down
17 changes: 10 additions & 7 deletions test/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports.tests.dependencies = (test, common) => {

res = db.prepare(`SELECT spatialite_version()`).get()
actual = semver.coerce(res['spatialite_version()'])
expected = semver.coerce('4.3.0a')
expected = semver.coerce('5.0.0')
t.true(semver.gte(actual, expected), 'spatialite_version')

res = db.prepare(`SELECT spatialite_target_cpu()`).get()
Expand All @@ -48,8 +48,10 @@ module.exports.tests.dependencies = (test, common) => {
expected = semver.coerce('3.6.2-CAPI-1.10.2 4d2925d6')
t.true(semver.gte(actual, expected), 'geos_version')

// res = db.prepare(`SELECT lwgeom_version()`).get()
// t.equals(res['lwgeom_version()'], null, 'lwgeom_version')
res = db.prepare(`SELECT rttopo_version()`).get()
actual = semver.coerce(res['rttopo_version()'])
expected = semver.coerce('1.1.0')
t.true(semver.gte(actual, expected), 'rttopo_version')

res = db.prepare(`SELECT libxml2_version()`).get()
actual = semver.coerce(res['libxml2_version()'])
Expand All @@ -75,10 +77,11 @@ module.exports.tests.features = (test, common) => {
t.equals(res['HasMathSQL()'], 1, 'HasMathSQL')
}, 'HasMathSQL')

t.doesNotThrow(() => {
res = db.prepare(`SELECT HasGeoCallbacks()`).get()
t.equals(res['HasGeoCallbacks()'], 1, 'HasGeoCallbacks')
}, 'HasGeoCallbacks')
// I don't believe this is required
// t.doesNotThrow(() => {
// res = db.prepare(`SELECT HasGeoCallbacks()`).get()
// t.equals(res['HasGeoCallbacks()'], 1, 'HasGeoCallbacks')
// }, 'HasGeoCallbacks')

t.doesNotThrow(() => {
res = db.prepare(`SELECT HasProj()`).get()
Expand Down

0 comments on commit 7e43a6b

Please sign in to comment.