문제

I am working with SpatiaLite for Android from Gaia-SINS using this tutorial.

I managed to create spatial database and it works fine. But I have problem getting distance between points (or any other geometry) in meters.

I was searching the web, and found many examples that uses Transform to get distance in meters. Projection that I use is 4326 and I insert points as POINT(Lon Lat). To calculate the distance I transform it to projection with SRID 3035.

The problem is that when I use transform on Android it returns NULL. I Compared it with SpatiaLite_GUI, in it this query works fine.

Can anyone say me why Transform on phone is not working? Is it because of the projection 3035 or something else?

[EDIT]

Here is simple SQL that is working in SpatiaLite GUI and not on Android.

SELECT Distance(
    Transform(GeomFromText('POINT(21.865466 43.327717)', 4326), 3035),
    Transform(GeomFromText('POINT(21.895659 43.32116)', 4326), 3035)) as Distance;

This query returns 2550.215591 in SpatiaLite GUI and 0.0 in Android. The 2.5km is correct distance.

The same query without Transform returns 0.030897 in both SpatiaLite GUI and Android.

SELECT Distance(
    GeomFromText('POINT(21.865466 43.327717)', 4326),
    GeomFromText('POINT(21.895659 43.32116)', 4326)) as Distance;
도움이 되었습니까?

해결책

Let me answer my own question.

The problem was in creating database. I am creating it in code and i haven't added spatialite_create() to create spatialite meta data in database.

Database db = new Database();
db.open(Constants.SQLITE_OPEN_READWRITE | Constants.SQLITE_OPEN_CREATE);
db.spatialite_create();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top