@opengis/gis 0.2.174 → 0.2.176
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -181
- package/dist/{CardIcon-Cg8bUM4G.js → CardIcon-c1Q2M3wQ.js} +1 -1
- package/dist/{EntityTablePage-DHQGlLRk.js → EntityTablePage-B5gpkH4S.js} +2 -2
- package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BIL1ocLY.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-DnGSvmMU.js} +1 -1
- package/dist/{HeaderActions.vue_vue_type_script_setup_true_lang-Buff9gTO.js → HeaderActions.vue_vue_type_script_setup_true_lang-C2B61JP6.js} +1 -1
- package/dist/{MapSettings-De-z7r5t.js → MapSettings-6-Xru5Q8.js} +2 -2
- package/dist/{RastersTablePage-Cdgkri9K.js → RastersTablePage-CXNOcTy-.js} +2 -2
- package/dist/{cartocss-BT50SVhy.js → cartocss-BFVqWvfP.js} +6 -6
- package/dist/{import-utils-CMWiuRPp.js → import-utils-uxk4LdUJ.js} +1 -1
- package/dist/{index-CHFLgCGW.js → index-CahlV-Xs.js} +39 -39
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +19 -19
- package/dist/{raster-dSEb1SIG.js → raster-CEi56f0P.js} +3 -3
- package/dist/{register-D7Puupgo.js → register-NFAGBNa3.js} +3 -3
- package/dist/{service-Cz6T0O3Z.js → service-BYspag8U.js} +829 -832
- package/dist/{vs-datatable-DqVncrSg.js → vs-datatable-CHcBr6zy.js} +2 -2
- package/module/gis/cls/service_type.json +42 -42
- package/module/gis/form/gis.registers.form.json +4 -1
- package/module/test/map/addr.json +302 -302
- package/module/test/map/addr1.yml +23 -23
- package/module/test/select/address.str_id.sql +3 -3
- package/package.json +77 -77
- package/plugin.js +64 -64
- package/server/migrations/array_intersect.sql +13 -13
- package/server/migrations/cartocss.sql +27 -27
- package/server/migrations/group_list.sql +74 -74
- package/server/migrations/maps.sql +30 -30
- package/server/migrations/metadata.sql +415 -415
- package/server/migrations/ogc.sql +106 -106
- package/server/migrations/rasters.sql +265 -265
- package/server/migrations/services.sql +247 -247
- package/server/migrations/services_users_rel.sql +22 -22
- package/server/migrations/widgets.sql +20 -20
- package/server/plugins/crons.js +21 -21
- package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
- package/server/plugins/mapnik/funcs/mapnik.js +151 -151
- package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
- package/server/plugins/mapnik/map.proto +437 -437
- package/server/plugins/vite.js +74 -74
- package/server/routes/cartocss/cartocss.route.js +31 -31
- package/server/routes/cartocss/cartocss.route.test.js +78 -78
- package/server/routes/cartocss/cartocss.schema.js +73 -73
- package/server/routes/cartocss/functions/add.cartocss.js +39 -39
- package/server/routes/cartocss/functions/get.cartocss.js +57 -57
- package/server/routes/gis/functions/checkXML.js +107 -107
- package/server/routes/gis/functions/dashboard.js +24 -24
- package/server/routes/gis/gis.route.js +26 -26
- package/server/routes/gis/gis.route.test.js +33 -33
- package/server/routes/map/functions/clearTiles.js +35 -35
- package/server/routes/map/functions/geojson.js +187 -187
- package/server/routes/map/functions/gis.convert.js +65 -65
- package/server/routes/map/functions/gis.icon.js +220 -220
- package/server/routes/map/functions/jsonData.js +206 -206
- package/server/routes/map/functions/layerList.js +102 -102
- package/server/routes/map/functions/map.js +122 -122
- package/server/routes/map/functions/mapCatalog.js +72 -72
- package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
- package/server/routes/map/functions/mapFeatures.js +133 -133
- package/server/routes/map/functions/mapFormat.js +232 -231
- package/server/routes/map/functions/mapTiles.js +162 -162
- package/server/routes/map/functions/maps.js +15 -15
- package/server/routes/map/functions/marker_icon.js +43 -43
- package/server/routes/map/functions/parseGeoFile.js +85 -85
- package/server/routes/map/functions/pointHeight.js +51 -51
- package/server/routes/map/functions/vtile.js +174 -174
- package/server/routes/map/functions/vtile1.js +185 -185
- package/server/routes/map/map.route.js +280 -280
- package/server/routes/map/map.route.test.js +503 -503
- package/server/routes/map/map.schema.js +356 -356
- package/server/routes/map/pin/circle1.svg +76 -76
- package/server/routes/map/pin/circle2.svg +18 -18
- package/server/routes/map/pin/none.svg +12 -12
- package/server/routes/map/pin/pin.svg +14 -14
- package/server/routes/map/pin/pin1.svg +16 -16
- package/server/routes/map/pin/pin2.svg +7 -7
- package/server/routes/map/pin/pin3.svg +34 -34
- package/server/routes/map/pin/pin4.svg +14 -14
- package/server/routes/map/pin/pin5.svg +7 -7
- package/server/routes/map/pin/pin6.svg +12 -12
- package/server/routes/map/pin/pin7.svg +12 -12
- package/server/routes/mapnik/functions/cartoBounds.js +32 -32
- package/server/routes/mapnik/functions/clearTiles.js +103 -103
- package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
- package/server/routes/mapnik/functions/createXml.js +76 -76
- package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
- package/server/routes/mapnik/functions/fileSearch.js +35 -35
- package/server/routes/mapnik/functions/fileStat.js +28 -28
- package/server/routes/mapnik/functions/pretile.js +138 -138
- package/server/routes/mapnik/functions/rasterInfo.js +66 -66
- package/server/routes/mapnik/functions/readDir.js +22 -22
- package/server/routes/mapnik/functions/rtile.js +164 -164
- package/server/routes/mapnik/functions/uploadRaster.js +152 -152
- package/server/routes/mapnik/functions/uploadXML.js +140 -140
- package/server/routes/mapnik/mapnik.route.js +102 -102
- package/server/routes/mapnik/mapnik.route.test.js +370 -370
- package/server/routes/mapnik/mapnik.schema.mjs +195 -195
- package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
- package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
- package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
- package/server/routes/maps/functions/add.map.js +42 -42
- package/server/routes/maps/functions/del.map.js +17 -17
- package/server/routes/maps/functions/get.map.js +119 -119
- package/server/routes/maps/maps.route.js +58 -58
- package/server/routes/maps/maps.route.test.js +231 -231
- package/server/routes/maps/maps.schema.js +9 -9
- package/server/routes/metadata/functions/editMetadata.js +35 -35
- package/server/routes/metadata/functions/metadataXML.js +19 -19
- package/server/routes/metadata/metadata.route.js +26 -26
- package/server/routes/metadata/metadata.route.test.js +46 -46
- package/server/routes/metadata/metadata.schema.js +53 -53
- package/server/routes/ogc/functions/map.info.point.js +117 -117
- package/server/routes/ogc/ogc.route.js +21 -21
- package/server/routes/ogc/ogc.route.test.js +53 -53
- package/server/routes/ogc/ogc.schema.js +16 -16
- package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
- package/server/routes/permissions/functions/catalog.permissions.js +12 -12
- package/server/routes/permissions/functions/get.permissions.js +59 -59
- package/server/routes/permissions/functions/gis.catalog.js +80 -80
- package/server/routes/permissions/permissions.route.js +35 -35
- package/server/routes/permissions/permissions.route.test.js +35 -35
- package/server/routes/permissions/permissions.schema.js +43 -43
- package/server/routes/registers/functions/add.registry.js +37 -37
- package/server/routes/registers/functions/classifiers.js +100 -100
- package/server/routes/registers/functions/columns.js +3 -3
- package/server/routes/registers/functions/content.type.js +9 -9
- package/server/routes/registers/functions/del.registry.js +14 -14
- package/server/routes/registers/functions/get.info.js +93 -93
- package/server/routes/registers/functions/gis.export.js +159 -159
- package/server/routes/registers/functions/gis.registry.js +71 -71
- package/server/routes/registers/functions/gis.registry.list.js +61 -61
- package/server/routes/registers/functions/handleRegistryRequest.js +147 -147
- package/server/routes/registers/functions/map.registry.js +87 -87
- package/server/routes/registers/registers.route.js +80 -80
- package/server/routes/registers/registers.route.test.js +144 -144
- package/server/routes/registers/registers.schema.js +246 -246
- package/server/routes/root.mjs +3 -3
- package/server/routes/services/functions/add.service.js +62 -62
- package/server/routes/services/functions/create.route.js +93 -93
- package/server/routes/services/functions/del.service.js +12 -12
- package/server/routes/services/functions/get.layer.geom.js +27 -27
- package/server/routes/services/functions/get.service.users.js +76 -76
- package/server/routes/services/functions/get.services.col.js +34 -34
- package/server/routes/services/functions/get.services.js +89 -89
- package/server/routes/services/functions/legend.auto.js +77 -77
- package/server/routes/services/services.route.js +76 -76
- package/server/routes/services/services.route.test.js +167 -167
- package/server/routes/services/services.schema.js +278 -278
- package/server/routes/widgets/functions/add.widget.js +38 -38
- package/server/routes/widgets/functions/del.widget.js +17 -17
- package/server/routes/widgets/functions/get.widget.js +41 -41
- package/server/routes/widgets/widgets.route.js +61 -61
- package/server/routes/widgets/widgets.route.test.js +144 -144
- package/server/routes/widgets/widgets.schema.js +24 -24
- package/server/shared/listFiles.js +15 -0
- package/utils.js +13 -13
|
@@ -1,159 +1,159 @@
|
|
|
1
|
-
import { createReadStream } from 'node:fs';
|
|
2
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
grpc, config, getMeta, getFolder, jsonToCsv,
|
|
7
|
-
pgClients,
|
|
8
|
-
} from '@opengis/fastify-table/utils.js';
|
|
9
|
-
|
|
10
|
-
import { BadRequestError, NotImplementedError } from '@opengis/fastify-table/errors.js';
|
|
11
|
-
|
|
12
|
-
import getInfo from './get.info.js';
|
|
13
|
-
import ContentType from './content.type.js';
|
|
14
|
-
|
|
15
|
-
const { jsonToXls, geojsonToShp } = grpc();
|
|
16
|
-
const rootDir = getFolder(config, 'local');
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Експорт даних реєстру
|
|
20
|
-
* @param {Object} query - Об'єкт запиту з форматом.
|
|
21
|
-
* @param {Object} params - Об'єкт параметрів з slug та type.
|
|
22
|
-
* @param {Function} reply
|
|
23
|
-
* @returns {boolean} File
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
export default async function gisExport({ slug, type, format }, pg = pgClients.client) {
|
|
27
|
-
if (!['csv', 'xlsx', 'shp', 'geojson'].includes(format)) {
|
|
28
|
-
throw BadRequestError('invalid params: format. Allowed: csv, xlsx, shp, geojson');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!slug) {
|
|
32
|
-
throw BadRequestError('not enough params: slug');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!type) {
|
|
36
|
-
throw BadRequestError('not enough params: type');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let registerInfo;
|
|
40
|
-
let serviceInfo;
|
|
41
|
-
|
|
42
|
-
if (type === 'register') {
|
|
43
|
-
registerInfo = await pg.query(
|
|
44
|
-
`SELECT table_name, columns, query
|
|
45
|
-
FROM gis.registers
|
|
46
|
-
WHERE $1 in (register_key,register_id)`,
|
|
47
|
-
[slug],
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
if (type === 'service') {
|
|
51
|
-
serviceInfo = await pg.query(
|
|
52
|
-
`SELECT source_path as table_name, attributes as columns, query
|
|
53
|
-
FROM gis.services
|
|
54
|
-
WHERE $1 in (service_key,service_id)`,
|
|
55
|
-
[slug],
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
const finalInfo = registerInfo?.rows[0] || serviceInfo?.rows[0];
|
|
59
|
-
|
|
60
|
-
const exportable = finalInfo?.columns?.filter(c => c.is_export);
|
|
61
|
-
const colmodel = (exportable || []).map(col => ({
|
|
62
|
-
name: col.name,
|
|
63
|
-
title: col.ua || col.name,
|
|
64
|
-
}));
|
|
65
|
-
const {
|
|
66
|
-
rows, table, srid, sqlList,
|
|
67
|
-
} = await getInfo({ finalInfo, format });
|
|
68
|
-
let filePath = ['csv', 'geojson', 'xlsx'].includes(format) ? path.join(rootDir, `/files/tmp/export_${table}_${Date.now()}.${format}`) : path.join(rootDir, `/files/tmp/export_${table}_${Date.now()}.zip`);
|
|
69
|
-
const ext = path.extname(filePath);
|
|
70
|
-
const filePathJSON = ['csv', 'geojson', 'shp'].includes(format) ? filePath.replace(ext, '.json') : filePath;
|
|
71
|
-
const exportedZipPaths = [];
|
|
72
|
-
|
|
73
|
-
const meta = await getMeta({ pg, table });
|
|
74
|
-
if ((format === 'geojson' || format === 'shp') && !meta?.geom) {
|
|
75
|
-
throw BadRequestError('Ця таблиця не містить полів геометрії. Виберіть тип, який не потребує геометрії для вивантаження');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (format === 'xlsx') {
|
|
79
|
-
if (!jsonToXls) {
|
|
80
|
-
throw NotImplementedError('Сервіс конвертації jsonToXls тимчасово недоступний. Спробуйте експортувати дані у іншому форматі...');
|
|
81
|
-
}
|
|
82
|
-
const { result } = await jsonToXls({
|
|
83
|
-
json: JSON.stringify(rows),
|
|
84
|
-
colmodel: JSON.stringify(colmodel),
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
await mkdir(path.dirname(filePath), { recursive: true });
|
|
88
|
-
await writeFile(filePath, result, 'base64');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (format === 'csv') {
|
|
92
|
-
await mkdir(path.dirname(filePathJSON), { recursive: true });
|
|
93
|
-
await writeFile(filePathJSON, JSON.stringify(rows));
|
|
94
|
-
|
|
95
|
-
await jsonToCsv({
|
|
96
|
-
filePath: filePathJSON, colmodel, columnList: colmodel.map(c => c.name),
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (['shp', 'geojson'].includes(format)) {
|
|
101
|
-
if (format === 'geojson') {
|
|
102
|
-
const geojson = {
|
|
103
|
-
type: 'FeatureCollection',
|
|
104
|
-
features: rows.map((row) => ({
|
|
105
|
-
type: 'Feature',
|
|
106
|
-
geometry: row.geom,
|
|
107
|
-
properties: Object.fromEntries(Object.entries(row).filter(([key]) => key !== 'geom')),
|
|
108
|
-
})),
|
|
109
|
-
};
|
|
110
|
-
filePath = filePathJSON.replace('.json', '.geojson');
|
|
111
|
-
await mkdir(path.dirname(filePath), { recursive: true });
|
|
112
|
-
await writeFile(filePath, JSON.stringify(geojson));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (format === 'shp') {
|
|
116
|
-
const proj = `EPSG:${srid || 4326}`;
|
|
117
|
-
for (const { type, query } of sqlList) {
|
|
118
|
-
const { rows } = await pg.query(query);
|
|
119
|
-
if (!rows.length) continue;
|
|
120
|
-
|
|
121
|
-
const geojson = {
|
|
122
|
-
type: 'FeatureCollection',
|
|
123
|
-
features: rows.map(row => ({
|
|
124
|
-
type: 'Feature',
|
|
125
|
-
geometry: row.geom,
|
|
126
|
-
properties: Object.fromEntries(Object.entries(row).filter(([k]) => k !== 'geom')),
|
|
127
|
-
})),
|
|
128
|
-
};
|
|
129
|
-
const geomShort = type.toLowerCase().replace('st_', '');
|
|
130
|
-
const typedPath = filePath.replace('.zip', `_${geomShort}.zip`);
|
|
131
|
-
|
|
132
|
-
const filePathTyped = filePath.replace('.zip', `_${type.toLowerCase().replace('st_', '')}.zip`);
|
|
133
|
-
const { result: shpZipBuffer } = await geojsonToShp({
|
|
134
|
-
geojson: JSON.stringify(geojson),
|
|
135
|
-
proj,
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
await mkdir(path.dirname(filePathTyped), { recursive: true });
|
|
139
|
-
await writeFile(filePathTyped, Buffer.from(shpZipBuffer, 'base64'));
|
|
140
|
-
|
|
141
|
-
exportedZipPaths.push(typedPath);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
let exportFilePath = filePath;
|
|
147
|
-
|
|
148
|
-
if (format === 'shp' && exportedZipPaths?.length > 0) {
|
|
149
|
-
exportFilePath = exportedZipPaths[0];
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const headers = {
|
|
153
|
-
'Content-Disposition': `attachment; filename=${encodeURIComponent(path.basename(exportFilePath))}`,
|
|
154
|
-
'Content-Type': ContentType[format]
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const fileStream = createReadStream(exportFilePath);
|
|
158
|
-
return { headers, data: fileStream };
|
|
159
|
-
}
|
|
1
|
+
import { createReadStream } from 'node:fs';
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
grpc, config, getMeta, getFolder, jsonToCsv,
|
|
7
|
+
pgClients,
|
|
8
|
+
} from '@opengis/fastify-table/utils.js';
|
|
9
|
+
|
|
10
|
+
import { BadRequestError, NotImplementedError } from '@opengis/fastify-table/errors.js';
|
|
11
|
+
|
|
12
|
+
import getInfo from './get.info.js';
|
|
13
|
+
import ContentType from './content.type.js';
|
|
14
|
+
|
|
15
|
+
const { jsonToXls, geojsonToShp } = grpc();
|
|
16
|
+
const rootDir = getFolder(config, 'local');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Експорт даних реєстру
|
|
20
|
+
* @param {Object} query - Об'єкт запиту з форматом.
|
|
21
|
+
* @param {Object} params - Об'єкт параметрів з slug та type.
|
|
22
|
+
* @param {Function} reply
|
|
23
|
+
* @returns {boolean} File
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export default async function gisExport({ slug, type, format }, pg = pgClients.client) {
|
|
27
|
+
if (!['csv', 'xlsx', 'shp', 'geojson'].includes(format)) {
|
|
28
|
+
throw BadRequestError('invalid params: format. Allowed: csv, xlsx, shp, geojson');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!slug) {
|
|
32
|
+
throw BadRequestError('not enough params: slug');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!type) {
|
|
36
|
+
throw BadRequestError('not enough params: type');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let registerInfo;
|
|
40
|
+
let serviceInfo;
|
|
41
|
+
|
|
42
|
+
if (type === 'register') {
|
|
43
|
+
registerInfo = await pg.query(
|
|
44
|
+
`SELECT table_name, columns, query
|
|
45
|
+
FROM gis.registers
|
|
46
|
+
WHERE $1 in (register_key,register_id)`,
|
|
47
|
+
[slug],
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (type === 'service') {
|
|
51
|
+
serviceInfo = await pg.query(
|
|
52
|
+
`SELECT source_path as table_name, attributes as columns, query
|
|
53
|
+
FROM gis.services
|
|
54
|
+
WHERE $1 in (service_key,service_id)`,
|
|
55
|
+
[slug],
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const finalInfo = registerInfo?.rows[0] || serviceInfo?.rows[0];
|
|
59
|
+
|
|
60
|
+
const exportable = finalInfo?.columns?.filter(c => c.is_export);
|
|
61
|
+
const colmodel = (exportable || []).map(col => ({
|
|
62
|
+
name: col.name,
|
|
63
|
+
title: col.ua || col.name,
|
|
64
|
+
}));
|
|
65
|
+
const {
|
|
66
|
+
rows, table, srid, sqlList,
|
|
67
|
+
} = await getInfo({ finalInfo, format });
|
|
68
|
+
let filePath = ['csv', 'geojson', 'xlsx'].includes(format) ? path.join(rootDir, `/files/tmp/export_${table}_${Date.now()}.${format}`) : path.join(rootDir, `/files/tmp/export_${table}_${Date.now()}.zip`);
|
|
69
|
+
const ext = path.extname(filePath);
|
|
70
|
+
const filePathJSON = ['csv', 'geojson', 'shp'].includes(format) ? filePath.replace(ext, '.json') : filePath;
|
|
71
|
+
const exportedZipPaths = [];
|
|
72
|
+
|
|
73
|
+
const meta = await getMeta({ pg, table });
|
|
74
|
+
if ((format === 'geojson' || format === 'shp') && !meta?.geom) {
|
|
75
|
+
throw BadRequestError('Ця таблиця не містить полів геометрії. Виберіть тип, який не потребує геометрії для вивантаження');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (format === 'xlsx') {
|
|
79
|
+
if (!jsonToXls) {
|
|
80
|
+
throw NotImplementedError('Сервіс конвертації jsonToXls тимчасово недоступний. Спробуйте експортувати дані у іншому форматі...');
|
|
81
|
+
}
|
|
82
|
+
const { result } = await jsonToXls({
|
|
83
|
+
json: JSON.stringify(rows),
|
|
84
|
+
colmodel: JSON.stringify(colmodel),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
88
|
+
await writeFile(filePath, result, 'base64');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (format === 'csv') {
|
|
92
|
+
await mkdir(path.dirname(filePathJSON), { recursive: true });
|
|
93
|
+
await writeFile(filePathJSON, JSON.stringify(rows));
|
|
94
|
+
|
|
95
|
+
await jsonToCsv({
|
|
96
|
+
filePath: filePathJSON, colmodel, columnList: colmodel.map(c => c.name),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (['shp', 'geojson'].includes(format)) {
|
|
101
|
+
if (format === 'geojson') {
|
|
102
|
+
const geojson = {
|
|
103
|
+
type: 'FeatureCollection',
|
|
104
|
+
features: rows.map((row) => ({
|
|
105
|
+
type: 'Feature',
|
|
106
|
+
geometry: row.geom,
|
|
107
|
+
properties: Object.fromEntries(Object.entries(row).filter(([key]) => key !== 'geom')),
|
|
108
|
+
})),
|
|
109
|
+
};
|
|
110
|
+
filePath = filePathJSON.replace('.json', '.geojson');
|
|
111
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
112
|
+
await writeFile(filePath, JSON.stringify(geojson));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (format === 'shp') {
|
|
116
|
+
const proj = `EPSG:${srid || 4326}`;
|
|
117
|
+
for (const { type, query } of sqlList) {
|
|
118
|
+
const { rows } = await pg.query(query);
|
|
119
|
+
if (!rows.length) continue;
|
|
120
|
+
|
|
121
|
+
const geojson = {
|
|
122
|
+
type: 'FeatureCollection',
|
|
123
|
+
features: rows.map(row => ({
|
|
124
|
+
type: 'Feature',
|
|
125
|
+
geometry: row.geom,
|
|
126
|
+
properties: Object.fromEntries(Object.entries(row).filter(([k]) => k !== 'geom')),
|
|
127
|
+
})),
|
|
128
|
+
};
|
|
129
|
+
const geomShort = type.toLowerCase().replace('st_', '');
|
|
130
|
+
const typedPath = filePath.replace('.zip', `_${geomShort}.zip`);
|
|
131
|
+
|
|
132
|
+
const filePathTyped = filePath.replace('.zip', `_${type.toLowerCase().replace('st_', '')}.zip`);
|
|
133
|
+
const { result: shpZipBuffer } = await geojsonToShp({
|
|
134
|
+
geojson: JSON.stringify(geojson),
|
|
135
|
+
proj,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
await mkdir(path.dirname(filePathTyped), { recursive: true });
|
|
139
|
+
await writeFile(filePathTyped, Buffer.from(shpZipBuffer, 'base64'));
|
|
140
|
+
|
|
141
|
+
exportedZipPaths.push(typedPath);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let exportFilePath = filePath;
|
|
147
|
+
|
|
148
|
+
if (format === 'shp' && exportedZipPaths?.length > 0) {
|
|
149
|
+
exportFilePath = exportedZipPaths[0];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const headers = {
|
|
153
|
+
'Content-Disposition': `attachment; filename=${encodeURIComponent(path.basename(exportFilePath))}`,
|
|
154
|
+
'Content-Type': ContentType[format]
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const fileStream = createReadStream(exportFilePath);
|
|
158
|
+
return { headers, data: fileStream };
|
|
159
|
+
}
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { pgClients, getTemplate } from "@opengis/fastify-table/utils.js";
|
|
2
|
-
import { BadRequestError, ConflictError, NotFoundError } from "@opengis/fastify-table/errors.js";
|
|
3
|
-
|
|
4
|
-
import { handleRegistryRequest } from './handleRegistryRequest.js';
|
|
5
|
-
|
|
6
|
-
const maxLimit = 100;
|
|
7
|
-
const defaultLimit = 9;
|
|
8
|
-
|
|
9
|
-
export default async function gisRegistry({
|
|
10
|
-
slug, objectId, search, filter, sql, page, limit: queryLimit,
|
|
11
|
-
}, pg = pgClients.client) {
|
|
12
|
-
|
|
13
|
-
if (sql && process.platform !== 'win32') {
|
|
14
|
-
throw ConflictError('query.sql is not allowed');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const limit = Math.min(queryLimit || defaultLimit, maxLimit);
|
|
18
|
-
|
|
19
|
-
const offset = page && page > 0 && !objectId ? (page - 1) * limit : 0;
|
|
20
|
-
|
|
21
|
-
if (!slug) {
|
|
22
|
-
throw BadRequestError('Params slug is required');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
rows: [registry],
|
|
27
|
-
} = await pg.query(
|
|
28
|
-
`SELECT register_id, name, description, card, table_name,
|
|
29
|
-
columns, filters, query, "order", pk, register_key,
|
|
30
|
-
is_files, view, is_downloadable, is_map, is_register, service_id
|
|
31
|
-
FROM gis.registers
|
|
32
|
-
WHERE $1 in (register_key,register_id)`,
|
|
33
|
-
[slug],
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
if (registry) {
|
|
37
|
-
return handleRegistryRequest({
|
|
38
|
-
settings: registry,
|
|
39
|
-
query: { search, filter },
|
|
40
|
-
object_id: objectId,
|
|
41
|
-
offset,
|
|
42
|
-
limit,
|
|
43
|
-
page,
|
|
44
|
-
pg,
|
|
45
|
-
sql,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const registryTemplate = await getTemplate('registry', slug);
|
|
50
|
-
|
|
51
|
-
if (!registryTemplate) {
|
|
52
|
-
throw NotFoundError('Template not found: ' + slug);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return handleRegistryRequest({
|
|
56
|
-
settings: registryTemplate,
|
|
57
|
-
query: { search, filter },
|
|
58
|
-
object_id: objectId,
|
|
59
|
-
register_key: registry.register_key,
|
|
60
|
-
is_downloadable: registry?.is_downloadable || registryTemplate?.is_downloadable,
|
|
61
|
-
is_map: registryTemplate.is_map,
|
|
62
|
-
is_register: registryTemplate.is_register,
|
|
63
|
-
is_files: registryTemplate.is_files,
|
|
64
|
-
service_id: registryTemplate.service_id,
|
|
65
|
-
offset,
|
|
66
|
-
limit,
|
|
67
|
-
page,
|
|
68
|
-
pg,
|
|
69
|
-
sql,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
1
|
+
import { pgClients, getTemplate } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
import { BadRequestError, ConflictError, NotFoundError } from "@opengis/fastify-table/errors.js";
|
|
3
|
+
|
|
4
|
+
import { handleRegistryRequest } from './handleRegistryRequest.js';
|
|
5
|
+
|
|
6
|
+
const maxLimit = 100;
|
|
7
|
+
const defaultLimit = 9;
|
|
8
|
+
|
|
9
|
+
export default async function gisRegistry({
|
|
10
|
+
slug, objectId, search, filter, sql, page, limit: queryLimit,
|
|
11
|
+
}, pg = pgClients.client) {
|
|
12
|
+
|
|
13
|
+
if (sql && process.platform !== 'win32') {
|
|
14
|
+
throw ConflictError('query.sql is not allowed');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const limit = Math.min(queryLimit || defaultLimit, maxLimit);
|
|
18
|
+
|
|
19
|
+
const offset = page && page > 0 && !objectId ? (page - 1) * limit : 0;
|
|
20
|
+
|
|
21
|
+
if (!slug) {
|
|
22
|
+
throw BadRequestError('Params slug is required');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
rows: [registry],
|
|
27
|
+
} = await pg.query(
|
|
28
|
+
`SELECT register_id, name, description, card, table_name,
|
|
29
|
+
columns, filters, query, "order", pk, register_key,
|
|
30
|
+
is_files, view, is_downloadable, is_map, is_register, service_id
|
|
31
|
+
FROM gis.registers
|
|
32
|
+
WHERE $1 in (register_key,register_id)`,
|
|
33
|
+
[slug],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (registry) {
|
|
37
|
+
return handleRegistryRequest({
|
|
38
|
+
settings: registry,
|
|
39
|
+
query: { search, filter },
|
|
40
|
+
object_id: objectId,
|
|
41
|
+
offset,
|
|
42
|
+
limit,
|
|
43
|
+
page,
|
|
44
|
+
pg,
|
|
45
|
+
sql,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const registryTemplate = await getTemplate('registry', slug);
|
|
50
|
+
|
|
51
|
+
if (!registryTemplate) {
|
|
52
|
+
throw NotFoundError('Template not found: ' + slug);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return handleRegistryRequest({
|
|
56
|
+
settings: registryTemplate,
|
|
57
|
+
query: { search, filter },
|
|
58
|
+
object_id: objectId,
|
|
59
|
+
register_key: registry.register_key,
|
|
60
|
+
is_downloadable: registry?.is_downloadable || registryTemplate?.is_downloadable,
|
|
61
|
+
is_map: registryTemplate.is_map,
|
|
62
|
+
is_register: registryTemplate.is_register,
|
|
63
|
+
is_files: registryTemplate.is_files,
|
|
64
|
+
service_id: registryTemplate.service_id,
|
|
65
|
+
offset,
|
|
66
|
+
limit,
|
|
67
|
+
page,
|
|
68
|
+
pg,
|
|
69
|
+
sql,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { NotFoundError } from "@opengis/fastify-table/errors.js";
|
|
2
|
-
import { pgClients, getTemplatePath, getTemplate } from "@opengis/fastify-table/utils.js";
|
|
3
|
-
|
|
4
|
-
export default async function gisRegistryList({ page = 1, limit = 9, search = '' }, pg = pgClients.client) {
|
|
5
|
-
|
|
6
|
-
const offset = limit * (page - 1);
|
|
7
|
-
|
|
8
|
-
const dbResult = await pg.query(
|
|
9
|
-
`SELECT register_key, name, description, keywords
|
|
10
|
-
FROM gis.registers
|
|
11
|
-
WHERE is_public = true AND is_active = true`
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
let templates = dbResult?.rows;
|
|
15
|
-
let fromDatabase = true;
|
|
16
|
-
|
|
17
|
-
if (!templates?.length) {
|
|
18
|
-
fromDatabase = false;
|
|
19
|
-
|
|
20
|
-
const registryListTemplate = getTemplatePath('registry');
|
|
21
|
-
|
|
22
|
-
if (!registryListTemplate?.length) {
|
|
23
|
-
throw NotFoundError('Templates not found');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
templates = (await Promise.all(
|
|
27
|
-
registryListTemplate.map(async ([slug]) => {
|
|
28
|
-
try {
|
|
29
|
-
const tpl = await getTemplate('registry', slug);
|
|
30
|
-
if (tpl?.visible === false) return null;
|
|
31
|
-
|
|
32
|
-
const { register_key, name, description, keywords } = tpl;
|
|
33
|
-
return { register_key, name, description, keywords };
|
|
34
|
-
} catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const filteredBySearch = search
|
|
42
|
-
? templates.filter(tpl => {
|
|
43
|
-
const q = search.toLowerCase();
|
|
44
|
-
return (
|
|
45
|
-
tpl.name?.toLowerCase().includes(q) ||
|
|
46
|
-
tpl.description?.toLowerCase().includes(q) ||
|
|
47
|
-
tpl.keywords?.join(' ').toLowerCase().includes(q)
|
|
48
|
-
);
|
|
49
|
-
})
|
|
50
|
-
: templates;
|
|
51
|
-
|
|
52
|
-
const paged = filteredBySearch.slice(offset, offset + limit);
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
rows: paged,
|
|
56
|
-
total: filteredBySearch.length,
|
|
57
|
-
page,
|
|
58
|
-
limit,
|
|
59
|
-
offset
|
|
60
|
-
};
|
|
61
|
-
}
|
|
1
|
+
import { NotFoundError } from "@opengis/fastify-table/errors.js";
|
|
2
|
+
import { pgClients, getTemplatePath, getTemplate } from "@opengis/fastify-table/utils.js";
|
|
3
|
+
|
|
4
|
+
export default async function gisRegistryList({ page = 1, limit = 9, search = '' }, pg = pgClients.client) {
|
|
5
|
+
|
|
6
|
+
const offset = limit * (page - 1);
|
|
7
|
+
|
|
8
|
+
const dbResult = await pg.query(
|
|
9
|
+
`SELECT register_key, name, description, keywords
|
|
10
|
+
FROM gis.registers
|
|
11
|
+
WHERE is_public = true AND is_active = true`
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
let templates = dbResult?.rows;
|
|
15
|
+
let fromDatabase = true;
|
|
16
|
+
|
|
17
|
+
if (!templates?.length) {
|
|
18
|
+
fromDatabase = false;
|
|
19
|
+
|
|
20
|
+
const registryListTemplate = getTemplatePath('registry');
|
|
21
|
+
|
|
22
|
+
if (!registryListTemplate?.length) {
|
|
23
|
+
throw NotFoundError('Templates not found');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
templates = (await Promise.all(
|
|
27
|
+
registryListTemplate.map(async ([slug]) => {
|
|
28
|
+
try {
|
|
29
|
+
const tpl = await getTemplate('registry', slug);
|
|
30
|
+
if (tpl?.visible === false) return null;
|
|
31
|
+
|
|
32
|
+
const { register_key, name, description, keywords } = tpl;
|
|
33
|
+
return { register_key, name, description, keywords };
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const filteredBySearch = search
|
|
42
|
+
? templates.filter(tpl => {
|
|
43
|
+
const q = search.toLowerCase();
|
|
44
|
+
return (
|
|
45
|
+
tpl.name?.toLowerCase().includes(q) ||
|
|
46
|
+
tpl.description?.toLowerCase().includes(q) ||
|
|
47
|
+
tpl.keywords?.join(' ').toLowerCase().includes(q)
|
|
48
|
+
);
|
|
49
|
+
})
|
|
50
|
+
: templates;
|
|
51
|
+
|
|
52
|
+
const paged = filteredBySearch.slice(offset, offset + limit);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
rows: paged,
|
|
56
|
+
total: filteredBySearch.length,
|
|
57
|
+
page,
|
|
58
|
+
limit,
|
|
59
|
+
offset
|
|
60
|
+
};
|
|
61
|
+
}
|