繁体   English   中英

将纬度和经度(double)数据转换为字节数组,以便在java中以Geometry或GeometryCollection值存储在mySql中

[英]Converting Latitude and Longitude(double) data to byte array in order to store in mySql as Geometry or GeometryCollection value in java

我的要求是在Java服务器上存储从移动Web服务获取的纬度和经度坐标( Double dataType值),并以GeometryGeometry collection数据类型存储在mySQL db中。 我使用以下查询之一创建了该表:

CREATE TABLE `mydb`.`location`(    
`coords` GEOMETRYCOLLECTION);

要么

CREATE TABLE `mydb`.`location`(
`coords` GEOMETRY);

在项目内部的NetBeans中 ,我创建了一个实体,用于将Web服务中的值存储到数据库中。 当我在数据库中为表创建了实体时,来自db的coords列在实体中被反向工程为byte[] (因为geometry / geometrycollection是db中的blob )。

从客户端设备(让我们说移动设备),我将经度纬度作为Double值从webService到我的java服务器 ,如下所示:

lati:  21.0826801  lng:  80.2707184

现在,我需要将Double坐标值转换为byte [] ,使其看起来像是从以下3个查询之一派生的空间数据

查询类型1:

INSERT INTO location VALUES (geomfromwkb(point(9.197915773, 45.476819539)));

查询类型2:

INSERT INTO location VALUES (geometrycollection(point(9.197915773, 45.476819539)));

查询类型3:

INSERT INTO location VALUES (geomcollfromwkb(point(9.197915773, 45.476819539)));

我该如何实现? 抱歉,很长的帖子,我已经搜索了整个网络,包括堆栈溢出 ,但没有发现与我当前的情况有关的内容。

第一个和第三个给你一个“点”,如通过

mysql> select ASTEXT(geomfromwkb(point(9.197915773, 45.476819539)));
+-------------------------------------------------------+
| ASTEXT(geomfromwkb(point(9.197915773, 45.476819539))) |
+-------------------------------------------------------+
| POINT(9.197915773 45.476819539)                       |
+-------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select ASTEXT(geometrycollection(point(9.197915773, 45.476819539)));
+--------------------------------------------------------------+
| ASTEXT(geometrycollection(point(9.197915773, 45.476819539))) |
+--------------------------------------------------------------+
| GEOMETRYCOLLECTION(POINT(9.197915773 45.476819539))          |
+--------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select ASTEXT(geomcollfromwkb(point(9.197915773, 45.476819539)));
+-----------------------------------------------------------+
| ASTEXT(geomcollfromwkb(point(9.197915773, 45.476819539))) |
+-----------------------------------------------------------+
| POINT(9.197915773 45.476819539)                           |
+-----------------------------------------------------------+
1 row in set (0.01 sec)

我认为不需要byte[]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM