ClassNotFoundException geosparksql.UDT.GeometryUDT

ClassNotFoundException geosparksql.UDT.GeometryUDT

我一直在尝试将 GeoPandas 数据框转换为 PySpark 数据框,但没有成功。目前,我已经扩展了 DataFrame class 以使用以下内容将 GPD DF 转换为 Spark DF:

from pyspark.sql import DataFrame
from pyspark.sql.types import IntegerType, StringType, FloatType, BooleanType, DateType, TimestampType, StructField, StructType
!pip install geospark
from geospark.sql.types import GeometryType

class SPandas(DataFrame):
  def __init__(self, sqlC, objgpd):
    esquema = dict(objgpd.dtypes)
    equivalencias = {'int64' : IntegerType, 'object' : StringType, 'float64' : FloatType, 
                     'bool' : BooleanType, 'datetime64' : DateType,
                     'timedelta' : TimestampType, 'geometry' : GeometryType}

    for clave, valor in esquema.items():
      try:
        esquema[clave] = equivalencias[str(valor)]
      except KeyError:
        esquema[clave] = StringType

    esquema = StructType([ StructField(v, esquema[v](), False) for v in esquema.keys() ])
    datos = sqlC.createDataFrame(objgpd, schema=esquema)
    super(self.__class__, self).__init__(datos._jdf, datos.sql_ctx)

前面的代码编译没有错误,但是当尝试 'take' 来自 DataFrame 的项目时,我收到以下错误:

fp = "Paralela/Barrios/Barrios.shp"
map_df = gpd.read_file(fp)
mapa_sp = SPandas(sqlC, map_df)
mapa_sp.take(1)

Py4JJavaError: An error occurred while calling o21.applySchemaToPythonRDD.
: java.lang.ClassNotFoundException: org.apache.spark.sql.geosparksql.UDT.GeometryUDT

问题出在 GDP DF 的 'geometry' 列,因为没有它它也能完美运行。 'geometry' 列具有 Shapely Polygon 对象,应由 GeoSpark 的 GeometryType class 识别。

有什么方法可以安装org.apache.spark.sql.geosparksql.UDT.GeometryUDT吗?我正在使用 Google Colab。

您需要在 hour 项目中包含 geospark 依赖项并将 jar 添加到您的运行时环境中。类路径。以下版本的 jar 与 spark-core_2.11:2.3.0

兼容
<dependency>
    <groupId>org.datasyslab</groupId>
    <artifactId>geospark</artifactId>
    <version>1.3.1</version>
    <scope>provided</scope>
</dependency>