@opengis/gis 0.2.45 → 0.2.47

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.
Files changed (159) hide show
  1. package/README.md +5 -5
  2. package/dist/index.css +1 -1
  3. package/dist/index.js +6244 -5599
  4. package/dist/index.umd.cjs +72 -52
  5. package/module/cls.json +6 -6
  6. package/module/gis/card/gis.metadata.table/index.yml +22 -22
  7. package/module/gis/card/gis.metadata.table/main_info.hbs +20 -20
  8. package/module/gis/card/gis.metadata.table/metadata_info.hbs +27 -27
  9. package/module/gis/card/gis.metadata.table/other.hbs +25 -25
  10. package/module/gis/card/gis.rasters.table/index.yml +11 -11
  11. package/module/gis/card/gis.rasters.table/main_info.hbs +27 -27
  12. package/module/gis/card/gis.registers.table/cls.hbs +36 -36
  13. package/module/gis/card/gis.registers.table/columns.hbs +89 -89
  14. package/module/gis/card/gis.registers.table/filters.hbs +80 -80
  15. package/module/gis/card/gis.registers.table/index.yml +23 -23
  16. package/module/gis/card/gis.registers.table/main_info.hbs +35 -35
  17. package/module/gis/card/gis.registers.table/source.hbs +45 -45
  18. package/module/gis/card/gis.services.table/attributes.hbs +91 -91
  19. package/module/gis/card/gis.services.table/filters.hbs +83 -83
  20. package/module/gis/card/gis.services.table/index.yml +25 -25
  21. package/module/gis/card/gis.services.table/main_info.hbs +27 -27
  22. package/module/gis/card/gis.services.table/source.hbs +25 -25
  23. package/module/gis/cls/bool.yes_no.json +12 -12
  24. package/module/gis/cls/encoding.json +14 -14
  25. package/module/gis/cls/geom_type.json +14 -14
  26. package/module/gis/cls/gis.column_type.json +34 -34
  27. package/module/gis/cls/gis.column_view_type.json +26 -26
  28. package/module/gis/cls/gis.filter_type.json +22 -22
  29. package/module/gis/cls/language.json +10 -10
  30. package/module/gis/cls/meta.service_type.json +42 -42
  31. package/module/gis/cls/ogc.service.json +21 -21
  32. package/module/gis/cls/service_type.json +42 -42
  33. package/module/gis/cls/source_type.json +10 -10
  34. package/module/gis/cls/standarts.json +6 -6
  35. package/module/gis/cls/topic_category.json +106 -106
  36. package/module/gis/cls/update_frequency.json +29 -29
  37. package/module/gis/cls/view.json +21 -21
  38. package/module/gis/form/gis.cartocss.form.json +45 -45
  39. package/module/gis/form/gis.group_list.form.json +17 -17
  40. package/module/gis/form/gis.maps.form.json +61 -61
  41. package/module/gis/form/gis.metadata.form.json +240 -240
  42. package/module/gis/form/gis.ogc_service.form.json +45 -45
  43. package/module/gis/form/gis.rasters.form.json +103 -103
  44. package/module/gis/form/gis.registers.form.json +124 -124
  45. package/module/gis/form/gis.registers_column.form.json +84 -84
  46. package/module/gis/form/gis.registers_filter.form.json +65 -65
  47. package/module/gis/form/gis.services.form.json +111 -111
  48. package/module/gis/form/gis.services_attributes.form.json +75 -75
  49. package/module/gis/form/gis.services_filter.form.json +65 -65
  50. package/module/gis/menu.json +43 -43
  51. package/module/gis/select/pg.columns.parent.sql +6 -6
  52. package/module/gis/select/pg.table_name.sql +17 -17
  53. package/module/gis/select/service_id.sql +1 -1
  54. package/module/gis/table/gis.cartocss.table.json +62 -62
  55. package/module/gis/table/gis.group_list.table.json +35 -35
  56. package/module/gis/table/gis.maps.table.json +108 -108
  57. package/module/gis/table/gis.metadata.table.json +70 -70
  58. package/module/gis/table/gis.ogc_service.table.json +98 -98
  59. package/module/gis/table/gis.rasters.table.json +101 -101
  60. package/module/gis/table/gis.registers.table.json +144 -144
  61. package/module/gis/table/gis.services.table.json +121 -121
  62. package/module/gis/table/site.gis.registers.table.json +88 -88
  63. package/module/gis/table/site.gis.services.table.json +106 -106
  64. package/module/gis/templates/ISO19136_2017_gml_template.xml +330 -330
  65. package/module/gis/tokens.yml +5 -5
  66. package/module/test/cls/bp_build_type.json +37 -37
  67. package/module/test/cls/doc_status.json +31 -31
  68. package/module/test/cls/ts.temp_status.json +18 -18
  69. package/module/test/cls/ts.temp_structure.ts_class.json +49 -49
  70. package/module/test/cls/ts.temp_type.json +9 -9
  71. package/module/test/layer/bp.json +59 -59
  72. package/module/test/layer/bp1.yml +33 -33
  73. package/module/test/layer/individual.yml +53 -53
  74. package/module/test/layer/ts.linking_passport.yml +55 -55
  75. package/module/test/layer/ts.temp_structure.yml +50 -50
  76. package/module/test/map/addr.yml +21 -21
  77. package/module/test/map/bp_myo.json +43 -43
  78. package/module/test/map/bpf.json +43 -43
  79. package/module/test/map/main.json +36 -36
  80. package/module/test/map/mbd.json +91 -91
  81. package/module/test/map/ts.json +52 -52
  82. package/module/test/select/address_id.json +2 -2
  83. package/module/test/select/address_id.sql +7 -7
  84. package/module/test/select/core.user_uid.sql +1 -1
  85. package/module/test/table/data_address.street.table.json +69 -69
  86. package/module/test/table/data_bp_myo.bp.table.json +122 -122
  87. package/package.json +75 -75
  88. package/plugin.js +45 -44
  89. package/server/migrations/maps.sql +30 -30
  90. package/server/migrations/ogc.sql +106 -106
  91. package/server/migrations/rasters.sql +263 -263
  92. package/server/migrations/services.sql +247 -247
  93. package/server/migrations/widgets.sql +20 -20
  94. package/server/plugins/crons.js +21 -21
  95. package/server/plugins/mapnik/funcs/mapnik.js +111 -106
  96. package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
  97. package/server/plugins/mapnik/map.proto +151 -0
  98. package/server/plugins/vite.js +74 -74
  99. package/server/routes/gis/cartocss/add.cartocss.js +152 -18
  100. package/server/routes/gis/cartocss/get.cartocss.js +12 -12
  101. package/server/routes/gis/dashboard.js +29 -29
  102. package/server/routes/gis/index.mjs +73 -73
  103. package/server/routes/gis/metadata/metadataXML.js +13 -13
  104. package/server/routes/gis/ogc/map.info.point.js +124 -124
  105. package/server/routes/gis/registers/add.registry.js +35 -35
  106. package/server/routes/gis/registers/del.registry.js +14 -14
  107. package/server/routes/gis/registers/funcs/classifiers.js +100 -100
  108. package/server/routes/gis/registers/funcs/columns.js +4 -4
  109. package/server/routes/gis/registers/funcs/content.type.js +9 -9
  110. package/server/routes/gis/registers/funcs/get.info.js +89 -89
  111. package/server/routes/gis/registers/funcs/handleRegistryRequest.js +145 -145
  112. package/server/routes/gis/registers/gis.export.js +148 -148
  113. package/server/routes/gis/registers/gis.registry.js +64 -64
  114. package/server/routes/gis/registers/gis.registry.list.js +59 -59
  115. package/server/routes/gis/registers/insert.columns.js +107 -107
  116. package/server/routes/gis/registers/insert.filters.js +110 -110
  117. package/server/routes/gis/registers/map.registry.js +79 -79
  118. package/server/routes/gis/services/add.service.js +64 -64
  119. package/server/routes/gis/services/del.service.js +12 -12
  120. package/server/routes/gis/services/get.layer.geom.js +27 -27
  121. package/server/routes/gis/services/get.services.col.js +33 -33
  122. package/server/routes/gis/services/get.services.js +84 -84
  123. package/server/routes/gis/services/legend.auto.js +77 -77
  124. package/server/routes/map/controllers/geojson.js +187 -187
  125. package/server/routes/map/controllers/jsonData.js +205 -205
  126. package/server/routes/map/controllers/layerList.js +60 -60
  127. package/server/routes/map/controllers/map.js +123 -123
  128. package/server/routes/map/controllers/mapCatalog.js +72 -72
  129. package/server/routes/map/controllers/mapCatalogAttribute.js +55 -55
  130. package/server/routes/map/controllers/mapFeatures.js +128 -128
  131. package/server/routes/map/controllers/mapFormat.js +83 -83
  132. package/server/routes/map/controllers/mapTiles.js +152 -152
  133. package/server/routes/map/controllers/maps.js +15 -15
  134. package/server/routes/map/controllers/marker_icon.js +43 -43
  135. package/server/routes/map/controllers/vtile.js +172 -172
  136. package/server/routes/map/index.mjs +142 -142
  137. package/server/routes/map/maps/add.map.js +43 -43
  138. package/server/routes/map/maps/del.map.js +18 -18
  139. package/server/routes/map/maps/get.map.js +80 -80
  140. package/server/routes/map/vtile1.js +170 -170
  141. package/server/routes/map/widgets/add.widget.js +38 -38
  142. package/server/routes/map/widgets/del.widget.js +22 -22
  143. package/server/routes/map/widgets/get.widget.js +40 -40
  144. package/server/routes/mapnik/controllers/createXML.js +61 -0
  145. package/server/routes/mapnik/controllers/rtile.js +86 -0
  146. package/server/routes/mapnik/controllers/uploadRaster.js +159 -0
  147. package/server/routes/mapnik/index.js +16 -0
  148. package/server/routes/root.mjs +3 -3
  149. package/utils.js +11 -11
  150. package/server/plugins/mapnik/funcs/createXML.js +0 -72
  151. package/server/plugins/mapnik/funcs/gdalWrapper.js +0 -72
  152. package/server/plugins/mapnik/funcs/map.proto +0 -241
  153. package/server/plugins/mapnik/funcs/rasterConfig.js +0 -11
  154. package/server/plugins/mapnik/funcs/rasterExists.js +0 -21
  155. package/server/plugins/mapnik/funcs/rasterInfo.js +0 -109
  156. package/server/plugins/mapnik/funcs/rasterVrt.js +0 -56
  157. package/server/plugins/mapnik/funcs/rasterXML.js +0 -65
  158. package/server/plugins/mapnik/utils/map.proto +0 -241
  159. package/server/routes/map/controllers/rtile.js +0 -134
