Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No such function: X #1

Open
deepy opened this issue Mar 19, 2013 · 7 comments
Open

No such function: X #1

deepy opened this issue Mar 19, 2013 · 7 comments

Comments

@deepy
Copy link

deepy commented Mar 19, 2013

Is X() and Y() not included?

@zhm
Copy link
Owner

zhm commented Mar 19, 2013

I tested it and the X() function works for me. Are you calling the spatialite function to initialize the plugin?

Example:

var sqlite = require('spatialite');
var db = new sqlite.Database(':memory:');

var query = "SELECT X(Centroid(GeomFromText('POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))'))) AS x;";

db.spatialite(function(err) {
  db.each(query, function(err, row) {
    console.log(row.x);
  });
});

@deepy
Copy link
Author

deepy commented Mar 19, 2013

Ah. My bad.

I don't suppose it's possible to do it with prepared statements somehow?

On Tue, Mar 19, 2013 at 5:32 PM, Zac McCormick notifications@github.comwrote:

I tested it and the X() function works for me. Are you calling the
spatialite function to initialize the plugin?

Example:

var sqlite = require('spatialite');var db = new sqlite.Database(':memory:');
var query = "SELECT X(Centroid(GeomFromText('POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))'))) AS x;";
db.spatialite(function(err) {
db.each(query, function(err, row) {
console.log(row.x);
});});


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-15130233
.

@zhm
Copy link
Owner

zhm commented Mar 19, 2013

I think it should be possible. This library just returns you a handle this library. So anything in their docs you should be able to do (with spatialite functions available).

@deepy
Copy link
Author

deepy commented Mar 19, 2013

Right, the problem I'm seeing there is how to properly create the
spatialized prepared statement.
If I create the prepared statement like normal and run
db.spatialite(function(err) {
db.each(qry.run(53.36548645,-6.457246577), function(err, row) {
console.log(row); });
});
I get an error about X() not existing, if I try to wrap db.prepare in the
same way then it fails and my prepared statement is undefined.

On Tue, Mar 19, 2013 at 6:03 PM, Zac McCormick notifications@github.comwrote:

I think it should be possible. This library just returns you a handle thishttps://github.com/developmentseed/node-sqlite3library. So anything in their docs you should be able to do (with
spatialite functions available).


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-15132314
.

@deepy
Copy link
Author

deepy commented Mar 19, 2013

Let's nevermind that for a moment.
I gave up and used the code you mentioned, now I'm getting exciting results.
It returns the correct row and then segfaults.

Following is the backtrace!

