sevar83 / android-spatialite

Spatialite database JNI wrapper for Android
101 stars 48 forks source link
android android-spatialite database geometry-data geospatial-data spatialite

Release

android-spatialite

WHAT IS THIS?

WHEN DO I NEED IT?

GETTING STARTED

If you know basic SQLite, there's almost nothing to learn. The API is 99% the same as the Android SQLite API (as of API level 15). The main difference is the packaging. Use org.spatialite.database.XYZ instead of android.database.sqlite.XYZ and org.spatialite.XYZ instead of android.database.XYZ. Same applies to the other classes - all platform SQLiteXYZ classes have their Spatialite versions.

Gradle

1) Have this in your project's build.gradle:

allprojects {
  repositories {
    ...
    maven { url "https://jitpack.io" }
  }
}

2) Add the following to your module's build.gradle:

implementation 'com.github.sevar83:android-spatialite:<LATEST_VERSION>'

EXAMPLE CODE

There is a very simple and useless example in the app module. Another example is the SpatiAtlas experiment.

HOW IT WORKS?

Works the same way as the platform SQLite. It's accessible through Java/JNI wrappers around the Spatialite C library. The Spatialite wrappers were derived and adapted from the platform SQLite wrappers (the standard Android SQLite API).

Other FAQ

What is Spatialite?

Simply: Spatialite = SQLite + advanced geospatial support.
Spatialite is a geospatial extension to SQLite. It is a set of few libraries written in C to extend SQLite with geometry data types and many SQL functions above geometry data. For more info: https://www.gaia-gis.it/gaia-sins/

Is there a list of all supported Spatialite functions?

Yes - http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.4.0.html

Does it use JDBC?

No. It uses cursors - the suggested lightweight approach to access SQL used in the Android platform instead of the heavier JDBC.

64-bit architectures supported?

Yes. It builds for arm64-v8a and x86_64. mips64 is not tested.

Reducing the APK size.

This library is distributed as multi-architecture AAR file. By default Gradle will produce a universal APK including the native .so libraries compiled for all supported CPU architectures. Usually that's unacceptable for large libraries like this. But that's easily fixed by using Gradle's "ABI splits" feature. The following gradle code will produce a separate APK per each architecture. The APK size is reduced few times.

android {
    splits {
        abi {
            enable true
                reset()
                include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
            }
        }
    }
}

What libraries are packaged currently?

REQUIREMENTS

Min SDK 16

MIGRATION TO 2.0+

  1. Remove calls to SQLiteDatabase.loadLibs(). Now it is automatically done.
  2. Replace all occasions of import org.spatialite.Cursor; with import android.database.Cursor;
  3. Replace all occasions of import org.spatialite.database.SQLite***Exception; with import android.database.sqlite.SQLite***Exception;

CHANGES

2.0.1

2.0.0

CREDITS

The main ideas used here were borrowed from:

SUPPORT

If you like this library, please consider...

Buy Me A Coffee

KNOWN PROJECTS USING THIS LIBRARY

LICENSE

Apache License 2.0