@opengis/gis 0.2.103 → 0.2.104

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/gis",
3
- "version": "0.2.103",
3
+ "version": "0.2.104",
4
4
  "type": "module",
5
5
  "author": "Softpro",
6
6
  "main": "./dist/index.js",
@@ -18,7 +18,7 @@ export default async function checkCarto({
18
18
  }
19
19
 
20
20
  // extract all columns, migrations-agnostic
21
- const cartocss = await pg.query('select *, ARRAY[ST_XMin(geom), ST_YMin(geom), ST_XMax(geom), ST_YMax(geom)] as bounds, st_asgeojson(geom)::json as geom from gis.cartocss where cartocss_id=$1', [params.id]).then(el => el.rows?.[0]);
21
+ const cartocss = await pg.query('select *, ARRAY[ST_XMin(geom), ST_YMin(geom), ST_XMax(geom), ST_YMax(geom)] as bounds, st_asgeojson(geom)::json as geom, source_path from gis.cartocss where cartocss_id=$1', [params.id]).then(el => el.rows?.[0]);
22
22
 
23
23
  if (!cartocss) {
24
24
  return reply.status(404).send({ error: `cartocss not found: ${params.id}`, code: 404 });
@@ -28,14 +28,15 @@ export default async function checkCarto({
28
28
  Object.keys(cartocss).filter(key => exclude.includes(key)).forEach(key => delete cartocss[key]);
29
29
 
30
30
  const rtile = await RenderTile({
31
- name: params.id,
31
+ name: cartocss.source_path ? `vector/${cartocss.source_path}` : params.id, // required for cartocss
32
32
  width: 256,
33
33
  bbox: [3713463.7081504324, 6088362.176970857, 3713616.5822070027, 6088515.051027427],
34
34
  ttl: '0',
35
35
  // debug: query.debug,
36
36
  }).catch(err => ({ err: err.toString() }));
37
37
 
38
- const bounds = cartocss.bounds || await cartoBounds({ id: params.id, dataset: cartocss.config }, pg);
38
+ // skip empty bounds[null,null,null,null]
39
+ const bounds = cartocss.bounds && cartocss.geom ? cartocss.bounds : await cartoBounds({ id: params.id, dataset: cartocss.config, table: cartocss.card_table }, pg);
39
40
 
40
41
  return {
41
42
  time: Date.now() - time,
@@ -1,12 +1,17 @@
1
1
  import { pgClients } from "@opengis/fastify-table/utils.js";
2
2
 
3
- export default async function cartoBounds({ id, dataset }, pg = pgClients.client) {
4
- const sqlBounds = dataset.map(el => ({ tbl: el.table.replace(/"/g, "").split('.'), geom: el.gcol || 'geom' })).map(({ tbl, geom }) => `select ST_EstimatedExtent('${tbl[0]}','${tbl[1]}', '${geom}')`);
5
- // const sqlBounds = dataset.map(el => ({ srid: el.srid || 4326, tbl: el.table.split('.'), geom: el.gcol || 'geom' })).map(({ tbl, geom, srid }) => `select st_transform(st_setsrid(ST_EstimatedExtent('${tbl[0]}','${tbl[1]}', '${geom}'),${srid}),4326) as st_estimatedextent`);
3
+ export default async function cartoBounds({ id, dataset, table }, pg = pgClients.client) {
4
+ if (!dataset?.length && !table) {
5
+ return [-180, -85.05112877980659, 180, 85.05112877980659];
6
+ }
7
+
8
+ const sqlBounds = dataset
9
+ ? dataset.map(el => ({ tbl: el.table.replace(/"/g, "").split('.'), geom: el.gcol || 'geom' })).map(({ tbl, geom }) => `select ST_Transform(ST_SetSRID( ST_EstimatedExtent('${tbl[0]}','${tbl[1]}', '${geom}'), (SELECT st_srid(${geom}) from ${tbl.join('.')} limit 1)),4326)`)
10
+ : [`select ST_Transform(ST_SetSRID(ST_EstimatedExtent('${table.split('.')[0]}', '${table.split('.')[1]}', 'geom'),(SELECT st_srid(geom) from ${table} limit 1)),4326)`];
6
11
 
7
12
  const geom = await pg.query(
8
13
  `update gis.cartocss set
9
- geom=(select st_extent(st_estimatedextent) from ( ${sqlBounds.join(' union all ')})q )
14
+ geom=(select st_extent(st_transform) from ( ${sqlBounds.join(' union all ')})q )
10
15
  where cartocss_id=$1 returning geom::box2d`,
11
16
  [id],
12
17
  ).then(e => e.rows?.[0]?.geom);