/home/deepy/locals/bin/node fingaltrees.js > out.txt 2> err.txt
*** glibc detected *** /home/deepy/locals/bin/node: free(): corrupted
unsorted chunks: 0x00000000023450a0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x76d76)[0x7f7a853fed76]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x6c)[0x7f7a85403aac]
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node(sqlite3_free+0x70)[0x7f7a850f1770]
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node(+0x3a0ac)[0x7f7a850fd0ac]
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node(+0x7186e)[0x7f7a8513486e]
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node(sqlite3_finalize+0x37)[0x7f7a85134a47]
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node(_ZN12node_sqlite39Statement8FinalizeEv+0x1c)[0x7f7a850e19cc]
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node(_ZN12node_sqlite39Statement8FinalizeEPNS0_5BatonE+0x11)[0x7f7a850e1a21]
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node(_ZN12node_sqlite39Statement7ProcessEv+0x67)[0x7f7a850e1b07]
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node(_ZN12node_sqlite39Statement14Work_AfterEachEP9uv_work_s+0x47)[0x7f7a850e1ca7]
/home/deepy/locals/bin/node(uv__work_done+0xa1)[0x6fb8d1]
/home/deepy/locals/bin/node[0x6f1e02]
/home/deepy/locals/bin/node[0x6f1eae]
/home/deepy/locals/bin/node(uv__io_poll+0x1bd)[0x6fe39d]
/home/deepy/locals/bin/node(uv_run+0xe8)[0x6f26f8]
/home/deepy/locals/bin/node(_ZN4node5StartEiPPc+0x150)[0x5b7ab0]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd)[0x7f7a853a6ead]
/home/deepy/locals/bin/node[0x5adafd]
======= Memory map: ========
00400000-00c4b000 r-xp 00000000 08:05 2630731
/home/deepy/locals/bin/node
00e4b000-00e60000 rwxp 0084b000 08:05 2630731
/home/deepy/locals/bin/node
00e60000-00e68000 rwxp 00000000 00:00 0
021be000-02527000 rwxp 00000000 00:00 0 [heap]
10553300000-10553385000 rwxp 00000000 00:00 0
312ab200000-312ab225000 rwxp 00000000 00:00 0
6b283600000-6b283700000 rwxp 00000000 00:00 0
10b1f5e0c000-10b1f5e40000 ---p 00000000 00:00 0
10b1f5e40000-10b1f5e60000 rwxp 00000000 00:00 0
10b1f5e60000-10b1f5e6c000 ---p 00000000 00:00 0
10e7362f1000-10e7362f2000 r-xp 00000000 00:00 0
11c585b36000-11c585b37000 r-xp 00000000 00:00 0
1495d6000000-1495d6f00000 ---p 00000000 00:00 0
1495d6f00000-1495d7000000 rwxp 00000000 00:00 0
1495d7000000-1495d7f00000 ---p 00000000 00:00 0
1495d7f00000-1495d8000000 rwxp 00000000 00:00 0
167ee30b0000-167ee32b0000 rwxp 00000000 00:00 0
1b9220800000-1b9220835000 rwxp 00000000 00:00 0
218be0baa000-218be0bab000 r-xp 00000000 00:00 0
2881cdb00000-2881cdc00000 rwxp 00000000 00:00 0
2af441d00000-2af441d25000 rwxp 00000000 00:00 0
2b890ec9a000-2b890ec9b000 r-xp 00000000 00:00 0
2d85570d8000-2d8557100000 ---p 00000000 00:00 0
2d8557100000-2d8557105000 rwxp 00000000 00:00 0
2d8557105000-2d8557106000 ---p 00000000 00:00 0
2d8557106000-2d85571ff000 rwxp 00000000 00:00 0
2d85571ff000-2d8557200000 ---p 00000000 00:00 0
2d8557200000-2d8557205000 rwxp 00000000 00:00 0
2d8557205000-2d8557206000 ---p 00000000 00:00 0
2d8557206000-2d85572ff000 rwxp 00000000 00:00 0
2d85572ff000-2d85770d8000 ---p 00000000 00:00 0
30cab3300000-30cab3400000 rwxp 00000000 00:00 0
379c2611d000-379c2611e000 r-xp 00000000 00:00 0
7f7a7c000000-7f7a7c04c000 rwxp 00000000 00:00 0
7f7a7c04c000-7f7a80000000 ---p 00000000 00:00 0
7f7a815ad000-7f7a81c79000 r-xp 00000000 08:05 2647657
/home/deepy/temp/node_modules/spatialite/build/Release/spatialite.so
7f7a81c79000-7f7a81e79000 ---p 006cc000 08:05 2647657
/home/deepy/temp/node_modules/spatialite/build/Release/spatialite.so
7f7a81e79000-7f7a81e92000 rwxp 006cc000 08:05 2647657
/home/deepy/temp/node_modules/spatialite/build/Release/spatialite.so
7f7a81e92000-7f7a81e94000 rwxp 00000000 00:00 0
7f7a81e94000-7f7a81ea7000 r-xp 00000000 08:05 1576589
/lib/x86_64-linux-gnu/libresolv-2.13.so
7f7a81ea7000-7f7a820a6000 ---p 00013000 08:05 1576589
/lib/x86_64-linux-gnu/libresolv-2.13.so
7f7a820a6000-7f7a820a7000 r-xp 00012000 08:05 1576589
/lib/x86_64-linux-gnu/libresolv-2.13.so
7f7a820a7000-7f7a820a8000 rwxp 00013000 08:05 1576589
/lib/x86_64-linux-gnu/libresolv-2.13.so
7f7a820a8000-7f7a820aa000 rwxp 00000000 00:00 0
7f7a820aa000-7f7a820af000 r-xp 00000000 08:05 1576594
/lib/x86_64-linux-gnu/libnss_dns-2.13.so
7f7a820af000-7f7a822ae000 ---p 00005000 08:05 1576594
/lib/x86_64-linux-gnu/libnss_dns-2.13.so
7f7a822ae000-7f7a822af000 r-xp 00004000 08:05 1576594
/lib/x86_64-linux-gnu/libnss_dns-2.13.so
7f7a822af000-7f7a822b0000 rwxp 00005000 08:05 1576594
/lib/x86_64-linux-gnu/libnss_dns-2.13.so
7f7a822b0000-7f7a822b2000 r-xp 00000000 08:05 1576769
/lib/libnss_mdns4_minimal.so.2
7f7a822b2000-7f7a824b1000 ---p 00002000 08:05 1576769
/lib/libnss_mdns4_minimal.so.2
7f7a824b1000-7f7a824b2000 rwxp 00001000 08:05 1576769
/lib/libnss_mdns4_minimal.so.2
7f7a824b2000-7f7a824bd000 r-xp 00000000 08:05 1576604
/lib/x86_64-linux-gnu/libnss_files-2.13.so
7f7a824bd000-7f7a826bc000 ---p 0000b000 08:05 1576604
/lib/x86_64-linux-gnu/libnss_files-2.13.so
7f7a826bc000-7f7a826bd000 r-xp 0000a000 08:05 1576604
/lib/x86_64-linux-gnu/libnss_files-2.13.so
7f7a826bd000-7f7a826be000 rwxp 0000b000 08:05 1576604
/lib/x86_64-linux-gnu/libnss_files-2.13.so
7f7a826be000-7f7a830bf000 rwxp 00000000 00:00 0
7f7a830bf000-7f7a830c0000 ---p 00000000 00:00 0
7f7a830c0000-7f7a838c0000 rwxp 00000000 00:00 0
7f7a838c0000-7f7a838c1000 ---p 00000000 00:00 0
7f7a838c1000-7f7a840c1000 rwxp 00000000 00:00 0
7f7a840c1000-7f7a840c2000 ---p 00000000 00:00 0
7f7a840c2000-7f7a848c2000 rwxp 00000000 00:00 0
7f7a848c2000-7f7a848c3000 ---p 00000000 00:00 0
7f7a848c3000-7f7a850c3000 rwxp 00000000 00:00 0
7f7a850c3000-7f7a85184000 r-xp 00000000 08:05 1057331
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node
7f7a85184000-7f7a85383000 ---p 000c1000 08:05 1057331
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node
7f7a85383000-7f7a85388000 rwxp 000c0000 08:05 1057331
/home/deepy/temp/node_modules/spatialite/node_modules/sqlite3/build/Release/node_sqlite3.node
7f7a85388000-7f7a85508000 r-xp 00000000 08:05 1576588
/lib/x86_64-linux-gnu/libc-2.13.so
7f7a85508000-7f7a85708000 ---p 00180000 08:05 1576588
/lib/x86_64-linux-gnu/libc-2.13.so
7f7a85708000-7f7a8570c000 r-xp 00180000 08:05 1576588
/lib/x86_64-linux-gnu/libc-2.13.so
7f7a8570c000-7f7a8570d000 rwxp 00184000 08:05 1576588
/lib/x86_64-linux-gnu/libc-2.13.so
7f7a8570d000-7f7a85712000 rwxp 00000000 00:00 0
7f7a85712000-7f7a85729000 r-xp 00000000 08:05 1576606
/lib/x86_64-linux-gnu/libpthread-2.13.so
7f7a85729000-7f7a85928000 ---p 00017000 08:05 1576606
/lib/x86_64-linux-gnu/libpthread-2.13.so
7f7a85928000-7f7a85929000 r-xp 00016000 08:05 1576606
/lib/x86_64-linux-gnu/libpthread-2.13.so
7f7a85929000-7f7a8592a000 rwxp 00017000 08:05 1576606
/lib/x86_64-linux-gnu/libpthread-2.13.so
7f7a8592a000-7f7a8592e000 rwxp 00000000 00:00 0
7f7a8592e000-7f7a85943000 r-xp 00000000 08:05 1572869
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f7a85943000-7f7a85b43000 ---p 00015000 08:05 1572869
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f7a85b43000-7f7a85b44000 rwxp 00015000 08:05 1572869
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f7a85b44000-7f7a85bc5000 r-xp 00000000 08:05 1576595
/lib/x86_64-linux-gnu/libm-2.13.so
7f7a85bc5000-7f7a85dc4000 ---p 00081000 08:05 1576595
/lib/x86_64-linux-gnu/libm-2.13.so
7f7a85dc4000-7f7a85dc5000 r-xp 00080000 08:05 1576595
/lib/x86_64-linux-gnu/libm-2.13.so
7f7a85dc5000-7f7a85dc6000 rwxp 00081000 08:05 1576595
/lib/x86_64-linux-gnu/libm-2.13.so
7f7a85dc6000-7f7a85eae000 r-xp 00000000 08:05 1835012
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7f7a85eae000-7f7a860ae000 ---p 000e8000 08:05 1835012
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7f7a860ae000-7f7a860b6000 r-xp 000e8000 08:05 1835012
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7f7a860b6000-7f7a860b8000 rwxp 000f0000 08:05 1835012
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7f7a860b8000-7f7a860cd000 rwxp 00000000 00:00 0
7f7a860cd000-7f7a860d4000 r-xp 00000000 08:05 1576608
/lib/x86_64-linux-gnu/librt-2.13.so
7f7a860d4000-7f7a862d3000 ---p 00007000 08:05 1576608
/lib/x86_64-linux-gnu/librt-2.13.so
7f7a862d3000-7f7a862d4000 r-xp 00006000 08:05 1576608
/lib/x86_64-linux-gnu/librt-2.13.so
7f7a862d4000-7f7a862d5000 rwxp 00007000 08:05 1576608
/lib/x86_64-linux-gnu/librt-2.13.so
7f7a862d5000-7f7a862d7000 r-xp 00000000 08:05 1576602
/lib/x86_64-linux-gnu/libdl-2.13.so
7f7a862d7000-7f7a864d7000 ---p 00002000 08:05 1576602
/lib/x86_64-linux-gnu/libdl-2.13.so
7f7a864d7000-7f7a864d8000 r-xp 00002000 08:05 1576602
/lib/x86_64-linux-gnu/libdl-2.13.so
7f7a864d8000-7f7a864d9000 rwxp 00003000 08:05 1576602
/lib/x86_64-linux-gnu/libdl-2.13.so
7f7a864d9000-7f7a864f9000 r-xp 00000000 08:05 1576610
/lib/x86_64-linux-gnu/ld-2.13.so
7f7a8655a000-7f7a866e2000 rwxp 00000000 00:00 0
7f7a866e5000-7f7a866e6000 ---p 00000000 00:00 0
7f7a866e6000-7f7a866f8000 rwxp 00000000 00:00 0
7f7a866f8000-7f7a866f9000 r-xp 0001f000 08:05 1576610
/lib/x86_64-linux-gnu/ld-2.13.so
7f7a866f9000-7f7a866fa000 rwxp 00020000 08:05 1576610
/lib/x86_64-linux-gnu/ld-2.13.so
7f7a866fa000-7f7a866fb000 rwxp 00000000 00:00 0
7fffed4c3000-7fffed4e4000 rwxp 00000000 00:00 0 [stack]
7fffed556000-7fffed557000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0
[vsyscall]
Aborted

