SpatiaLite for iOS
v5.1.0iOSSpatiaLite 5.1.0 for React Native apps on iOS, precompiled for arm64 devices and simulators as @crossbind/port-spatialite-ios.
npm install @crossbind/port-spatialite-ios@betaInstall
The whole flow, including Expo, is in the React Native playbook.
Usage
The examples the WebAssembly page runs, as iOS compiles them: the same headers and the same calls. They are checked on the WebAssembly build.
Store points and measure the distance between them
The calls every SpatiaLite program starts with: spatialite_alloc_connection and spatialite_init_ex register the spatial SQL functions on a SQLite connection, InitSpatialMetaData creates the metadata tables and AddGeometryColumn adds a geometry column. GeomFromText reads WKT, and ST_Distance(a, b, 1) measures on the WGS 84 ellipsoid.
5.1.0 3 Istanbul 0 km, Izmir 327 km, Ankara 350 km
Find places in a map view and the nearest ones with a spatial index
CreateSpatialIndex keeps an R*Tree of the bounding boxes of a geometry column, and queries reach it through virtual tables: SpatialIndex returns the rows inside a box such as the map view, and KNN2 the rows nearest to a point with their distance in metres.
Bursa, Edirne, Istanbul, Izmir Bursa 133 km, Istanbul 189 km, Ankara 201 km
Measure areas and distances in metres
SpatiaLite measures in the units of the coordinates, so ST_Area of a longitude/latitude polygon comes out in square degrees. ST_Transform to a projected CRS, here UTM zone 35N (EPSG:32635), gives square metres and metres, stretched the further a shape lies from the zone; ST_Distance(a, b, 1) measures on the ellipsoid with no projection at all.
0.000200 square degrees, 1868349 m² 350462 m in UTM zone 35N, 350082 m on the ellipsoid
Reproject coordinates between EPSG codes
ST_Transform moves a geometry to another reference system through PROJ, which reads the proj.db the build preloads. InitSpatialMetaData(1) registers the 6,559 EPSG codes SpatiaLite knows in spatial_ref_sys, where their names are too.
WGS 84 / Pseudo-Mercator: POINT(3225860.732004 5013551.237223) WGS 84 / UTM zone 35N: POINT(666370.505017 4541552.487191) back to WGS 84: POINT(28.9784 41.0082)
Read GeoJSON in and write a FeatureCollection out
GeomFromGeoJSON reads a GeoJSON geometry into a SpatiaLite geometry, and AsGeoJSON writes one back rounded to the decimals you ask for. SQLite's JSON functions wrap the rows into a FeatureCollection that Leaflet, MapLibre or OpenLayers load as it is.
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"name":"Galata Tower"},"geometry":{"type":"Point","coordinates":[28.97413,41.02564]}},{"type":"Feature","properties":{"name":"Galata Bridge"},"geometry":{"type":"LineString","coordinates":[[28.97336,41.01963],[28.97139,41.02402]]}}]}What is different on iOS
pod installcompiles your headers with the library through the plugin's podspec, and the app build links the result.- Named imports from
./native/<header>.hwork as on the web:await initNative()once, then call the classes. - There is no
m.FSand no/memfs: files live in the app's own storage, and your C++ takes their paths. - No Worker and no COOP or COEP:
runtime: 'mt'uses pthreads directly.
Other platforms
- SpatiaLite overview: the apps, every platform's setup and the packages.
- SpatiaLite for WebAssembly: browsers, Node.js and edge runtimes.
- SpatiaLite for Android: React Native apps on Android.
- SpatiaLite for WASI: command-line programs under wasmtime.
Facts on this page come from the port manifests in the repository and from what npm served on beta when the site was built. See the Libraries guide for the full consumer flow.