Skip to content

Implement WKT validation in data-type.ts - #3298

Merged
lixun910 merged 4 commits into
keplergl:masterfrom
bdjulbic:fix/implement-wkr-validation
Feb 5, 2026
Merged

Implement WKT validation in data-type.ts#3298
lixun910 merged 4 commits into
keplergl:masterfrom
bdjulbic:fix/implement-wkr-validation

Conversation

@bdjulbic

@bdjulbic bdjulbic commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Add WKT validation function and regex for geometry types.

Issue:
When geometry is loaded as csv, Kepler map tooltip would show entire value. This PR add a heuristic check to determine if the value is a wkt geometry value

image

Copilot AI review requested due to automatic review settings February 5, 2026 17:55
Add WKT validation function and regex for geometry types.

Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
@bdjulbic
bdjulbic force-pushed the fix/implement-wkr-validation branch from 767678b to 8ef57d2 Compare February 5, 2026 17:57
Removed comments regarding WKT geometry prefixes for clarity.

Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
@bdjulbic
bdjulbic force-pushed the fix/implement-wkr-validation branch from cf4c058 to 492f234 Compare February 5, 2026 17:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements WKT (Well-Known Text) validation to detect geometry fields in CSV data, preventing long geometry strings from appearing in map tooltips. The implementation adds a lightweight heuristic check that identifies WKT-formatted geometry values and marks them as GEOMETRY_FROM_STRING type, similar to the existing WKB (Well-Known Binary) validation.

Changes:

  • Added WKT_PREFIX_RE regex pattern to match standard WKT geometry types (POINT, LINESTRING, POLYGON, etc.) with optional SRID prefix and dimension suffixes
  • Implemented isWkt() validation function with performance optimizations (early returns for non-strings, length checks, and structural validation before regex matching)
  • Integrated WKT validation into getFieldsFromData() to automatically detect WKT geometry columns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/common-utils/src/data-type.ts
Comment thread src/common-utils/src/data-type.ts
Removed comment about structural checks for strings.

Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
@bdjulbic
bdjulbic force-pushed the fix/implement-wkr-validation branch from ab3de85 to 1f65276 Compare February 5, 2026 18:00
Comment thread src/common-utils/src/data-type.ts Outdated
const WKT_PREFIX_RE =
/^(?:SRID=\d+\s*;\s*)?(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(?:Z|M|ZM))?\s*\(/i;

function isWkt(value: unknown): boolean {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am aware that geojson-utils already has a function parseGeometryFromString for converting string to geometry, which technically could be used here, but imo its too performance intensive for this use case

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This check is good and fast enough for WKT.

Signed-off-by: bdjulbic <bdjulbic@foursquare.com>

@lixun910 lixun910 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lixun910
lixun910 merged commit cbb3204 into keplergl:master Feb 5, 2026
7 checks passed
bdjulbic added a commit to bdjulbic/kepler.gl that referenced this pull request Feb 6, 2026
Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
bdjulbic added a commit to bdjulbic/kepler.gl that referenced this pull request Feb 6, 2026
Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
bdjulbic added a commit to bdjulbic/kepler.gl that referenced this pull request Feb 6, 2026
Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants