简体   繁体   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

My requirement is to store latitude and longitude coordinates( Double dataType values) fetched from a mobile webservice on java server and store in mySQL db as Geometry or Geometry collection datatype. 我的要求是在Java服务器上存储从移动Web服务获取的纬度和经度坐标( Double dataType值),并以GeometryGeometry collection数据类型存储在mySQL db中。 I've created the table using one of the below queries: 我使用以下查询之一创建了该表:

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

or 要么

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

And in NetBeans inside my project, I've created an entity to store values from webservice to the db. 在项目内部的NetBeans中 ,我创建了一个实体,用于将Web服务中的值存储到数据库中。 And when I've created the entity for the table in my db, the coords column from db is reverse engineered as byte[] in the entity(since the geometry/geometrycollection is a blob in db). 当我在数据库中为表创建了实体时,来自db的coords列在实体中被反向工程为byte[] (因为geometry / geometrycollection是db中的blob )。

From the client device(lets say a mobile), I get the latitude and longitude as Double values from webService to my java server something like: 从客户端设备(让我们说移动设备),我将经度纬度作为Double值从webService到我的java服务器 ,如下所示:

lati:  21.0826801  lng:  80.2707184

Now I need to convert those coordinate values which are Double to byte[ ] , such that it should look like a spatial data that is derived from one of the 3 queries below: 现在,我需要将Double坐标值转换为byte [] ,使其看起来像是从以下3个查询之一派生的空间数据

Query Type 1: 查询类型1:

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

Query Type 2: 查询类型2:

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

Query Type 3: 查询类型3:

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

How could I achieve it? 我该如何实现? Sorry for the long post, I've searched all around the web including stack overflow and found nothing relevant to my current scenario. 抱歉,很长的帖子,我已经搜索了整个网络,包括堆栈溢出 ,但没有发现与我当前的情况有关的内容。

The first and third give you a "point", as seen via 第一个和第三个给你一个“点”,如通过

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)

I see no need for byte[] . 我认为不需要byte[]

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

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