<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Spark DataFrame apply Databricks geospatial indexing functions in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/spark-dataframe-apply-databricks-geospatial-indexing-functions/m-p/4333#M1082</link>
    <description>&lt;P&gt;I have a spark DataFrame with `h3` hex ids and I am trying to obtain the polygon geometries.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from pyspark.sql import SparkSession
from pyspark.sql.functions import col, expr
from pyspark.databricks.sql.functions import *
&amp;nbsp;
from mosaic import enable_mosaic
enable_mosaic(spark, dbutils)
&amp;nbsp;
&amp;nbsp;
# Create a Spark session
spark = SparkSession.builder.appName("Mosaic").getOrCreate()
&amp;nbsp;
# Create a DataFrame with hex IDs
df = spark.createDataFrame([
    (1, "87422c2a9ffffff"),
    (2, "87422c2a9000000"),
    (3, "87422c2a8ffffff")
], ("id", "h3hex_id"))
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;
sdf2 = sdf1.withColumn("geometry", h3_boundaryaswkt(col("h3hex_id")))
sdf2.sample(fraction=0.1).show()
&amp;nbsp;
AnalysisException: [H3_NOT_ENABLED] h3_boundaryaswkt is disabled or unsupported. Consider enabling Photon or switch to a tier that supports H3 expressions; 
&amp;nbsp;
&amp;nbsp;
sdf2 = sdf1.withColumn("geometry", grid_boundary(col("h3hex_id"), format_name="WKT"))
sdf2.sample(fraction=0.1).show()
&amp;nbsp;
&amp;nbsp;
AnalysisException: [UNRESOLVED_COLUMN.WITH_SUGGESTION] A column or function parameter with name `WKT` cannot be resolved. Did you mean one of the following? ..&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have installed `databricks-mosaic 0.3.10` on the cluster.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I resolve the exception and apply the function spark DataFrame?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;https://databrickslabs.github.io/mosaic/api/spatial-indexing.html &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.databricks.com/sql/language-manual/functions/h3_boundaryaswkt.html#examples" target="test_blank"&gt;https://docs.databricks.com/sql/language-manual/functions/h3_boundaryaswkt.html#examples&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 15 May 2023 21:13:01 GMT</pubDate>
    <dc:creator>kll</dc:creator>
    <dc:date>2023-05-15T21:13:01Z</dc:date>
    <item>
      <title>Spark DataFrame apply Databricks geospatial indexing functions</title>
      <link>https://community.databricks.com/t5/data-engineering/spark-dataframe-apply-databricks-geospatial-indexing-functions/m-p/4333#M1082</link>
      <description>&lt;P&gt;I have a spark DataFrame with `h3` hex ids and I am trying to obtain the polygon geometries.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from pyspark.sql import SparkSession
from pyspark.sql.functions import col, expr
from pyspark.databricks.sql.functions import *
&amp;nbsp;
from mosaic import enable_mosaic
enable_mosaic(spark, dbutils)
&amp;nbsp;
&amp;nbsp;
# Create a Spark session
spark = SparkSession.builder.appName("Mosaic").getOrCreate()
&amp;nbsp;
# Create a DataFrame with hex IDs
df = spark.createDataFrame([
    (1, "87422c2a9ffffff"),
    (2, "87422c2a9000000"),
    (3, "87422c2a8ffffff")
], ("id", "h3hex_id"))
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;
sdf2 = sdf1.withColumn("geometry", h3_boundaryaswkt(col("h3hex_id")))
sdf2.sample(fraction=0.1).show()
&amp;nbsp;
AnalysisException: [H3_NOT_ENABLED] h3_boundaryaswkt is disabled or unsupported. Consider enabling Photon or switch to a tier that supports H3 expressions; 
&amp;nbsp;
&amp;nbsp;
sdf2 = sdf1.withColumn("geometry", grid_boundary(col("h3hex_id"), format_name="WKT"))
sdf2.sample(fraction=0.1).show()
&amp;nbsp;
&amp;nbsp;
AnalysisException: [UNRESOLVED_COLUMN.WITH_SUGGESTION] A column or function parameter with name `WKT` cannot be resolved. Did you mean one of the following? ..&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have installed `databricks-mosaic 0.3.10` on the cluster.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I resolve the exception and apply the function spark DataFrame?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;https://databrickslabs.github.io/mosaic/api/spatial-indexing.html &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.databricks.com/sql/language-manual/functions/h3_boundaryaswkt.html#examples" target="test_blank"&gt;https://docs.databricks.com/sql/language-manual/functions/h3_boundaryaswkt.html#examples&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 21:13:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/spark-dataframe-apply-databricks-geospatial-indexing-functions/m-p/4333#M1082</guid>
      <dc:creator>kll</dc:creator>
      <dc:date>2023-05-15T21:13:01Z</dc:date>
    </item>
  </channel>
</rss>

