GDAL for Android
v3.13.3AndroidGDAL 3.13.3 for React Native apps on Android, precompiled for arm64-v8a devices and the x86_64 emulator as @crossbind/port-gdal-android.
npm install @crossbind/port-gdal-android@betaInstall
The whole flow, including Expo, is in the React Native playbook.
Usage
The examples the WebAssembly page runs, as Android compiles them: the same headers and the same calls. They are checked on the WebAssembly build.
Convert GeoJSON to GeoPackage and Shapefile, reprojected
Format conversion is what GDAL is used for most, as the ogr2ogr tool: GDALVectorTranslate takes the same arguments, here -f for the format and -t_srs for the coordinate system. The input is text handed over through /vsimem/, and a zipped Shapefile is one file.
GPKG: 3 features, EPSG:3857, extent 3021523 4639455 3657925 5013551 ESRI Shapefile: 3 features, EPSG:32635, extent 512465 4252837 1000822 4541552
Write a GeoTIFF and read its georeferencing back
GDALCreate writes a raster with GDALSetGeoTransform and a CRS from OSRImportFromEPSG; GDALOpenEx opens it again as it opens any of the formats GDAL reads, and the size, band type, geotransform and CRS come back from the dataset. GDALInfo returns the report the gdalinfo tool prints.
GTiff, 200 x 150 pixels, 1 band of Float32 origin 500000, 4450000; pixel size 30 x -30 WGS 84 / UTM zone 35N, EPSG:32635 values 100 to 597 Upper Left ( 500000.000, 4450000.000) ( 27d 0' 0.00"E, 40d12' 1.44"N) Lower Right ( 506000.000, 4445500.000) ( 27d 4'13.64"E, 40d 9'35.41"N)
Reproject a raster and write a Cloud-Optimized GeoTIFF
GDALWarp reprojects as the gdalwarp tool does, here into a virtual raster that is computed while it is read; GDALTranslate with -of COG then writes it tiled, compressed and with overviews, the layout web maps read with HTTP range requests.
1093 x 672 pixels of 0.000322 x 0.000322 degrees LAYOUT=COG, COMPRESSION=DEFLATE, 256 x 256 blocks overviews 546 x 336, 273 x 168, 136 x 84
Hillshade, slope and contour lines from an elevation model
GDALDEMProcessing is the gdaldem tool: hillshade, slope, aspect, roughness, TRI and TPI by name. GDALContourGenerateEx draws the contour lines gdal_contour draws, into any vector layer; here an in-memory one, measured with OGR_G_Length.
hillshade: 12.00 to 255.00, mean 156.63, checksum 58516 slope: 0.00 to 42.97, mean 27.46, checksum 54054 contours every 100 m: 11 lines from 200 to 900 m, 46.9 km long
Read features and filter them by attribute and area
OGR reads every vector format through one API: the schema from OGR_L_GetLayerDefn, then OGR_L_GetNextFeature over the features that pass OGR_L_SetAttributeFilter, a SQL WHERE clause, and OGR_L_SetSpatialFilterRect. Open options turn the lon and lat columns of a CSV into points.
sensors: 6 features of Point, fields id Integer, kind String, reading Real 1 air 31.5 POINT (28.9784 41.0082) 3 water 22.7 POINT (27.1428 38.4237) 6 air 27.3 POINT (29.061 40.1885)
What is different on Android
- The React Native plugin compiles your headers with the library inside Gradle's native build, so
npm run androidbuilds everything. - 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
- GDAL overview: the apps, every platform's setup and the packages.
- GDAL for WebAssembly: browsers, Node.js and edge runtimes.
- GDAL for iOS: React Native apps on iOS.
- GDAL 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.