-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
publish an example for using geographical data
- Loading branch information
Showing
10 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
examples/make a geographic data application using sqlite extensions/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM debian:12-slim | ||
|
||
WORKDIR /var/www | ||
|
||
ADD https://github.com/lovasoa/SQLpage/releases/download/v0.7.2/sqlpage-linux.tgz . | ||
|
||
RUN apt-get update && \ | ||
apt-get -y install sqlite3 libsqlite3-mod-spatialite && \ | ||
tar xvzf sqlpage-linux.tgz && \ | ||
rm sqlpage-linux.tgz | ||
|
||
COPY . . | ||
|
||
CMD ["sqlite3"] |
22 changes: 22 additions & 0 deletions
22
examples/make a geographic data application using sqlite extensions/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Using spatialite to build a geographic data application | ||
|
||
## Introduction | ||
|
||
This is a small application that uses [spatialite](https://www.gaia-gis.it/fossil/libspatialite/index) | ||
to save data associated to greographic coordinates. | ||
|
||
### Installation | ||
|
||
You need to install the `spatialite` extension for SQLite. On Debian, or Ubuntu, you can do it with: | ||
|
||
```bash | ||
sudo apt install libsqlite3-mod-spatialite | ||
``` | ||
|
||
Then you can run this application normally with SQLPage. | ||
|
||
Notice the `sqlite_extensions` configuration parameter in [`sqlpage/sqlpage.json`](./sqlpage/sqlpage.json). | ||
|
||
## Screenshots | ||
|
||
![](./screenshots/code.png) |
10 changes: 10 additions & 0 deletions
10
examples/make a geographic data application using sqlite extensions/add_point.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
INSERT INTO spatial_data (label, geom) | ||
VALUES ( | ||
:Label, | ||
MakePoint( | ||
CAST(:Longitude AS REAL), | ||
CAST(:Latitude AS REAL | ||
), 4326) | ||
) RETURNING | ||
'redirect' AS component, | ||
'index.sql' AS link; |
15 changes: 15 additions & 0 deletions
15
examples/make a geographic data application using sqlite extensions/index.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
SELECT 'list' as component, | ||
'My points' as title; | ||
SELECT label as title, | ||
'point.sql?id=' || id as link, | ||
'red' as color, | ||
'world-pin' as icon | ||
FROM spatial_data; | ||
|
||
SELECT 'form' AS component, | ||
'Add a point' AS title, | ||
'add_point.sql' AS action; | ||
|
||
SELECT 'Label' AS name; | ||
SELECT 'Latitude' AS name, 'number' AS type, 0.00000001 AS step; | ||
SELECT 'Longitude' AS name, 'number' AS type, 0.00000001 AS step; |
43 changes: 43 additions & 0 deletions
43
examples/make a geographic data application using sqlite extensions/point.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
SELECT 'datagrid' as component, label as title FROM spatial_data WHERE id = $id; | ||
|
||
SELECT 'Latitude' as title, | ||
ST_Y(geom) as description, | ||
'purple' as color, | ||
'world-latitude' as icon | ||
FROM spatial_data WHERE id = $id; | ||
|
||
SELECT 'Longitude' as title, | ||
ST_X(geom) as description, | ||
'purple' as color, | ||
'world-longitude' as icon | ||
FROM spatial_data WHERE id = $id; | ||
|
||
SELECT 'Created at' as title, | ||
created_at as description, | ||
'calendar' as icon, | ||
'Date and time of creation' as footer | ||
FROM spatial_data WHERE id = $id; | ||
|
||
SELECT 'Label' as title, | ||
label as description, | ||
'geo:' || ST_Y(geom) || ',' || ST_X(geom) || '?z=16' AS link, | ||
'blue' as color, | ||
'world' as icon, | ||
'User-generated point name' as footer | ||
FROM spatial_data | ||
WHERE id = $id; | ||
|
||
SELECT 'list' as component, 'Closest points' as title; | ||
SELECT to_label as title, | ||
ROUND(CvtToKm(distance), 3) || ' km' as description, | ||
'point.sql?id=' || to_id as link, | ||
'red' as color, | ||
'world-pin' as icon | ||
FROM distances | ||
WHERE from_id = $id | ||
ORDER BY distance | ||
LIMIT 5; | ||
|
||
SELECT 'map' AS component, | ||
ST_Y(geom) AS latitude, ST_X(geom) AS longitude | ||
FROM spatial_data WHERE id = $id; |
Binary file added
BIN
+846 KB
...make a geographic data application using sqlite extensions/screenshots/code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
...geographic data application using sqlite extensions/sqlpage/migrations/0000_create_db.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- Create a spatialite-enabled database | ||
CREATE TABLE spatial_data ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
label TEXT NOT NULL, | ||
geom POINT, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
SELECT InitSpatialMetaData(); | ||
|
||
CREATE VIEW distances AS | ||
SELECT from_point.id AS from_id, | ||
from_point.label AS from_label, | ||
to_point.id AS to_id, | ||
to_point.label AS to_label, | ||
ST_Distance( | ||
from_point.geom, | ||
to_point.geom, | ||
TRUE | ||
) AS distance | ||
FROM spatial_data AS from_point, spatial_data AS to_point | ||
WHERE from_point.id != to_point.id; |
5 changes: 5 additions & 0 deletions
5
examples/make a geographic data application using sqlite extensions/sqlpage/sqlpage.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"sqlite_extensions": [ | ||
"mod_spatialite" | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
...ke a geographic data application using sqlite extensions/sqlpage/templates/map.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<iframe | ||
height="350" | ||
frameborder="0" | ||
scrolling="no" | ||
marginheight="0" | ||
marginwidth="0" | ||
src="https://www.openstreetmap.org/export/embed.html?bbox={{longitude}}%2C{{latitude}}" | ||
></iframe> |