ST_WITHIN 使用 Spark/Java (ST_WITHIN using Spark / Java)


問題描述

ST_WITHIN 使用 Spark/Java (ST_WITHIN using Spark / Java)

我有以下數據框:

+‑‑‑‑‑‑‑‑‑‑‑‑‑+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+
|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

有什麼想法嗎?我需要你的幫助

謝謝


參考解法

方法 1:

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

  • </ul>

    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();
    

    (by HBoulmidumitru)

    參考文件

    1. ST_WITHIN using Spark / Java (CC BY‑SA 2.5/3.0/4.0)

#java #apache-spark #geospark






相關問題

電子郵件地址中帶有 + 字符的 Java 郵件 (Java mail with + character in email address)

如何快速原型化 Java 代碼? (How to quickly prototype Java code?)

如何使用 Maven 在目標(SVN-)服務器上創建 Javadoc? (How to create Javadoc on the target (SVN-) server using Maven?)

為什麼檢查二叉樹有效性的解決方案不起作用? (Why the solution for checking the validity of binary tree is not working?)

Selenium webdriver通過第一個數字找到texy (Selenium webdriver find texy by first digits)

setOnClickListener 沒有在圖像視圖上被調用 (setOnClickListener is not getting called on image view)

繪製多邊形:找不到錯誤 (Drawing Polygon : unable to find error)

半透明 JButton:對像出現在背景中 (Semi-Transparent JButton: Objects appear in Background)

比較同一數組的元素 (Compare elements of the same array)

Java 屏幕截圖小程序 (Java screen capture applet)

Minecraft 1.8.9 Forge Modding 的Java 開發工具包,需要什麼JDK/JRE,代碼是否正確? (Java Development Kit with Minecraft 1.8.9 Forge Modding, What JDK/JRE Is Needed, Is Code Correct?)

java while (resultset.next()) 不返回同一列中的所有數據 (java while (resultset.next()) does not return all data in the same column)







留言討論