On Tue, Mar 19, 2013 at 6:08 PM, Alex Nordlund deep.alexander@gmail.comwrote:

Right, the problem I'm seeing there is how to properly create the
spatialized prepared statement.
If I create the prepared statement like normal and run
db.spatialite(function(err) {
db.each(qry.run(53.36548645,-6.457246577), function(err, row) {
console.log(row); });
});
I get an error about X() not existing, if I try to wrap db.prepare in the
same way then it fails and my prepared statement is undefined.

On Tue, Mar 19, 2013 at 6:03 PM, Zac McCormick notifications@github.comwrote:

I think it should be possible. This library just returns you a handle
this https://github.com/developmentseed/node-sqlite3 library. So
anything in their docs you should be able to do (with spatialite functions
available).


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-15132314
.

@zhm
Copy link
Owner

zhm commented Mar 19, 2013

Whoa, what version of node are you using?

I was able to get it work with prepared statements using the following pattern:

var query = "SELECT X(Centroid(GeomFromText($point))) AS x;";

db.spatialite(function(err) {
  var stmt = db.prepare(query);
  stmt.all({ $point: 'POINT(27 -82)' }, function(err, row) {
    console.log(row);
  });
  stmt.finalize(function(err, row) {
    console.log('Done');
  });
});

@deepy
Copy link
Author

