within

6yt4nkrj  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(287)

我有以下Dataframe:

+-------------+-----------------+------------------+
|longitude    |latitude         |geom              |
+-------------+-----------------+------------------+
|-7.07378166  |33.826661        [00 00 00 00 01 0..|
|-7.5952683   |33.544191        [00 00 00 00 01 0..|                  
+-------------+-----------------+------------------+

我使用以下代码:

Dataset<Row> result_f = sparkSession.sql("select * from data_f where  ST_WITHIN(ST_GeomFromText(CONCAT('POINT(',longitude_f,' ',latitude_f,')',4326)),geom)");
result_f.show();

但我得到以下错误:

java.lang.ClassCastException: [B cannot be cast to org.apache.spark.sql.catalyst.util.ArrayData
at org.apache.spark.sql.geosparksql.expressions.ST_Within.eval(Predicates.scala:105)

编辑

longitude : Double type
latitude  : Double type
geom      : Binary type

你知道吗?我需要你的帮助
谢谢您

3gtaxfhh

3gtaxfhh1#

我不认为stu geomfromtext可以从文本构造几何体,但是有:
圣彼得堡
圣彼得堡
圣乔治
斯图角
st\u pointfromtext公司
st\ u polygonfromtext公司
stu linestringfromtext从文本
st\ u PolygonFrom信封
stïu圆
我建议两者都用 ST_Point 或者 ST_PointFromText 然后是 predicate ST_WITHIN 像这样:

Dataset<Row> result_f = sparkSession.sql("select * from data_f where  ST_WITHIN(ST_Point(CAST(data_f.latitude AS Decimal(24,20)), CAST(data_f.longitude AS Decimal(24,20))),geom)");
result_f.show();

相关问题