Skip to content

Commit 96b2c47

Browse files
committed
Initial commit
0 parents  commit 96b2c47

File tree

5,392 files changed

+1688715
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,392 files changed

+1688715
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
deps/*/build
3+
node_modules

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/spatialite/deps/lwgeom"]
2+
path = src/spatialite/deps/lwgeom
3+
url = [email protected]:zhm/lwgeom.git

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- 0.8
4+
- 0.6
5+
- 0.9

LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2013, Zac McCormick <[email protected]>
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
* Redistributions of source code must retain the above copyright notice,
7+
this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright notice,
9+
this list of conditions and the following disclaimer in the documentation
10+
and/or other materials provided with the distribution.
11+
* Neither the name of "Development Seed" nor the names of its contributors
12+
may be used to endorse or promote products derived from this software
13+
without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL Konstantin Käfer BE LIABLE FOR ANY DIRECT,
19+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
REPORTER ?= spec
2+
TESTS ?= test/*.coffee
3+
4+
all: build
5+
6+
build:
7+
node-gyp build
8+
9+
clean:
10+
node-gyp clean
11+
12+
test:
13+
@PATH="./node_modules/.bin:${PATH}" && NODE_PATH="./lib:$(NODE_PATH)" \
14+
mocha \
15+
--reporter $(REPORTER) \
16+
--require should \
17+
--compilers coffee:coffee-script \
18+
$(TESTS)
19+
20+
.PHONY: build clean test

README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# node-spatialite
2+
3+
Standalone, cross-platform SpatiaLite 4.0 binding for node.js with all features enabled. The goal of this project is to have a completely standalone build of SpatiaLite that doesn't require any system dependencies (no need to `apt-get install ...` or install any system libraries other than the ones required to build native node.js modules. The result is a consistent build across platforms with a guarantee of functionality and the versions of the dependencies. There are number of ways to get SpatiaLite binaries on the various platforms, but none of them include all of the features in a consistent way. This project contains a complete gyp build system for SpatiaLite - so someone might find it useful for other things outside of nodejs also.
4+
5+
If you're familiar with SQL, this is a great way to get easy access to the power of GEOS, Proj4, and SQL without needing a full PostGIS server. A fair amount of work was put into getting [liblwgeom](https://www.gaia-gis.it/fossil/libspatialite/wiki?name=liblwgeom-4.0) support compiled across OS X, Linux, and Windows so you can use the geometry validation functions `ST_MakeValid`, `ST_IsValid`, `ST_Split`, and more.
6+
7+
# Usage
8+
This module simply exposes [node-sqlite3](https://github.com/developmentseed/node-sqlite3) with an additional method on the `Database` object to enable SpatiaLite. I opted to re-use this awesome library and dynamically load the extension so you can still use the `node-sqlite3` API without SpatiaLite if you like.
9+
10+
Here is a simple example that shows the usage of GEOS-enabled `Centroid` and LWGEOM-enabled `ST_MakeValid`.
11+
12+
```js
13+
sql = require('spatialite');
14+
db = new sql.Database(':memory:');
15+
db.spatialite(function() {
16+
db.each("SELECT AsGeoJSON(ST_MakeValid(Centroid(GeomFromText('POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))'))));", function(err, row) {
17+
console.log(row);
18+
});
19+
});
20+
```
21+
22+
# Tested on
23+
- OS X 64bit
24+
- Linux 64bit (Ubuntu)
25+
- Linux 32bit (Ubuntu)
26+
- Windows 64bit
27+
- Windows 32bit (pending some testing)
28+
29+
# Included in this build
30+
- SpatiaLite 4.0.0 [SQL Reference](http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.0.0.html)
31+
- GEOS-3.4.0-dev - Compiled with GEOS_TRUNK flag so all of the latest triangulation functions are available:
32+
- `DelaunayTriangulation`
33+
- `VoronojDiagram`
34+
- `ConcaveHull`
35+
- Proj 4.8.0
36+
- iconv 1.14
37+
- FreeXL 1.0.0e
38+
- liblwgeom 2.0.2 (from PostGIS 2.0.2) available functions:
39+
- `MakeValid`
40+
- `MakeValidDiscarded`
41+
- `Segmentize`
42+
- `Split`
43+
- `SplitLeft`
44+
- `SplitRight`
45+
- `Azimuth`
46+
- `SnapToGrid`
47+
- `GeoHash`
48+
- `AsX3D`
49+
- `MaxDistance`
50+
- `3DDistance`
51+
- `3DMaxDistance`
52+
53+
# Building
54+
55+
There's a lot of code in these dependencies and the build scripts are fairly complex. If it doesn't work, submit an issue!
56+
57+
To build the shared library, you will need to first install `node-gyp`.
58+
59+
$ npm install -g node-gyp
60+
61+
Build it:
62+
63+
$ node-gyp configure build
64+
65+
# Notes:
66+
67+
A lot of this was inspired by @TooTallNate's post on embedding dependencies in node modules.
68+
69+
http://n8.io/converting-a-c-library-to-gyp/
70+
71+
# License
72+
73+
This module is BSD licensed. The dependencies have their own licenses which are available in their directories.

Vagrantfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Vagrant::Config.run do |config|
2+
config.vm.define 'linux64' do |target|
3+
target.vm.box = 'precise'
4+
target.vm.customize ["modifyvm", :id, "--memory", 2048]
5+
target.vm.forward_port 22, 2222
6+
target.vm.network :hostonly, "22.22.22.22"
7+
end
8+
9+
config.vm.define 'linux32' do |target|
10+
target.vm.box = 'precise32'
11+
target.vm.customize ["modifyvm", :id, "--memory", 2048]
12+
target.vm.forward_port 22, 2222
13+
target.vm.network :hostonly, "22.22.22.22"
14+
end
15+
end

binding.gyp

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
'variables': { 'target_arch%': 'ia32' },
3+
4+
'target_defaults': {
5+
'default_configuration': 'Debug',
6+
'configurations': {
7+
'Debug': {
8+
'defines': [ 'DEBUG', '_DEBUG' ],
9+
'msvs_settings': {
10+
'VCCLCompilerTool': {
11+
'RuntimeLibrary': 1, # static debug
12+
},
13+
},
14+
},
15+
'Release': {
16+
'defines': [ 'NDEBUG' ],
17+
'msvs_settings': {
18+
'VCCLCompilerTool': {
19+
'RuntimeLibrary': 0, # static release
20+
},
21+
},
22+
}
23+
},
24+
'msvs_settings': {
25+
'VCCLCompilerTool': {
26+
},
27+
'VCLibrarianTool': {
28+
},
29+
'VCLinkerTool': {
30+
'GenerateDebugInformation': 'true',
31+
},
32+
},
33+
'defines': [
34+
],
35+
'include_dirs': [
36+
'src/config/<(OS)/<(target_arch)',
37+
'src/spatialite/src/headers',
38+
'src'
39+
],
40+
'conditions': [
41+
['OS == "win"', {
42+
'defines': [
43+
'WIN32'
44+
],
45+
}]
46+
],
47+
},
48+
49+
'targets': [
50+
{
51+
'target_name': 'spatialite',
52+
'type': 'shared_library',
53+
'direct_dependent_settings': {
54+
'include_dirs': [
55+
'src/config/<(OS)/<(target_arch)',
56+
'src/spatialite/src/headers'
57+
],
58+
'defines': [
59+
'ENABLE_LWGEOM'
60+
],
61+
},
62+
'dependencies': [
63+
'src/spatialite/deps/geos/binding.gyp:geos',
64+
'src/spatialite/deps/proj/binding.gyp:proj',
65+
'src/spatialite/deps/iconv/binding.gyp:iconv',
66+
'src/spatialite/deps/lwgeom/binding.gyp:lwgeom',
67+
'src/spatialite/deps/freexl/binding.gyp:freexl'
68+
],
69+
'sources': [
70+
'src/spatialite/src/gaiaaux/gg_sqlaux.c',
71+
'src/spatialite/src/gaiaaux/gg_utf8.c',
72+
'src/spatialite/src/gaiaexif/gaia_exif.c',
73+
'src/spatialite/src/gaiageo/gg_advanced.c',
74+
'src/spatialite/src/gaiageo/gg_endian.c',
75+
'src/spatialite/src/gaiageo/gg_ewkt.c',
76+
'src/spatialite/src/gaiageo/gg_extras.c',
77+
'src/spatialite/src/gaiageo/gg_geodesic.c',
78+
'src/spatialite/src/gaiageo/gg_geoJSON.c',
79+
'src/spatialite/src/gaiageo/gg_geometries.c',
80+
'src/spatialite/src/gaiageo/gg_geoscvt.c',
81+
'src/spatialite/src/gaiageo/gg_gml.c',
82+
'src/spatialite/src/gaiageo/gg_kml.c',
83+
'src/spatialite/src/gaiageo/gg_lwgeom.c',
84+
'src/spatialite/src/gaiageo/gg_relations.c',
85+
'src/spatialite/src/gaiageo/gg_shape.c',
86+
'src/spatialite/src/gaiageo/gg_transform.c',
87+
'src/spatialite/src/gaiageo/gg_vanuatu.c',
88+
'src/spatialite/src/gaiageo/gg_voronoj.c',
89+
'src/spatialite/src/gaiageo/gg_wkb.c',
90+
'src/spatialite/src/gaiageo/gg_wkt.c',
91+
'src/spatialite/src/shapefiles/shapefiles.c',
92+
'src/spatialite/src/spatialite/mbrcache.c',
93+
'src/spatialite/src/spatialite/metatables.c',
94+
'src/spatialite/src/spatialite/spatialite.c',
95+
'src/spatialite/src/spatialite/statistics.c',
96+
'src/spatialite/src/spatialite/virtualdbf.c',
97+
'src/spatialite/src/spatialite/virtualfdo.c',
98+
'src/spatialite/src/spatialite/virtualnetwork.c',
99+
'src/spatialite/src/spatialite/virtualshape.c',
100+
'src/spatialite/src/spatialite/virtualspatialindex.c',
101+
'src/spatialite/src/spatialite/virtualXL.c',
102+
'src/spatialite/src/srsinit/epsg_inlined_00.c',
103+
'src/spatialite/src/srsinit/epsg_inlined_01.c',
104+
'src/spatialite/src/srsinit/epsg_inlined_02.c',
105+
'src/spatialite/src/srsinit/epsg_inlined_03.c',
106+
'src/spatialite/src/srsinit/epsg_inlined_04.c',
107+
'src/spatialite/src/srsinit/epsg_inlined_05.c',
108+
'src/spatialite/src/srsinit/epsg_inlined_06.c',
109+
'src/spatialite/src/srsinit/epsg_inlined_07.c',
110+
'src/spatialite/src/srsinit/epsg_inlined_08.c',
111+
'src/spatialite/src/srsinit/epsg_inlined_09.c',
112+
'src/spatialite/src/srsinit/epsg_inlined_10.c',
113+
'src/spatialite/src/srsinit/epsg_inlined_11.c',
114+
'src/spatialite/src/srsinit/epsg_inlined_12.c',
115+
'src/spatialite/src/srsinit/epsg_inlined_13.c',
116+
'src/spatialite/src/srsinit/epsg_inlined_14.c',
117+
'src/spatialite/src/srsinit/epsg_inlined_15.c',
118+
'src/spatialite/src/srsinit/epsg_inlined_16.c',
119+
'src/spatialite/src/srsinit/epsg_inlined_17.c',
120+
'src/spatialite/src/srsinit/epsg_inlined_18.c',
121+
'src/spatialite/src/srsinit/epsg_inlined_19.c',
122+
'src/spatialite/src/srsinit/epsg_inlined_20.c',
123+
'src/spatialite/src/srsinit/epsg_inlined_21.c',
124+
'src/spatialite/src/srsinit/epsg_inlined_22.c',
125+
'src/spatialite/src/srsinit/epsg_inlined_23.c',
126+
'src/spatialite/src/srsinit/epsg_inlined_24.c',
127+
'src/spatialite/src/srsinit/epsg_inlined_25.c',
128+
'src/spatialite/src/srsinit/epsg_inlined_26.c',
129+
'src/spatialite/src/srsinit/epsg_inlined_27.c',
130+
'src/spatialite/src/srsinit/epsg_inlined_28.c',
131+
'src/spatialite/src/srsinit/epsg_inlined_29.c',
132+
'src/spatialite/src/srsinit/epsg_inlined_30.c',
133+
'src/spatialite/src/srsinit/epsg_inlined_31.c',
134+
'src/spatialite/src/srsinit/epsg_inlined_32.c',
135+
'src/spatialite/src/srsinit/epsg_inlined_33.c',
136+
'src/spatialite/src/srsinit/epsg_inlined_34.c',
137+
'src/spatialite/src/srsinit/epsg_inlined_35.c',
138+
'src/spatialite/src/srsinit/epsg_inlined_36.c',
139+
'src/spatialite/src/srsinit/epsg_inlined_37.c',
140+
'src/spatialite/src/srsinit/epsg_inlined_38.c',
141+
'src/spatialite/src/srsinit/epsg_inlined_39.c',
142+
'src/spatialite/src/srsinit/epsg_inlined_40.c',
143+
'src/spatialite/src/srsinit/epsg_inlined_extra.c',
144+
'src/spatialite/src/srsinit/epsg_inlined_prussian.c',
145+
'src/spatialite/src/srsinit/epsg_inlined_wgs84_00.c',
146+
'src/spatialite/src/srsinit/epsg_inlined_wgs84_01.c',
147+
'src/spatialite/src/srsinit/srs_init.c',
148+
'src/spatialite/src/versioninfo/version.c',
149+
'src/spatialite/src/virtualtext/virtualtext.c'
150+
]
151+
},
152+
]
153+
}

configure

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node-gyp configure

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/spatialite');

install_deps.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This script is for installing dependencies in Linux for testing
2+
3+
sudo apt-get update &&
4+
sudo apt-get install -y python-software-properties python g++ make clang build-essential &&
5+
# sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable -y &&
6+
# sudo apt-get update &&
7+
# sudo apt-get install -y postgresql-9.1 postgresql-server-dev-9.1 postgresql-plpython-9.1 postgresql-contrib &&
8+
# sudo apt-get install -y libxml2-dev libgeos-dev libproj-dev libgdal-dev libfreexl-dev sqlite3 postgis &&
9+
sudo add-apt-repository -y ppa:chris-lea/node.js &&
10+
sudo apt-get install -y nodejs npm &&
11+
sudo npm install -g node-gyp
12+
13+
# cd ~
14+
15+
# wget http://www.gaia-gis.it/gaia-sins/freexl-1.0.0e.tar.gz && tar -xvf freexl-1.0.0e.tar.gz
16+
# wget http://download.osgeo.org/geos/geos-3.3.7.tar.bz2 && tar -xvf geos-3.3.7.tar.bz2
17+
# wget http://download.osgeo.org/postgis/source/postgis-2.0.2.tar.gz && tar -xvf postgis-2.0.2.tar.gz
18+
# wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz && tar -xvf proj-4.8.0.tar.gz
19+
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz && tar -xvf libiconv-1.14.tar.gz
20+
# wget http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.0.0.tar.gz && tar -xvf libspatialite-4.0.0.tar.gz

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./spatialite');

lib/spatialite.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var sqlite3 = module.exports = exports = require('sqlite3');
2+
var fs = require('fs');
3+
4+
sqlite3.Database.prototype.spatialite = function(callback) {
5+
var base_path = './build/Release/spatialite';
6+
var linux_path = base_path + '.so';
7+
var osx_path = base_path + '.dylib';
8+
var windows_path = base_path + '.dll';
9+
10+
var extension_path = null;
11+
12+
if (fs.existsSync(linux_path)) {
13+
extension_path = linux_path;
14+
} else if (fs.existsSync(osx_path)) {
15+
extension_path = osx_path;
16+
} else if (fs.existsSync(windows_path)) {
17+
extension_path = windows_path;
18+
} else {
19+
throw new Error("Unable to find spatialite extension.");
20+
}
21+
22+
this.loadExtension(extension_path, callback);
23+
};

package.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "spatialite",
3+
"description": "SpatiaLite for node",
4+
"version": "0.0.1",
5+
"homepage": "http://github.com/zhm/node-spatialite",
6+
"author": {
7+
"name": "Zac McCormick",
8+
"url": "http://github.com/zhm",
9+
"email": "[email protected]"
10+
},
11+
"contributors": [
12+
"Zac McCormick <[email protected]>"
13+
],
14+
"repository": {
15+
"type": "git",
16+
"url": "git://github.com/zhm/node-spatialite.git"
17+
},
18+
"dependencies": {
19+
"sqlite3": "*"
20+
},
21+
"devDependencies": {
22+
"coffee-script": "*",
23+
"underscore": "*",
24+
"mocha": "*",
25+
"should": "*",
26+
"step": "0.0.4",
27+
"expresso": "*"
28+
},
29+
"engines": {
30+
"node": ">= 0.6.13"
31+
},
32+
"scripts": {
33+
"pretest": "npm install --dev",
34+
"test": "make test"
35+
},
36+
"licenses": [{ "type": "BSD" }],
37+
"main": "./lib/spatialite"
38+
}

0 commit comments

Comments
 (0)