ST_GeomFromWKB(binary wkb) 在 Java 语言下使用 Spark 中的翻译为:

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

GEOMETRY ST_GeomFromWKB(binary wkb) on spark using Java Language

问题

我有一个包含Binary列类型的数据框:

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|BinaryGeometry                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|[00 00 00 00 01 03 00 00 00 01 00 00 00 11 00 00 00 04 00 F0 00 DC CC 1A C0 87 14 01 81 1E 1B 41 40 FC FF EF 00 68 AA 1A C0 BF EE 57 20 85 19 41 40 04 00 F0 00 8C 86 1A C0 CC DC 8B DC AE 1A 41 40 FF FF EF 00 44 74 1A C0 CA 9D 5D 61 10 1C 41 40 FF FF EF 00 64 63 1A C0 BF 1F 98 0B 3A 1D 41 40 FF FF EF 00 44 47 1A C0 E4 6B A0 DD CE 1D 41 40 FC FF EF 00 D8 2B 1A C0 54 E4 71 67 6D 1C 41 40 FF FF EF 00 44 1A 1A C0 BF 1F 98 0B 3A 1D 41 40 02 00 F0 00 80 0B 1A C0 0D 80 00 13 2F 23 41 40 02 00 F0 00 B0 35 1A C0 CC F6 23 F8 BD 26 41 40 04 00 F0 00 0C 43 1A C0 73 1A 44 AF 16 26 41 40 02 00 F0 00 40 5A 1A C0 FF 54 9C 7C 2D 27 41 40 02 00 F0 00 50 68 1A C0 87 6E B9 42 44 28 41 40 02 00 F0 00 00 7C 1A C0 78 2B 85 BA F5 26 41 40 FC FF EF 00 18 91 1A C0 49 96 6F 58 C6 28 41 40 02 00 F0 00 B0 BC 1A C0 91 FA 4B 0E 7F 20 41 40 04 00 F0 00 DC CC 1A C0 87 14 01 81 1E 1B 41 40] |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

我想将Well Known Binary (WKB)转换为Geometry。

根据我的研究,ST_GeomFromWKB函数返回一个ST_Geometry值,该值从包含ST_GeometryLONG BINARY值转换而来,该LONG BINARY值包含Well Known Binary (WKB)表示。

我尝试在我的数据框上应用它,但是BinaryGeometry列是一个Binary类型,类似于Array[Byte]

我的问题是:如何从Spark的Binary列获取LONG BINARY值?

我尝试使用hex函数。

df.withColumn("BinaryGeometry", hex(col("BinaryGeometry")))
  .withColumn("BinaryGeometry", expr("ST_GeomFromWKB(BinaryGeometry)"))

我得到以下不正确的输出:

POINT (0 0)

编辑

|-- BinaryGeometry: binary (nullable = true)

参考链接
http://www.h2gis.org/docs/dev/ST_GeomFromWKB/

英文:

I have a dataframe with Binary column type :

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|BinaryGeometry                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|[00 00 00 00 01 03 00 00 00 01 00 00 00 11 00 00 00 04 00 F0 00 DC CC 1A C0 87 14 01 81 1E 1B 41 40 FC FF EF 00 68 AA 1A C0 BF EE 57 20 85 19 41 40 04 00 F0 00 8C 86 1A C0 CC DC 8B DC AE 1A 41 40 FF FF EF 00 44 74 1A C0 CA 9D 5D 61 10 1C 41 40 FF FF EF 00 64 63 1A C0 BF 1F 98 0B 3A 1D 41 40 FF FF EF 00 44 47 1A C0 E4 6B A0 DD CE 1D 41 40 FC FF EF 00 D8 2B 1A C0 54 E4 71 67 6D 1C 41 40 FF FF EF 00 44 1A 1A C0 BF 1F 98 0B 3A 1D 41 40 02 00 F0 00 80 0B 1A C0 0D 80 00 13 2F 23 41 40 02 00 F0 00 B0 35 1A C0 CC F6 23 F8 BD 26 41 40 04 00 F0 00 0C 43 1A C0 73 1A 44 AF 16 26 41 40 02 00 F0 00 40 5A 1A C0 FF 54 9C 7C 2D 27 41 40 02 00 F0 00 50 68 1A C0 87 6E B9 42 44 28 41 40 02 00 F0 00 00 7C 1A C0 78 2B 85 BA F5 26 41 40 FC FF EF 00 18 91 1A C0 49 96 6F 58 C6 28 41 40 02 00 F0 00 B0 BC 1A C0 91 FA 4B 0E 7F 20 41 40 04 00 F0 00 DC CC 1A C0 87 14 01 81 1E 1B 41 40] |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

I want to Convert the Well Known Binary wkb into a Geometry.

From my researsh I found that ST_GeomFromWKB function returns an ST_Geometry value, which is transformed from a LONG BINARY value containing the Well Known Binary (WKB) representation of an ST_Geometry.

I'm trying to apply that on my dataframe , But the BinaryGeometry column is a Binary type like an Array[Byte].

My question is : how to get the LONG BINARY value from Binary column on spark ?

I tried hex function .

df.withColumn("BinaryGeometry",hex(col("BinaryGeometry")))
        .withColumn("BinaryGeometry",expr("ST_GeomFromWKB(BinaryGeometry)"))

I get the following output witch is not correct:

POINT (0 0)

EDIT

|-- BinaryGeometry: binary (nullable = true)

See also
http://www.h2gis.org/docs/dev/ST_GeomFromWKB/

答案1

得分: 1

问题已解决,解决方法如下:

问题出在加载数据库表时,我们必须使用以下代码:

Dataset<Row> df_zones = sparkSession.read().format("jdbc")
    .option("url", "")
    .option("driver", "com.mysql.jdbc.Driver")
    .option("dbtable", "(select ST_AsWKT(geom) as BinaryGeometry from zones) as t")
    .option("user", "root")
    .option("password", "")
    .load();
英文:

I resolved the problem as following :

the problem is in the loading of the database table, we must use the following code:

Dataset &lt;Row&gt; df_zones =        sparkSession.read().format(&quot;jdbc&quot;).option(&quot;url&quot;, &quot;&quot;).option(&quot;driver&quot;, &quot;com.mysql.jdbc.Driver&quot;).option(&quot;dbtable&quot;, &quot;(select ST_AsWKT(geom) as BinaryGeometry  from zones) as t&quot;).option(&quot;user&quot;, &quot;root&quot;).option(&quot;password&quot;, &quot;&quot;).load();

huangapple
  • 本文由 发表于 2020年8月6日 17:20:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63280529.html
匿名

发表评论

匿名网友

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

确定