Skip to content

breekmd/SpatialiteForms

Repository files navigation

SpatialiteForms

A nuget package that enables spatialite for Xamarin Forms. As an example this allows to do offline reverse geocoding on mobile devices (this barely scratches the surface of Spatialite, but it's a very common usecase for mobile dev)

It's entirely based on:

If you find this library useful, please support the above projects.

What this means is that it exposes a SQLiteConnection that supports spatial SQL capabilities.

To enable this functionality native libraries/framework is required (apart from the nuget package itself) :

  1. Get Android libraries from here and add under libs folder, with build action as "AndroidNativeLibrary". Folder structure under Android project:
  .
 ├── Assets
 ├── ...
 ├── libs                    
 │   ├── armeabi-v7a       
 │       ├── libspatialite.so   
 │   ├── x86
 │       ├── libspatialite.so   
 └── ...
  1. Get iOS framework from here and add as Native Reference to iOS project

Targeted architecture (these architectures are compatible with most devices)

Platform Arch Comments
Android x86 will also run on x86_64
Android armeabi-v7a will also run on arm64-v8a
iOS x86_64 for emulators
iOS arm64 for devices starting with iPhone 5s

Supported Spatialite functionality

Functionality Android iOS
HasEpsg
HasFreeXL
HasGeoCallbacks
HasGeos
HasGeosAdvanced
HasGeosTrunk
HasIconv
HasLibxml2
HasMathSQL
HasProj

Spatialite component versions

Component Android version iOS version
Geos 3.5.0-CAPI-1.9.0 r4084 3.5.0-CAPI-1.9.0 r4084
Libxml2 2.9.1 2.9.4
Proj4 Rel. 4.9.2, 08 September 2015 Rel. 4.9.2, 08 September 2015
Spatialite 4.4.0-topo-1 4.4.0-RC1

There's small version mismatches which shouldn't cause problems, but please raise an issue if anything occurs.

Current versioning/capabilities information can be accessed via SpatialiteInfo property, available in the SpatialiteConnection class.

SpatialiteForms also allows to use "pre-packaged" database files using Assets folder in Android and Resources folder for iOS.

Usage

Example using countryData.db on how to prepackage a database with geometry data within the xamarin app and to get a Spatialite-capable SQLiteConnection.

Database countryData was created using Spatialite-GUI (very powerful tool) through which shape data was imported (shape data originated from here)

  1. Add countryData.db under Assets folder on Android (build action - Android asset) and Resources folder on iOS (build action - Bundle resource)

  2. Define a Region class

public class Region {  
  public string Name { get; set; }  
}
  1. Get the Spatialite capable SQLiteConnection
var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "countryData.db");
SpatialiteConnection spatialite = CrossSpatialiteForms.Current.GetSpatialiteConnection(dbPath, "countryData.db", true);

var info = spatialite.SpatialiteInfo;
var region = spatialite.SQLiteConnection.Query<Region>("select name from region where within(Makepoint(-100.7594387, 46.77519), geometry);").FirstOrDefault();

the result region should have the name of North Dakota

Again this is only a small thing of what spatialite is capable of, please check official Spatialite documentation for more details.

Nuget package

https://www.nuget.org/packages/Plugin.SpatialiteForms/

License

This project is licensed under GPL3

Spatialite libraries have been compiled from original source code and no changes were made to it.

If you believe that I have infringed your copyright in any way please let me know and I will remove any code that is your copyright ASAP.

About

Package that enables Spatialite functionality for Xamarin Forms (includes offline reverse geocoding for Xamarin Forms)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published