@@ -1,72 +0,0 @@
1
- import path from 'path';
2
- import { randomUUID as uuidv4 } from 'crypto';
3
- import mapnik from './mapnik.js';
4
-
5
- import { config } from '@opengis/fastify-table/utils.js';
6
-
7
- const { mapServerAddress } = mapnik();
8
-
9
- function unixPath(data) {
10
- if (mapServerAddress && !mapServerAddress?.includes('localhost') && data?.[1] === ':') {
11
- return path.posix.join('/data/softpro', data.substr(3).replace(/\\/g, '/'));
12
- }
13
- return data;
14
- }
15
- const gdalWrapper = async ({
16
- name, pathIn, pathOut, parameters, funcs, send = console.log,
17
- }) => {
18
- const timeStart = new Date();
19
- const pref = name === 'gdalbuildvrt' ? ' -o ' : '';
20
- const cmd = `${name} ${parameters || ''} ${unixPath(pathIn) || ''} ${pref} ${unixPath(pathOut) || ''}`;
21
-
22
- if (mapServerAddress) {
23
- const out = pref + (unixPath(pathOut) || '');
24
- const obj = {
25
- name, path: unixPath(pathIn), out, params: parameters,
26
- };
27
-
28
- const time = Date.now();
29
- const { result, err } = await mapnik().gdal(obj);
30
-
31
- if (config.local && false) {
32
- send(cmd);
33
- send(JSON.stringify(obj));
34
- send(`${Date.now() - time}`);
35
- }
36
-
37
- if (err) {
38
- const logObj = {
39
- level: 'ERROR',
40
- uuid: uuidv4(),
41
- name: 'GDAL',
42
- subname: 'GDALWRAPPER',
43
- msec: new Date() - timeStart,
44
- param: { cmd },
45
- status: '500',
46
- response: { error: err },
47
- };
48
- // log.error({ name: 'gdal', ...logObj });
49
- send(err);
50
- }
51
- return { err, result };
52
- }
53
-
54
- const result = await funcs.exec(cmd, { send });
55
- if (!result) {
56
- const logObj = {
57
- level: 'ERROR',
58
- uuid: uuidv4(),
59
- name: 'GDAL',
60
- subname: 'GDALWRAPPER',
61
- msec: new Date() - timeStart,
62
- param: { cmd },
63
- status: '500',
64
- response: { error: `Cant execute ${cmd}` },
65
- };
66
- // log.error({ name: 'gdal', ...logObj });
67
- return { err: `Cant execute ${cmd}` };
68
- }
69
- return { result };
70
- };
71
-
72
- export default gdalWrapper;
@@ -1,241 +0,0 @@
1
- syntax = "proto3";
2
-
3
-
4
- message render_in {
5
- string path = 1;
6
- string name = 2;
7
- repeated double bbox = 3 [packed=true];
8
- string tile = 4;
9
- string xml = 5;
10
- int32 width = 6;
11
- int32 height = 7;
12
- }
13
-
14
-
15
- message render_out {
16
- string err = 1;
17
- string base64 = 2;
18
- string tile = 3;
19
- }
20
-
21
- message xml_in {
22
- string path = 1;
23
- string name = 2;
24
- string xml = 3;
25
- bool reload = 4;
26
- }
27
-
28
- message xml_out {
29
- string err = 1;
30
- bool is_ok = 2;
31
- }
32
-
33
- message cmd_in {
34
- string cmd = 1;
35
- string svg = 2;
36
- string filename = 3;
37
- }
38
-
39
- message cmd_out {
40
- string err = 1;
41
- string base64 = 2;
42
- }
43
-
44
- message gdal_in {
45
- string name = 1;
46
- string path = 2;
47
- string out = 3;
48
- string params = 4;
49
- }
50
- message gdal_out {
51
- string result = 1;
52
- string err = 2;
53
- }
54
-
55
- message clear_tiles_in {
56
- string path = 1;
57
- }
58
-
59
- message clear_tiles_out {
60
- oneof clear_message {
61
- bool ok = 1;
62
- string err = 2;
63
- }
64
- }
65
-
66
- message empty {}
67
-
68
- message statusRenderInfo {
69
- string name = 1;
70
- bool isActive = 2;
71
- float workTime = 3;
72
- }
73
-
74
- message statusInfo {
75
- repeated statusRenderInfo info = 1;
76
- }
77
-
78
- message printMapOut {
79
- string map = 1;
80
- string err = 2;
81
- }
82
-
83
- message xyz {
84
- float x = 1;
85
- float y = 2;
86
- float z = 3;
87
- }
88
-
89
- message printMapIn {
90
- string baseurl = 1;
91
- string baseImg = 2;
92
- repeated string xml = 3;
93
- string overlayXml = 4;
94
- string overlay = 5;
95
- int32 width = 6;
96
- int32 height = 7;
97
- repeated double bbox = 8;
98
- xyz pos = 9;
99
- string geojsonSettings = 10;
100
- }
101
-
102
- message log_in {
103
- uint32 rows = 1;
104
- string level = 2;
105
- }
106
-
107
- message log_out {
108
- repeated string logs = 1;
109
- }
110
-
111
- message sqlToShpIn {
112
- string db = 1;
113
- string host = 2;
114
- string port = 3;
115
- string sql = 4;
116
- string savePath = 5;
117
- string shpName = 6;
118
- }
119
-
120
- message shapeOut {
121
- string zipPath = 1;
122
- }
123
-
124
- message fileIn {
125
- bytes fileBytes = 1;
126
- string relativeFilepath = 2;
127
- }
128
-
129
- message deleteFileIn {
130
- string dir = 1;
131
- repeated string objectList = 2;
132
- }
133
-
134
- message fileManagerOut {
135
- bool status = 1;
136
- string operation = 2;
137
- }
138
-
139
- message checkFilesDir {
140
- string dir = 1;
141
- repeated string filesSearch = 2;
142
- }
143
-
144
- enum status {
145
- LOADING = 0;
146
- OK = 1;
147
- }
148
-
149
- message filesStatus {
150
- status fileLoadingStatus = 1;
151
- }
152
-
153
- message fileListIn {
154
- string dir = 1;
155
- }
156
-
157
- message fileInfo {
158
- repeated fileInfoL fileInfoList = 1;
159
- }
160
-
161
- message fileInfoL {
162
- oneof fileInfo {
163
- fileInfoObj file = 1;
164
- dirInfoObj dir = 2;
165
- }
166
- }
167
-
168
- message fileInfoObj {
169
- string type = 1;
170
- string birthtime = 2;
171
- string name = 3;
172
- uint64 size = 4;
173
- string ext = 5;
174
- string server = 6;
175
- }
176
-
177
- message dirInfoObj {
178
- string type = 1;
179
- string birthtime = 2;
180
- string name = 3;
181
- uint64 size = 4;
182
- uint64 count = 5;
183
- string server = 6;
184
- }
185
-
186
- message deleteOut {
187
- repeated deleteObjSuccess success = 1;
188
- repeated deleteObjError error = 2;
189
-
190
- }
191
-
192
- message deleteObjSuccess {
193
- string object = 1;
194
- string type = 2;
195
- string status = 3;
196
- }
197
-
198
- message deleteObjError {
199
- string object = 1;
200
- string fullPath = 2;
201
- string result = 3;
202
- }
203
-
204
- message readDirIn {
205
- string dir = 1;
206
- repeated string filter = 2;
207
- string fullPath = 3;
208
- }
209
-
210
- message readDirOut {
211
- repeated string res = 1;
212
-
213
- }
214
-
215
- message downloadFileIn {
216
- string filePath = 1;
217
- }
218
-
219
- message downloadFileOut {
220
- bytes chunk_data = 1;
221
- }
222
-
223
-
224
- service Map {
225
- rpc Render(render_in) returns (render_out) {}
226
- rpc RenderXML(render_in) returns (render_out) {}
227
- rpc LoadXML(xml_in) returns (xml_out) {}
228
- rpc MarkerIcon(cmd_in) returns (cmd_out) {}
229
- rpc Gdal(gdal_in) returns (gdal_out) {}
230
- rpc ClearTiles(clear_tiles_in) returns (clear_tiles_out) {}
231
- rpc RenderStatus(empty) returns (statusInfo) {}
232
- rpc PrintMap(printMapIn) returns (printMapOut) {}
233
- rpc Log(log_in) returns (log_out) {}
234
- rpc SqlToShp(sqlToShpIn) returns (shapeOut) {}
235
- rpc uploadFile(fileIn) returns (fileManagerOut) {}
236
- rpc deleteFiles(deleteFileIn) returns (deleteOut) {}
237
- rpc checkFiles(checkFilesDir) returns (filesStatus) {}
238
- rpc fileList(fileListIn) returns (fileInfo) {}
239
- rpc readDir(readDirIn) returns (readDirOut) {}
240
- rpc downloadFile(downloadFileIn) returns (stream downloadFileOut) {}
241
- }
@@ -1,11 +0,0 @@
1
- import yaml from 'js-yaml';
2
-
3
- import mapnik from './mapnik.js';
4
-
5
- const { downloadFile } = mapnik();
6
-
7
- export default async function rasterConfig(fullPath) {
8
- if (!fullPath.endsWith('config.yml')) return;
9
- const { data } = await downloadFile({ filePath: fullPath });
10
- return yaml.load(data.toString('utf8'));
11
- }
@@ -1,21 +0,0 @@
1
- import path from 'node:path';
2
-
3
- import mapnik from './mapnik.js';
4
-
5
- const { checkFiles } = mapnik();
6
-
7
- export default async function rasterExists(fullPath, preview = 0) {
8
- const name = path.basename(fullPath).replace('.vrt', '.tif');
9
- const findpath = preview ? path.posix.join(path.dirname(fullPath), 'preview1', name) : fullPath;
10
- const { fileLoadingStatus: stat } = await checkFiles({ dir: path.dirname(findpath), filesSearch: [path.basename(findpath)] })
11
-
12
- if (stat === 'OK') {
13
- return findpath;
14
- }
15
-
16
- if (fullPath.includes('mosaic.vrt')) {
17
- const { fileLoadingStatus: stat1 } = await checkFiles({ dir: path.dirname(findpath), filesSearch: ['mosaic.vrt'] });
18
- console.log('stat: mosaic.vrt', stat1);
19
- return stat1 === 'OK' ? findpath.replace('.tif', '.vrt') : null;
20
- }
21
- }
@@ -1,109 +0,0 @@
1
- import path from 'node:path';
2
- import { createHash } from 'node:crypto';
3
- import { existsSync } from 'node:fs';
4
- import { writeFile, mkdir, readFile } from 'node:fs/promises';
5
-
6
- import { getRedis, logger, getPG } from '@opengis/fastify-table/utils.js';
7
-
8
- import mapnik from './mapnik.js';
9
- import rasterVrt from './rasterVrt.js';
10
- import rasterExists from './rasterExists.js';
11
- import rootFolder from './rootFolder.mjs';
12
-
13
- const { gdal } = mapnik();
14
-
15
- const pg = getPG();
16
- const rclient = getRedis();
17
-
18
- export default async function rasterInfo(fullPath, send = () => { }, proj4text, nocache = 0) {
19
- const time = [Date.now()];
20
-
21
- const key = `raster-stat:${fullPath}`;
22
- const cache = await rclient.get(key).then(el => (el ? JSON.parse(el) : null));
23
-
24
- if (cache?.fullPath && cache.size && cache.extent && !nocache) {
25
- return { type: 'redis', ...cache };
26
- }
27
-
28
- // console.log(fullPath)
29
- if (fullPath.includes('.vrt')) {
30
- await rasterVrt(fullPath, send)
31
- }
32
-
33
- // file cache
34
- const hash = createHash('md5').update(fullPath).digest("hex");
35
-
36
- const statPath = path.join(rootFolder, `stat/${hash}.json`);
37
- if (existsSync(statPath) && !nocache) {
38
- send('stat:' + statPath);
39
- const fileData = await readFile(statPath, 'utf-8');
40
-
41
- await rclient.set(key, fileData);
42
- const parse = JSON.parse(fileData)
43
-
44
- if (parse.fullPath && parse.extent) return parse;
45
- }
46
- // console.log(fullPath);
47
-
48
- // size
49
- const exists = fullPath.includes('.vrt') ? 1 : await rasterExists(fullPath)
50
- //console.log(fullPath, exists)
51
- send('exists:' + fullPath + ' - ' + (exists ? 'yes' : 'no'));
52
- if (!exists) return { error: 'file not exists info ' + fullPath }
53
-
54
- const { result: stat, error: err1 = '' } = await gdal({ name: 'ls -lah ', path: fullPath })
55
- .then(el => (el.result ? { result: el.result.replace(/\n/g, '') } : el));
56
- time.push(Date.now());
57
-
58
- const size = stat.split(' ')[4]
59
-
60
- // srs
61
- // send('srs:' + (proj4text || '') + fullPath)
62
- const { result: srs, err: error1 } = proj4text ? { result: proj4text } : await gdal({ name: 'gdalsrsinfo', path: fullPath, params: '-o proj4 ' })
63
- .then(el => (el.result ? { result: el.result.replace(/\n/g, '') } : el));
64
-
65
- if (error1) return { error: error1 }
66
- time.push(Date.now());
67
-
68
- // gdalinfo
69
- // send('info:' + fullPath)
70
- const { result, err: error } = await gdal({ name: 'gdalinfo', path: fullPath, params: '-json' });
71
-
72
- if (error) return { error }
73
- const gdalInfo = JSON.parse(result);
74
-
75
- time.push(Date.now());
76
- send('wgs84:' + JSON.stringify(gdalInfo?.wgs84Extent) + ' coors:' + JSON.stringify(gdalInfo?.cornerCoordinates));
77
-
78
- console.log(proj4text, gdalInfo?.cornerCoordinates)
79
- if (proj4text && gdalInfo?.cornerCoordinates) {
80
- const { lowerLeft, upperRight } = gdalInfo.cornerCoordinates;
81
- //send(gdalInfo.cornerCoordinates);
82
- const { geom, extent } = await pg.query(`select st_asgeojson(geom)::json as geom, geom::box2d as extent from
83
- (select st_transform('box(${lowerLeft[0]} ${lowerLeft[1]}, ${upperRight[0]} ${upperRight[1]})'::box2d,'${proj4text}','+proj=longlat +datum=WGS84 +no_defs') as geom )q`)
84
- .then(el => el.rows[0]);
85
- //send(extent)
86
- gdalInfo.wgs84Extent = geom;
87
- gdalInfo.extent = extent.substring(4, extent.length - 1).replace(/ /g, ',').split(',')
88
- }
89
-
90
- // extent
91
- const geom = gdalInfo?.wgs84Extent;
92
- const extent = gdalInfo.extent || (geom?.coordinates?.[0]?.[0] ? geom.coordinates[0][0].concat(geom.coordinates[0][2]) : undefined);
93
- // send(extent);
94
-
95
- const data = {
96
- time: { total: Date.now() - time[0], size: time[1] - time[0], srs: time[2] - time[1], info: time[3] - time[2] }, srs, gdalInfo, fullPath, size, extent, error
97
- };
98
-
99
- await rclient.setex(key, 8000, JSON.stringify(data));
100
-
101
- // file cache
102
- await mkdir(path.dirname(statPath), { recursive: true });
103
-
104
- logger.file('editor', { time: Date.now() - time[0], srs, statPath, })
105
-
106
- await writeFile(statPath, JSON.stringify(data, null, 2));
107
-
108
- return data;
109
- }
@@ -1,56 +0,0 @@
1
- import path from 'node:path';
2
-
3
- import mapnik from './mapnik.js';
4
- import rasterConfig from './rasterConfig.js';
5
-
6
- const { gdal, uploadFile, downloadFile } = mapnik();
7
-
8
- export default async function rasterVrt(rasterPath, send = () => { }) {
9
- if (rasterPath.includes('.tif')) {
10
- return null;
11
- }
12
-
13
- const folderPath = path.posix.dirname(rasterPath);
14
-
15
- // vrt config
16
- const configFilePath = rasterPath.replace('/preview1', '').replace('mosaic.vrt', 'config.yml')
17
- const configData = await rasterConfig(configFilePath);
18
-
19
- // -b 1 -b 2 -b 3 -overwrite
20
- // -b 1 -b 2 -b 3 -hidenodata -srcnodata "0 0 0" -addalpha -overwrite
21
- const vrt = configData?.vrt || ' -b 1 -b 2 -b 3 -hidenodata -srcnodata "0 0 0" -vrtnodata "256 256 256" -addalpha -overwrite';
22
-
23
-
24
- const paramsVrt = `${vrt} -input_file_list ${folderPath}/files.txt `; // ${folderPath}/mosaic.vrt ${folderPath}/*.tif
25
- send(paramsVrt)
26
- const obj = {
27
- name: 'gdalbuildvrt', out: ` -o ${folderPath}/mosaic.vrt `, params: paramsVrt,
28
- };
29
-
30
- // check mosaic.vrt exists
31
- const time1 = Date.now()
32
- const fullPath = rasterPath;
33
-
34
- send('vrt:' + rasterPath)
35
- const { result: resStat } = await gdal({ name: `ls "${fullPath}"` });
36
-
37
- if (resStat) return { obj, resStat };
38
-
39
- const { result: files } = await gdal({ name: `ls "${folderPath}"` });
40
- const fileList = files.split('\n').filter(el => el.toLowerCase().endsWith('.tif') && !el.includes('mosaic')).map(el => path.posix.join(folderPath, el) || `"${path.posix.join(folderPath, el)}"`);
41
- send({ folderPath, files: fileList.length, time: Date.now() - time1 })
42
-
43
- if (!fileList.length) return { err: 'fileList is empty' };
44
-
45
- await gdal({ name: `rm -rf "${folderPath}/files.txt"` });
46
-
47
- await uploadFile({ fileBytes: Buffer.from(fileList.join('\n')), relativeFilepath: path.posix.join(folderPath, 'files.txt') });
48
-
49
- const time = Date.now()
50
- send(obj);
51
- const { result, err } = await gdal(obj);
52
- send(err || result);
53
- await downloadFile({ filePath: fullPath });
54
- send({ rasterPath, time: Date.now() - time })
55
- return { result, err, obj };
56
- }
@@ -1,65 +0,0 @@
1
- import path from 'node:path';
2
- import { mkdir, writeFile } from 'node:fs/promises';
3
-
4
- import { config, pgClients } from '@opengis/fastify-table/utils.js';
5
-
6
- import rasterInfo from './rasterInfo.js';
7
- import createXML from './createXML.js';
8
- import mapnik from './mapnik.js';
9
- import rootFolder from './rootFolder.mjs';
10
-
11
- const { loadXML } = mapnik();
12
-
13
- export default async function rasterXML({ id, pg = pgClients.client, send = () => { } }) {
14
- if (!id) {
15
- send('not enough params: id', true);
16
- return { error: 'not enough params: id' };
17
- }
18
-
19
- const db = pg.options?.database;
20
-
21
- const { source_path: rasterPath, srid, proj4 } = await pg.query(
22
- 'SELECT source_path, srid, proj4 from gis.rasters where raster_id=$1',
23
- [id]
24
- ).then(el => el.rows?.[0] || {});
25
-
26
- const proj4text = srid ? await pg.query('select proj4text from spatial_ref_sys where srid::text=$1', [srid]).then(el => el.rows?.[0]?.proj4text) : null;
27
- const fullPath = rasterPath ? path.posix.join(config.mapServerRoot || '', config.folder, '/map/raster/', rasterPath, (rasterPath?.toLowerCase().includes('.tif') ? '' : 'mosaic.vrt')) : null;
28
-
29
- if (!fullPath) {
30
- send('file not found ' + fullPath, true);
31
- return { error: 'file not found ' + fullPath };
32
- }
33
-
34
- const { error, srs = proj4, extent, size, gdalInfo } = await rasterInfo(fullPath);
35
-
36
- send(`xml srs: ${proj4text || proj4 || '-'} file:${fullPath} size:${size}`);
37
-
38
- if (error) {
39
- send(error.toString(), true);
40
- return { error: error.toString() };
41
- }
42
-
43
- const xmlFileText = await createXML({
44
- fullPath,
45
- srs: proj4 || proj4text || srs,
46
- extent,
47
- send,
48
- size,
49
- });
50
-
51
- if (srs && proj4 && gdalInfo?.wgs84Extent && id) {
52
- const wgs = '+proj=longlat +datum=WGS84 +no_defs';
53
- await pg.query(
54
- 'update gis.rasters set bbox=st_transform(st_transform($2,$5,$3),$4,$5) where raster_id=$1 returning bbox::box2d',
55
- [id, gdalInfo.wgs84Extent, srs, proj4, wgs],
56
- ).then(el => el.rows?.[0]) || {};
57
- }
58
-
59
- send(xmlFileText);
60
- await loadXML({ xml: xmlFileText, name: id, reload: true });
61
- const localPath = path.join(rootFolder, `mapnik/${db}_${id}.xml`);
62
- await mkdir(path.dirname(localPath), { recursive: true });
63
- await writeFile(localPath, xmlFileText);
64
- return localPath;
65
- }