ST_Translate takes a geometry column and two numbers and returns a geometry column. The result is the input geometry translated in the x and y directions by the specified offsets.
Function | Syntax |
---|---|
Python | translate(geometry, x |
SQL | ST |
Scala | translate(geometry, x |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for translate.
Python and SQL Examples
from geoanalytics_fabric.sql import functions as ST
data = [
("POINT (-117.05 34.22)",),
("MULTIPOINT (-117.55 34.33, -117.66 34.44, -117.66 34.22)",),
("LINESTRING (-116.89 33.96, -116.71 34.01, -116.66 34.08)", ),
("POLYGON ((-117.27 34.05, -117.22 33.91, -116.96 33.64, -116.66 33.71, -117.08 33.91, -117.16 34.09, -117.27 34.05))", )
]
df = spark.createDataFrame(data, ["wkt"]) \
.withColumn("geometry", ST.geom_from_text("wkt", srid=4326))
df_translate = df.withColumn("translate", ST.translate("geometry", x_offset=2, y_offset=-1))
ax = df_translate.st.plot("geometry", facecolor="none", edgecolor="red", figsize=(15, 8))
df_translate.st.plot("translate", ax=ax, facecolor="none", edgecolor="blue")
Scala Example
Scala
import com.esri.geoanalytics.sql.{functions => ST}
import org.apache.spark.sql.{functions => F}
case class GeometryRow(wkt: String)
val data = Seq(GeometryRow("POINT (-117.05 34.22)"),
GeometryRow("MULTIPOINT (-117.55 34.33, -117.66 34.44, -117.66 34.22)"),
GeometryRow("LINESTRING (-116.89 33.96, -116.71 34.01, -116.66 34.08)"),
GeometryRow("POLYGON ((-117.27 34.05, -117.22 33.91, -116.96 33.64, -116.66 33.71, -117.08 33.91, -117.16 34.09, -117.27 34.05))"))
val df = spark.createDataFrame(data)
.withColumn("geometry", ST.geomFromText($"wkt", F.lit(4326)))
.withColumn("translate", ST.translate($"geometry", 2, -1))
df.select("translate").show(truncate = false)
Result
+-----------------------------------------------------------------------------------------------------------------------------+
|translate |
+-----------------------------------------------------------------------------------------------------------------------------+
|{"x":-115.05,"y":33.22} |
|{"points":[[-115.55,33.33],[-115.66,33.44],[-115.66,33.22]]} |
|{"paths":[[[-114.89,32.96],[-114.71,33.01],[-114.66,33.08]]]} |
|{"rings":[[[-115.27,33.05],[-115.16,33.09],[-115.08,32.91],[-114.66,32.71],[-114.96,32.64],[-115.22,32.91],[-115.27,33.05]]]}|
+-----------------------------------------------------------------------------------------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |