英文:
ST_WITHIN using Spark / Java
问题
I have the following dataframe:
+-------------+-----------------+------------------+
|longitude |latitude |geom |
+-------------+-----------------+------------------+
|-7.07378166 |33.826661 [00 00 00 00 01 0..|
|-7.5952683 |33.544191 [00 00 00 00 01 0..|
+-------------+-----------------+------------------+
I'm using the following code:
Dataset
result_f.show();
But I get the following error:
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)
EDIT:
longitude: Double type
latitude: Double type
geom: Binary type
Any idea? I need your help.
Thank you.
英文:
I have the following dataframe :
+-------------+-----------------+------------------+
|longitude |latitude |geom |
+-------------+-----------------+------------------+
|-7.07378166 |33.826661 [00 00 00 00 01 0..|
|-7.5952683 |33.544191 [00 00 00 00 01 0..|
+-------------+-----------------+------------------+
I'm using the following code :
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();
But I get the following error :
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)
EDIT
longitude : Double type
latitude : Double type
geom : Binary type
Any idea ? I need your help
Thank you
答案1
得分: 2
我不认为ST_GeomFromText可以用于从文本构建几何对象,但可以使用以下函数:
- ST_GeomFromWKT
- ST_GeomFromWKB
- ST_GeomFromGeoJSON
- ST_Point
- ST_PointFromText
- ST_PolygonFromText
- ST_LineStringFromText
- ST_PolygonFromEnvelope
- ST_Circle
我建议使用ST_Point
或ST_PointFromText
,然后使用谓词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();
英文:
I don't think ST_GeomFromText is availble as constructing a geometry from text however there are:
- ST_GeomFromWKT
- ST_GeomFromWKB
- ST_GeomFromGeoJSON
- ST_Point
- ST_PointFromText
- ST_PolygonFromText
- ST_LineStringFromText
- ST_PolygonFromEnvelope
- ST_Circle
I suggest to use either ST_Point
or ST_PointFromText
and after that the predicate ST_WITHIN
Something like this:
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();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论