Skip to content

Commit ec1357c

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix/truncate-map-tooltips
# Conflicts: # test/node/utils/dataset-utils-test.js
2 parents 14ea63d + cbb3204 commit ec1357c

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/common-utils/src/data-type.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ import {h3IsValid} from './h3-utils';
1111

1212
const H3_ANALYZER_TYPE = 'H3';
1313

14+
// Returns true if the value is likely a WKT geometry string (heuristic check).
15+
const WKT_PREFIX_RE =
16+
/^(?:SRID=\d+\s*;\s*)?(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(?:Z|M|ZM))?\s*\(/i;
17+
18+
export function isWkt(value: unknown): boolean {
19+
if (typeof value !== 'string') {
20+
return false;
21+
}
22+
23+
const s = value.trim();
24+
if (s.length < 10) {
25+
return false;
26+
}
27+
28+
if (!s.includes('(') || !s.includes(')')) {
29+
return false;
30+
}
31+
32+
return WKT_PREFIX_RE.test(s);
33+
}
34+
1435
export const ACCEPTED_ANALYZER_TYPES = [
1536
AnalyzerDATA_TYPES.DATE,
1637
AnalyzerDATA_TYPES.TIME,
@@ -267,6 +288,11 @@ export function getFieldsFromData(data: RowData, fieldOrder: string[]): Field[]
267288
type = data.some(d => isHexWkb(d[name])) ? AnalyzerDATA_TYPES.GEOMETRY : type;
268289
}
269290

291+
// quick check if string is wkt
292+
if (type === AnalyzerDATA_TYPES.STRING) {
293+
type = data.some(d => isWkt(d[name])) ? AnalyzerDATA_TYPES.GEOMETRY_FROM_STRING : type;
294+
}
295+
270296
return {
271297
name,
272298
id: name,

0 commit comments

Comments
 (0)