deepy commented Mar 20, 2013

I'm on v0.10.0, but it seems to me to be a SQLite/spatialite related.

The following database with the following code produces the crash:
http://x13.se/~deepy/new.db

var qry = 'SELECT name, ((X(Geometry)-X(loc))(X(Geometry)-X(loc))) +
((Y(Geometry)-Y(loc))
(Y(Geometry)-Y(loc))) as distance FROM test, (SELECT
MakePoint(%LAT%,%LONG%) as loc) ORDER BY distance LIMIT 1';
cords = "53.36548645 -6.457246577".split(' ');
newqry = qry.replace('%LAT%', cords[0]).replace('%LONG%',
cords[1]);
db.spatialite(function(err) {
db.each(newqry, function(err, row) {
console.log(row); });
});

On Tue, Mar 19, 2013 at 6:27 PM, Zac McCormick notifications@github.comwrote:

Whoa, what version of node are you using?

I was able to get it work with prepared statements using the following
pattern:

var query = "SELECT X(Centroid(GeomFromText($point))) AS x;";
db.spatialite(function(err) {
var stmt = db.prepare(query);
stmt.all({ $point: 'POINT(27 -82)' }, function(err, row) {
console.log(row);
});
stmt.finalize(function(err, row) {
console.log('Done');
});});


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-15133816
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants