GEOS for Android
v3.15.0AndroidGEOS 3.15.0 for React Native apps on Android, precompiled for arm64-v8a devices and the x86_64 emulator as @crossbind/port-geos-android.
npm install @crossbind/port-geos-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.
Intersect, unite and subtract two polygons
Overlay is the most used part of GEOS: GEOSIntersection_r, GEOSUnion_r and GEOSDifference_r on shapes read from WKT, with GEOSArea_r to measure the result.
3.15.0-CAPI-1.21.0 POLYGON ((5 5, 5 10, 10 10, 10 5, 5 5)) 25 175 75
Test points against a prepared polygon
Point in polygon is the most common spatial question. GEOSPrepare_r indexes the polygon once; GEOSPreparedContainsXY_r and GEOSPreparedIntersectsXY_r then answer per point and differ only on the boundary, and GEOSPreparedRelate_r gives the full DE-9IM matrix.
2 2: contains true, intersects true 5 5: contains false, intersects false 10 5: contains false, intersects true 12 5: contains false, intersects false 212101212
Measure area, length and distance
GEOSArea_r, GEOSLength_r and GEOSDistance_r in the units of the coordinates, GEOSNearestPoints_r for where two shapes come closest, and GEOSGetCentroid_r. GEOS works in the plane, so project longitude and latitude before measuring.
1200 140 60 15 LINESTRING (40 30, 52 39) POINT (20 15)
Buffer points, lines and polygons
GEOSBuffer_r turns a point into a circle of straight segments, GEOSBufferWithStyle_r sets the caps and joins of a line's corridor, a negative distance shrinks a polygon, and GEOSOffsetCurve_r draws a parallel line.
312.1445 1000 1078.0361 POLYGON ((2 2, 2 18, 18 18, 18 2, 2 2)) 256 LINESTRING (0 5, 100 5)
Find why a polygon is invalid and repair it
GEOSisValid_r and GEOSisValidReason_r say whether a shape breaks the OGC rules, what is wrong and where. GEOSMakeValidWithParams_r repairs it two ways, which agree on a bowtie and differ on a hole that leaks out of its shell.
false Self-intersection[5 5] MULTIPOLYGON (((5 5, 10 10, 10 0, 5 5)), ((0 0, 0 10, 5 5, 0 0))) true 50 Self-intersection[5 10] linework 150 structure 75
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
- GEOS overview: the apps, every platform's setup and the packages.
- GEOS for WebAssembly: browsers, Node.js and edge runtimes.
- GEOS for iOS: React Native apps on iOS.
- GEOS 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.