zhm / node-spatialite

Standalone, cross-platform SpatiaLite 4.0 binding for node.js with all features enabled
Other
67 stars 17 forks source link

InitSpatialMetaData() #6

Open diplonics opened 9 years ago

diplonics commented 9 years ago

Hi, While I'm not new to spatial data and using PostGIS etc. I am new to node and this package. I'm trying to run this query: var query = "SELECT AsGeoJSON(ST_Transform(GeomFromText('LINESTRING(" + lineString + ")',4326), 3857), 6, 3) AS tbbox;";

but the ST_Transform is failing with the message: { [Error: SQLITE_ERROR: no such table: spatial_refsys] errno: 1, code: 'SQLITE ERROR' }

How to I enable/create the spatial_ref_table, is there something I missed during the installation?

Thanks in advance.

zhm commented 9 years ago

Can you paste a complete code snippet that reproduces it? It might be related to the setup code....

diplonics commented 9 years ago

No probs, here's the code but don't think anything fancy is being done here.


var sqlite = require('spatialite'); var db = new sqlite.Database(':memory:'); var query = "SELECT AsGeoJSON(ST_Transform(GeomFromText('LINESTRING(" + lineString + ")',4326), 3857), 6, 3) AS tbbox;"; db.spatialite(function(error){ db.each(query, function(error, row){ if(error){ console.log(error); } console.log(util.inspect(row, false, null)); //Other logic code to happen here based on the SQL transform result }); }); db.close();


For your info and might help. Removing the ST_Transform method and all runs fine. The platform I'm developing on is Windows 7 so followed your VS build instructions. This code will be deployed on a linux server but I don't have access to this to test this issue yet.

Thanks again.