ST_Within takes two geometry columns and returns a boolean column. The function returns True
if the first geometry
is completely inside the second geometry; otherwise, it returns False
.
Function | Syntax |
---|---|
Python | within(geometry1, geometry2) |
SQL | ST |
Scala | within(geometry1, geometry2) |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for within.
This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.
Examples
from geoanalytics_fabric.sql import functions as ST
data = [
("POLYGON ((0 0, 0 10, 10 10, 10 0))", "LINESTRING (2 2, 4 4)" ),
("POLYGON ((0 0, 0 10, 10 10, 10 0))", "LINESTRING (0 10, 5 15, 10 20)")
]
df = spark.createDataFrame(data, ["poly_wkt", "line_wkt"])\
.withColumn("linestring", ST.line_from_text("line_wkt"))\
.withColumn("polygon", ST.poly_from_text("poly_wkt"))\
.withColumn("within", ST.within("linestring", "polygon"))\
.drop("poly_wkt", "line_wkt")
df.show(truncate=False)
Result
+-----------------------------------+-----------------------------------------------+------+
|linestring |polygon |within|
+-----------------------------------+-----------------------------------------------+------+
|{"paths":[[[2,2],[4,4]]]} |{"rings":[[[0,0],[0,10],[10,10],[10,0],[0,0]]]}|true |
|{"paths":[[[0,10],[5,15],[10,20]]]}|{"rings":[[[0,0],[0,10],[10,10],[10,0],[0,0]]]}|false |
+-----------------------------------+-----------------------------------------------+------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |