How to handle , Error parsing WKT: Invalid coordinate value '180' found at position

swapnilmd
New Contributor II

DBR Version- 16.2
spark.databricks.geo.st.enabled true

SQL Query I am running:

 

 

%sql
WITH points (
    SELECT st_astext(st_point(30D, 10D)) AS point_geom
    UNION SELECT st_astext(st_point(10D, 90D)) AS point_geom
    UNION SELECT st_astext(st_point(40D, 40D)) AS point_geom)
SELECT st_geoglength(st_astext(st_makeline(collect_list(st_geomfromtext(point_geom)))))
FROM points

 

 


Full Error :
[WKT_PARSE_ERROR] Error parsing WKT: Invalid coordinate value '90' found at position 21 SQLSTATE: 22023


How to handle this error, how can I make this geometry compatible with databricks' st_* functions?
Note: st_isvalid is true for above geometry

swapnilmd
New Contributor II

Also ,other geospatial libraries like apache sedona, supports these geometries.

mark_ott
Databricks Employee
Databricks Employee

The error occurs because Databricks (based on GEOS/OGC standards) expects coordinates in Well-Known Text (WKT) that fall into valid ranges:

  • Longitude (X or first coordinate): −180≤X≤180

  • Latitude (Y or second coordinate): −90≤Y≤90

Your SQL includes:
st_point(10D, 90D)
Here, 90 is valid for latitude, but if you ever used a value above 90 it would trigger a WKT parse error, commonly seen with "Invalid coordinate value" errors in Databricks geospatial functions.

Key Points

  • Latitude must never exceed ±90.

  • Longitude must never exceed ±180.

How To Fix

  • Double-check your coordinate values in st_point(x, y) calls.

  • Make sure the y (second) value is not greater than 90 nor less than −90.

  • If your input is correct, ensure you are not accidentally swapping longitude/latitude order.

Sample Correction

If you originally wrote:

sql
SELECT st_astext(st_point(10D, 90D)) AS point_geom

This is valid because 90 is within allowed latitude. If you wrote 91 or higher, that would fail. If your error persists, make sure:

  • Your actual input values are not outside the range.

  • You're not using 90 or -90 as longitude (first value).

Example Full Query Correction

sql
WITH points AS ( SELECT st_astext(st_point(30D, 10D)) AS point_geom UNION SELECT st_astext(st_point(10D, 90D)) AS point_geom UNION SELECT st_astext(st_point(40D, 40D)) AS point_geom ) SELECT st_geoglength(st_astext(st_makeline(collect_list(st_geomfromtext(point_geom)))) FROM points

This query should work if all coordinate values are within range. If it does not, double-check for typos or data issues (like using degree symbols, non-decimal values, or non-numeric strings).

Additional Guidance

  • Use ST_IsValid() only checks general validity, not coordinate domain. It won't catch domain errors for WKT parsing. Always validate ranges.

  • If parsing from external data, preprocess to check for invalid coordinates before using them in SQL.

  • Refer to Databricks ST_* function docs for expected ranges.

For more troubleshooting, paste your exact raw input and check for invisible characters, decimals/commas, or try running each point individually to isolate the bad value.


Summary:
Ensure all coordinates are inside valid latitude (±90) and longitude (±180) domains. Correct any values outside this range, as WKT parsing in Databricks will fail otherwise.