Skip to content

Compile the SpatiaLite source code into mod_spatialite to add spatial data support to SQLite using SELECT load_extension.

Notifications You must be signed in to change notification settings

tigawanna/spatialite-for-android-nodejs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spatialite for Android with Node.js Support

This project provides prebuilt Spatialite extensions for Android that can be used with SQLite to add spatial data support to your applications. The Spatialite library (version 5.0.0) has been cross-compiled using the Android NDK for multiple architectures to support different Android devices.

Why This Project Exists

Spatialite is a powerful spatial extension for SQLite that enables spatial/GIS functionality. However, the official Spatialite library does not provide direct support for Android platforms. This project bridges that gap by cross-compiling the Spatialite source code using the Android NDK, making it possible to use spatial functions in SQLite on Android devices.

As the developer, I personally wanted a reliable way to load Spatialite extensions into op-sqlite for React Native projects, which led to the forking of this repository with prebuilt binaries specifically for this purpose.

The project supports multiple Android architectures:

  • ARM64 (arm64-v8a)
  • ARMv7 (armeabi-v7a)
  • x86
  • x86_64

How to Run and Use

Prerequisites

  • Android NDK installed
  • Android API level 13 or higher

Build steps

cd jni
# i used version 27.3.13750724 , replace with whatever version you have
export ANDROID_NDK_HOME=~/Android/Sdk/ndk/27.3.13750724
export ANDROID_NDK_ROOT=$ANDROID_NDK_HOME

ndk-build clean
ndk-build

Using the Prebuilt Artifacts

The prebuilt artifacts are located in the /libs directory with separate folders for each supported Android architecture:

libs/
├── arm64-v8a/
│   └── libspatialite.so
├── armeabi-v7a/
│   └── libspatialite.so
├── x86/
│   └── libspatialite.so
└── x86_64/
    └── libspatialite.so

To confirm that they have the correct symbols

nm -D libs/x86/libspatialite.so | grep sqlite3_modspatialite_init
# Output:
009d5cd0 T sqlite3_modspatialite_init

Using with op-sqlite

To use the prebuilt Spatialite extension with op-sqlite in your React Native project:

  1. Place the appropriate libspatialite.so files in your Android project's libs folder
  2. Use the following code to load the extension:
import { open } from "@op-engineering/op-sqlite";

const opsqliteDb = open({
  name: "myDB",
});
const path = "libspatialite";
opsqliteDb.loadExtension(path, "sqlite3_modspatialite_init");

This will enable all Spatialite functions in your SQLite database, allowing you to perform spatial queries like:

SELECT ST_AsText(geometry_column) FROM your_table;
SELECT ST_Distance(point1, point2) FROM your_table;

Project Details

  • Spatialite Version: 5.0.0
  • Host Platform: Ubuntu 20.04 (x86_64 architecture)
  • Target Platform: Android API 13 (arm64-v8a and other architectures)
  • Build Status: Successful builds for all supported architectures (as of latest commit: d1c482f7)

Compilation Details

The library is compiled using the Android NDK from the original Spatialite source code. The build process includes several dependencies to provide full Spatialite functionality:

  • GEOS (Geometry Engine - Open Source)
  • PROJ (Cartographic Projections Library)
  • libxml2
  • JSON-C
  • Iconv
  • LZMA/XZ support

About

Compile the SpatiaLite source code into mod_spatialite to add spatial data support to SQLite using SELECT load_extension.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 55.8%
  • Makefile 16.7%
  • C++ 10.4%
  • HTML 8.3%
  • Shell 5.2%
  • Python 1.1%
  • Other 2.5%