Give this a shot
Create a view in SQL Server that converts geometry to Well-Known Text before federating:
-- Create view in SQL Server
CREATE VIEW dbo.vw_spatial_converted AS
SELECT
id,
location_name,
location.STAsText() AS geom_wkt,
location.STSrid() AS srid,
location.AsBinaryZM() AS geom_wkb_zm, -- If you need Z/M coordinates
other_columns
FROM dbo.locations;
Then federate the view instead of the base table and convert in Databricks:
# In Databricks (requires DBR 17.1+ for native GEOMETRY support)
from pyspark.sql.functions import expr
df = spark.table("foreign_catalog.sqlserver_db.vw_spatial_converted")
# Convert WKT to native GEOMETRY type
df_spatial = df.withColumn(
"geometry",
expr("ST_GeomFromWKT(geom_wkt, CAST(srid AS INT))")
)
# Now you can use Databricks spatial functions
result = df_spatial.where(
expr("ST_Within(geometry, ST_GeomFromWKT('POLYGON((...))', 4326))")
)