Spatial predicates

st_contains

st_contains(geom1, geom2)

Returns true if geom1 ‘spatially’ contains geom2.

Parameters:
  • geom1 (Column) – Geometry

  • geom2 (Column) – Geometry

Return type:

Column: BooleanType

Example:

df = spark.createDataFrame([{'point': 'POINT (25 15)', 'poly': 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'}])
df.select(st_contains('poly', 'point')).show()
+------------------------+
|st_contains(poly, point)|
+------------------------+
|                    true|
+------------------------+

Note

ST_Within is the inverse of ST_Contains, where ST_Contains(a, b)==ST_Within(b,a).

st_intersects

st_intersects(geom1, geom2)

Returns true if the geometry geom1 intersects geom2. Also, see st_intersects_agg function.

Parameters:
  • geom1 (Column) – Geometry

  • geom2 (Column) – Geometry

Return type:

Column: BooleanType

Example:

df = spark.createDataFrame([{'p1': 'POLYGON ((0 0, 0 3, 3 3, 3 0))', 'p2': 'POLYGON ((2 2, 2 4, 4 4, 4 2))'}])
df.select(st_intersects(col('p1'), col('p2'))).show(1, False)
+---------------------+
|st_intersects(p1, p2)|
+---------------------+
|                 true|
+---------------------+

Note

Intersection logic will be dependent on the chosen geometry API (ESRI or JTS). ESRI is only available for mosaic < 0.4.x series, in mosaic >= 0.4.0 JTS is the only geometry API.

st_within

st_within(geom1, geom2)

Returns true if geom1 ‘spatially’ is within geom2.

Parameters:
  • geom1 (Column) – Geometry

  • geom2 (Column) – Geometry

Return type:

Column: BooleanType

Example:

df = spark.createDataFrame([{'point': 'POINT (25 15)', 'poly': 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'}])
df.select(st_within('point', 'poly')).show()
+----------------------+
|st_within(point, poly)|
+----------------------+
|                  true|
+----------------------+

Note

ST_Within is the inverse of ST_Contains, where ST_Contains(a, b)==ST_Within(b,a).