-
Notifications
You must be signed in to change notification settings - Fork 0
/
geopackage.js
78 lines (70 loc) · 1.79 KB
/
geopackage.js
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
// geopackage.js
// Martin Pravda
/*jslint browser */
function geopackage(
db
) {
function get_feature_tables() {
return db.exec(
`
SELECT
c.table_name AS name,
g.geometry_type_name AS geom_type,
c.srs_id AS srs,
g.column_name as geom_column_name
FROM
gpkg_contents c
LEFT JOIN
gpkg_geometry_columns g
ON
c.table_name = g.table_name
WHERE
c.data_type = 'features';
`
);
}
function get_feature(table_name, column_names = []) {
let columns = (
column_names.length > 0
? column_names.join(", ")
: " * "
)
return db.exec(
`
SELECT
${columns}
FROM
${table_name};
`
);
}
function get_feature_as_geojson(
table_name,
geometry_columm,
column_names = []
) {
return db.exec(
`
SELECT
json_object(
'type', 'FeatureCollection',
'features', json_group_array(
json_object(
'type', 'Feature',
'geometry', json(
AsGeoJSON(${geometry_columm})
)
)
)
) AS geometry
FROM ${table_name};
`
);
}
return Object.freeze({
get_feature,
get_feature_as_geojson,
get_feature_tables
});
}
export default Object.freeze(geopackage);