ST_WITHIN 在 Spark / Java 中的使用

huangapple go评论109阅读模式
英文:

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 = 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.

英文:

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_PointST_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&lt;Row&gt; result_f = sparkSession.sql(&quot;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)&quot;);
result_f.show();

huangapple
  • 本文由 发表于 2020年7月23日 00:19:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/63038764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定