B4A Library Spatialite

warwound

Expert
Licensed User
Longtime User
A bit of Googling suggests that the spatialite library should work in plain java - and therefore b4j.
But your exception shows that java fails to find and load the .so library file.

Can you find out what is the value of 'java.library.path' and then copy the .so file to this location?
 

gvoulg

Member
Licensed User
Longtime User
Hi Martin
You mean the libjsqlite.so file thats inside /lib/x86 directory in spatialite.jar?
Tried to copy it in different directories on my computer with no success.
I get 'java.library.path' with java -xshowsettings: properties in command line window
I get same error log
Regards
 

Lykaion

Member
Licensed User
Longtime User
Hi everybody, I have a little problem and I hope to find some help here
This is my code:

B4X:
Dim DBCon As Spatialite_Database
    Dim DBRec As Spatialite_TableResult
    Dim sqlcostanti As Spatialite_Constants
    'connessione all'archivio
    DBCon.Initialize()
    DBCon.Open(File.DirDefaultExternal, spatialite.nomedb, sqlcostanti.SQLITE_OPEN_READWRITE)
    DBRec = DBCon.GetTable("SELECT astext(ST_Transform(geomfromtext('POINT(11 40)', 4326),3857))")
        Log(DBRec.Rows(0,0))
    DBCon.Close

I think the code is ok, is really simple, but it give me always null values in the log and when i remove the ST_Transform it work fine.
I've tried to change each srids but the result not change...
If is useful, watching for my spatialite version the system response is 4.0.0, anyone had similar problems?
Every help is really apreciated
 

M6SOFT

Member
Licensed User
Longtime User
Try
AsText(Transform(GeomFromText('POINT(11 40)',4326), 3857))
 

Lykaion

Member
Licensed User
Longtime User
Try
AsText(Transform(GeomFromText('POINT(11 40)',4326), 3857))

I've found the solution
I've tried to create the db from sqlite library, unfortunately with this way the system can't create the spatialite structure and relative tables, creating the db in my pc and after copy the file all works fine!
 

MrYang

New Member
Licensed User
Longtime User
Hi Martin
I used two libraries in the same project,LibGDX library and spatialite library.

B4X:
    Dim SpatialiteConstants As Spatialite_Constants
    Dim SpatialiteDatabase As Spatialite_Database
    Dim lgdx As LibGDX

    SpatialiteDatabase.Initialize
    SpatialiteDatabase.Open(DATABASE_PATH,DATABASE_FILENAME,SpatialiteConstants.SQLITE_OPEN_READWRITE)
    lgdx.Initialize("")

I got a problem:

PackageAdded: package:b4a.SpatialiteTest1
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 424)
java.lang.UnsatisfiedLinkError: No implementation found for void jsqlite.Database.internal_init() (tried Java_jsqlite_Database_internal_1init and Java_jsqlite_Database_internal_1init__)
at jsqlite.Database.internal_init(Native Method)
at jsqlite.Database.<clinit>(Database.java:1025)
at uk.co.martinpearman.b4a.spatialite.Database.Initialize(Database.java:76)
at b4a.SpatialiteTest1.main._activity_create(main.java:424)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at b4a.SpatialiteTest1.main.afterFirstLayout(main.java:104)
at b4a.SpatialiteTest1.main.access$000(main.java:17)
at b4a.SpatialiteTest1.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6360)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
If you can change the target version......targetSdkVersion xx....sample 21 or 23...
 

warwound

Expert
Licensed User
Longtime User
Spatialite library updated to version 2.00

This update makes no changes to the library methods, instead it contains an updated version of the native C spatialite library.
Version 5.0.0 of spatialite native C library is wrapped, this version supports the following CPU architectures:

arm64-v8a
armeabi-v7a
x86_64

Download the latest version from:
 

synasir

Member
Licensed User
Longtime User
Hi Martin,

I am using your Spatialite Library from http://b4a.martinpearman.co.uk/spatialite/ (Spatialite_library_files_v2.20.zip).

I think that there might be a bug in your library.

Here are my steps.

1. Downloaded spatialite_gui-NG-5.0.0-win-amd64.7z from https://www.gaia-gis.it/gaia-sins/windows-bin-amd64-latest/
2. Created a new sqlite db file which populated the spatial_ref_sys table.
3. Tested several WGS84 conversions using the spatialite_gui app.

SELECT ST_AsText(ST_Transform(ST_GeomFromText('POINT(102.169998 3.405541)', 4326),3375))

POINT(463822.411401 376746.015235)


SELECT ST_AsText(ST_Transform(ST_GeomFromText('POINT(112.960079 1.984808)', 4326),3376))

POINT(364271.879307 219602.859137)


SELECT ST_AsText(ST_Transform(ST_GeomFromText('POINT(102.169998 3.405541)', 4326),3168)

POINT(464016.543346 376740.098876)

All are correct according to EPSG.IO.

Ran the scripts again in B4A.

The 4326 to 3375 and 3376 conversions are correct.

File.Copy(File.DirAssets,"db.sqlite", File.DirInternal, "db.sqlite")
Dim DBCon As Spatialite_Database
Dim DBRec As Spatialite_TableResult
Dim sqlcostanti As Spatialite_Constants
DBCon.Initialize()
DBCon.Open(File.DirInternal, "db.sqlite", sqlcostanti.SQLITE_OPEN_READONLY)


DBRec = DBCon.GetTable("SELECT ST_AsText(ST_Transform(ST_GeomFromText('POINT(102.169998 3.405541)', 4326),3168))")
Log(DBRec.Rows(0,0))

However for the 4326 to 3168 conversions, I got this

POINT(463847.87424 376717.570411) - Incorrect

as compared to

POINT(464016.543346 376740.098876) - Correct


Also for your information, if I were to reverse the conversion from 3168 back to 4326 using the incorrect output, the WGS84 coordinate is correct.

Thanks for your time and effort for the great library.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…