Implement WKT validation in data-type.ts - #3298
Conversation
Add WKT validation function and regex for geometry types. Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
767678b to
8ef57d2
Compare
Removed comments regarding WKT geometry prefixes for clarity. Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
cf4c058 to
492f234
Compare
There was a problem hiding this comment.
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_REregex 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.
Removed comment about structural checks for strings. Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
ab3de85 to
1f65276
Compare
| 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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Agreed. This check is good and fast enough for WKT.
Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
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