@opengis/gis 0.2.10 → 0.2.12

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 (147) hide show
  1. package/README.md +5 -5
  2. package/dist/index.css +1 -1
  3. package/dist/index.js +3591 -3469
  4. package/dist/index.umd.cjs +41 -41
  5. package/module/cls.json +6 -6
  6. package/module/gis/card/gis.maps.table/index.yml +14 -14
  7. package/module/gis/card/gis.maps.table/main_info.hbs +25 -25
  8. package/module/gis/card/gis.maps.table/maps_layers.hbs +19 -19
  9. package/module/gis/card/gis.metadata.table/index.yml +22 -22
  10. package/module/gis/card/gis.metadata.table/main_info.hbs +20 -20
  11. package/module/gis/card/gis.metadata.table/metadata_info.hbs +27 -27
  12. package/module/gis/card/gis.metadata.table/other.hbs +25 -25
  13. package/module/gis/card/gis.rasters.table/index.yml +11 -11
  14. package/module/gis/card/gis.rasters.table/main_info.hbs +27 -27
  15. package/module/gis/card/gis.registers.table/cls.hbs +36 -36
  16. package/module/gis/card/gis.registers.table/columns.hbs +89 -89
  17. package/module/gis/card/gis.registers.table/filters.hbs +80 -80
  18. package/module/gis/card/gis.registers.table/index.yml +23 -23
  19. package/module/gis/card/gis.registers.table/main_info.hbs +35 -35
  20. package/module/gis/card/gis.registers.table/source.hbs +45 -45
  21. package/module/gis/card/gis.services.table/attributes.hbs +91 -91
  22. package/module/gis/card/gis.services.table/filters.hbs +83 -83
  23. package/module/gis/card/gis.services.table/index.yml +25 -25
  24. package/module/gis/card/gis.services.table/main_info.hbs +27 -27
  25. package/module/gis/card/gis.services.table/source.hbs +25 -25
  26. package/module/gis/cls/bool.yes_no.json +12 -12
  27. package/module/gis/cls/encoding.json +14 -14
  28. package/module/gis/cls/geom_type.json +14 -14
  29. package/module/gis/cls/gis.column_type.json +34 -34
  30. package/module/gis/cls/gis.column_view_type.json +26 -26
  31. package/module/gis/cls/gis.filter_type.json +22 -22
  32. package/module/gis/cls/language.json +10 -10
  33. package/module/gis/cls/meta.service_type.json +42 -42
  34. package/module/gis/cls/ogc.service.json +21 -21
  35. package/module/gis/cls/service_type.json +42 -42
  36. package/module/gis/cls/source_type.json +10 -10
  37. package/module/gis/cls/standarts.json +6 -6
  38. package/module/gis/cls/topic_category.json +106 -106
  39. package/module/gis/cls/update_frequency.json +29 -29
  40. package/module/gis/cls/view.json +21 -21
  41. package/module/gis/form/gis.group_list.form.json +17 -17
  42. package/module/gis/form/gis.maps.form.json +64 -64
  43. package/module/gis/form/gis.metadata.form.json +240 -240
  44. package/module/gis/form/gis.ogc_service.form.json +40 -40
  45. package/module/gis/form/gis.rasters.form.json +99 -99
  46. package/module/gis/form/gis.registers.form.json +110 -110
  47. package/module/gis/form/gis.registers_column.form.json +84 -84
  48. package/module/gis/form/gis.registers_filter.form.json +65 -65
  49. package/module/gis/form/gis.services.form.json +120 -120
  50. package/module/gis/form/gis.services_attributes.form.json +75 -75
  51. package/module/gis/form/gis.services_filter.form.json +65 -65
  52. package/module/gis/menu.json +43 -43
  53. package/module/gis/select/pg.columns.parent.sql +6 -6
  54. package/module/gis/select/pg.table_name.sql +17 -17
  55. package/module/gis/select/service_id.sql +1 -1
  56. package/module/gis/table/gis.group_list.table.json +35 -35
  57. package/module/gis/table/gis.maps.table.json +69 -69
  58. package/module/gis/table/gis.metadata.table.json +70 -70
  59. package/module/gis/table/gis.ogc_service.table.json +91 -91
  60. package/module/gis/table/gis.rasters.table.json +97 -97
  61. package/module/gis/table/gis.registers.table.json +79 -79
  62. package/module/gis/table/gis.services.table.json +99 -99
  63. package/module/gis/table/site.gis.registers.table.json +88 -88
  64. package/module/gis/table/site.gis.services.table.json +106 -106
  65. package/module/gis/templates/ISO19136_2017_gml_template.xml +330 -330
  66. package/module/gis/tokens.yml +5 -5
  67. package/module/test/cls/bp_build_type.json +37 -37
  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/table/data_address.street.table.json +69 -69
  85. package/module/test/table/data_bp_myo.bp.table.json +122 -122
  86. package/package.json +67 -67
  87. package/plugin.js +44 -44
  88. package/server/migrations/ogc.sql +106 -106
  89. package/server/migrations/rasters.sql +263 -263
  90. package/server/migrations/services.sql +247 -247
  91. package/server/migrations/widgets.sql +20 -20
  92. package/server/plugins/crons.js +21 -21
  93. package/server/plugins/mapnik/funcs/createXML.js +72 -72
  94. package/server/plugins/mapnik/funcs/gdalWrapper.js +72 -72
  95. package/server/plugins/mapnik/funcs/map.proto +241 -241
  96. package/server/plugins/mapnik/funcs/mapnik.js +106 -106
  97. package/server/plugins/mapnik/funcs/rasterConfig.js +11 -11
  98. package/server/plugins/mapnik/funcs/rasterExists.js +20 -20
  99. package/server/plugins/mapnik/funcs/rasterInfo.js +109 -109
  100. package/server/plugins/mapnik/funcs/rasterVrt.js +55 -55
  101. package/server/plugins/mapnik/funcs/rasterXML.js +65 -65
  102. package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
  103. package/server/plugins/mapnik/utils/map.proto +241 -241
  104. package/server/plugins/vite.js +74 -74
  105. package/server/routes/gis/index.mjs +59 -59
  106. package/server/routes/gis/metadata/metadataXML.js +13 -13
  107. package/server/routes/gis/ogc/map.info.point.js +124 -124
  108. package/server/routes/gis/registers/add.registry.js +35 -35
  109. package/server/routes/gis/registers/del.registry.js +14 -14
  110. package/server/routes/gis/registers/funcs/classifiers.js +100 -100
  111. package/server/routes/gis/registers/funcs/columns.js +4 -4
  112. package/server/routes/gis/registers/funcs/content.type.js +9 -9
  113. package/server/routes/gis/registers/funcs/get.info.js +89 -89
  114. package/server/routes/gis/registers/funcs/handleRegistryRequest.js +122 -122
  115. package/server/routes/gis/registers/gis.export.js +148 -148
  116. package/server/routes/gis/registers/gis.registry.js +38 -38
  117. package/server/routes/gis/registers/gis.registry.list.js +59 -59
  118. package/server/routes/gis/registers/insert.columns.js +107 -107
  119. package/server/routes/gis/registers/insert.filters.js +110 -110
  120. package/server/routes/gis/registers/map.registry.js +79 -79
  121. package/server/routes/gis/services/add.service.js +64 -64
  122. package/server/routes/gis/services/del.service.js +12 -12
  123. package/server/routes/gis/services/get.layer.geom.js +27 -27
  124. package/server/routes/gis/services/get.services.col.js +33 -33
  125. package/server/routes/gis/services/get.services.js +84 -84
  126. package/server/routes/gis/services/legend.auto.js +77 -77
  127. package/server/routes/map/controllers/layerList.js +60 -60
  128. package/server/routes/map/controllers/map.js +123 -123
  129. package/server/routes/map/controllers/mapCatalog.js +72 -72
  130. package/server/routes/map/controllers/mapCatalogAttribute.js +55 -55
  131. package/server/routes/map/controllers/mapFeatures.js +128 -128
  132. package/server/routes/map/controllers/mapFormat.js +83 -83
  133. package/server/routes/map/controllers/mapTiles.js +152 -152
  134. package/server/routes/map/controllers/maps.js +15 -15
  135. package/server/routes/map/controllers/marker_icon.js +43 -43
  136. package/server/routes/map/controllers/rtile.js +134 -134
  137. package/server/routes/map/controllers/vtile.js +172 -172
  138. package/server/routes/map/index.mjs +86 -86
  139. package/server/routes/map/maps/add.map.js +41 -41
  140. package/server/routes/map/maps/del.map.js +18 -18
  141. package/server/routes/map/maps/get.map.js +88 -88
  142. package/server/routes/map/vtile1.js +170 -170
  143. package/server/routes/map/widgets/add.widget.js +38 -38
  144. package/server/routes/map/widgets/del.widget.js +22 -22
  145. package/server/routes/map/widgets/get.widget.js +40 -40
  146. package/server/routes/root.mjs +3 -3
  147. package/utils.js +11 -11
@@ -1,11 +1,11 @@
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
+ 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 +1,21 @@
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
- }
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
21
  }
@@ -1,109 +1,109 @@
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
+ 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 +1,56 @@
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 };
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
56
  }
@@ -1,65 +1,65 @@
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
- }
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
+ }
@@ -1,8 +1,8 @@
1
- import path from 'node:path';
2
- import { existsSync } from 'node:fs';
3
-
4
- import { config } from '@opengis/fastify-table/utils.js';
5
-
6
- const root = config.temp || (existsSync('/data/local') ? '/data/local/kamianske' : process.cwd());
7
-
8
- export default path.join(root, 'log/map').replace(/\\/g, '/');
1
+ import path from 'node:path';
2
+ import { existsSync } from 'node:fs';
3
+
4
+ import { config } from '@opengis/fastify-table/utils.js';
5
+
6
+ const root = config.temp || (existsSync('/data/local') ? '/data/local/kamianske' : process.cwd());
7
+
8
+ export default path.join(root, 'log/map').replace(/\\/g, '/');