This repository was archived by the owner on Jul 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspatialize-sqlite.sh
More file actions
executable file
·96 lines (85 loc) · 2.63 KB
/
spatialize-sqlite.sh
File metadata and controls
executable file
·96 lines (85 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
#
# Copyright © 2014–5 Brad Ackerman.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Parse command-line arguments.
set -- `getopt hd:m:e: "$@"`
if [ $# -lt 1 ]
then
# getopt failed
exit 66
fi
while [ $# -gt 0 ]
do
case "$1" in
-e) sqlite_exec="$2"; shift
;;
-d) dbfile="$2"; shift
;;
--) shift; break;;
-m) spatialite_module="$2"; shift;;
-*) echo >&2 \
"usage: $0 -d dbfile -e sqlite_executable -m spatialite_module"
exit 42;;
*) break;;
esac
shift
done
if [ -z "${dbfile}" ]
then
echo "missing parameter: -d dbfile.sqlite"
exit 2
fi
if [ -z "${sqlite_exec}" ]
then
echo "missing parameter: -e sqlite_executable"
exit 2
fi
if [ -z "${spatialite_module}" ]
then
echo "missing parameter: -m spatialite_module"
exit 2
fi
# Make the database spatial; generate the jumps data
${sqlite_exec} ${dbfile} <<EOF
SELECT load_extension('${spatialite_module}');
-- Initialize Spatialite triggers, views, and tables
SELECT InitSpatialMetaData();
-- Solar systems map
SELECT AddGeometryColumn('mapSolarSystems', 'the_geom', -1, 'POINT', 'XYZ');
UPDATE mapsolarsystems SET the_geom=MakePointZ(x,y,z, -1);
-- Jumps
CREATE TABLE jumps_data (
fromSystem integer NOT NULL,
toSystem integer NOT NULL,
cost integer NOT NULL DEFAULT 1,
PRIMARY KEY (fromSystem, toSystem)
);
-- Has to be 2D because spatialite_network doesn't like 3D.
-- Not that the geometry is actually being used here, mind.
SELECT AddGeometryColumn('jumps_data', 'the_geom', -1, 'LINESTRING', 'XY');
INSERT INTO jumps_data(fromSystem, toSystem, cost, the_geom)
SELECT fromSolarSystemID, toSolarSystemID, 1,
MakeLine(CastToXY(fss.the_geom), CastToXY(tss.the_geom))
FROM mapSolarSystemJumps j
JOIN mapSolarSystems fss ON j.fromSolarSystemID = fss.solarSystemID
JOIN mapSolarSystems tss ON j.toSolarSystemID = tss.solarSystemID;
EOF
spatialite_network -d ${dbfile} -T jumps_data -f fromSystem -t toSystem \
-c cost -g the_geom --unidirectional -o jumps_net
# Set up the routing output.
${sqlite_exec} ${dbfile} <<EOF
SELECT load_extension('${spatialite_module}');
CREATE VIRTUAL TABLE jump_route using virtualnetwork(jumps_net);
EOF