Postgis-如何通过JDBC处理数据类型“地理" [英] Postgis - How to work with data type 'geography' via JDBC

查看:742
本文介绍了Postgis-如何通过JDBC处理数据类型“地理"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在处理使用postgresql 9.3 postgis 2.1的Web项目.

Working on a web project, which uses postgresql 9.3 postgis 2.1.

表中有一列类型为geography的列,它只存储一个point.

There is a column of type geography in the table, it just store a point.

现在,我需要使用Java对象通过JDBC插入/选择类型.

Now I need to insert / select the type via JDBC with Java object.

在阅读postgis手册后,没有发现太多相关信息.

After reading postgis manual, didn't find much information relevant.

问题是:

  1. 在java pojo模型类中,该列应使用哪种Java数据类型?
  2. 如何编写插入sql?
  3. 如何编写select sql以检索值并将其放入Java对象?
  4. 如果使用mybatis,那么是否会回答上述问题?
  1. In java pojo model class, what Java data type should be used for the column?
  2. How to write the insert sql?
  3. How to write the select sql to retrieve the value and put into Java object?
  4. If mybatis is used, then does it effect answers to above questions?

推荐答案

对于POINT几何,您不需要特殊的类型.只需使用double之类的原始数据类型作为坐标即可.

You don't need special types for POINT geometries. Just use primitive data types like double for the coordinates.

例如,要通过lonlat参数插入新的geography类型,请使用几何构造函数:

E.g., to insert a new geography type via lon and lat parameters, use geometry constructor functions:

INSERT INTO my_table (geog)
VALUES (ST_SetSRID(ST_MakePoint(:lon, :lat), 4326)::geography);

或将它们作为浮点数取回,请使用几何访问器函数:

Or get them back as floating point numbers, use geometry accessor functions:

SELECT ST_Y(geog::geometry) AS lat, ST_X(geog::geometry) AS lon FROM my_table;

还有其他输入/输出格式,例如GeoJSON,WKT等.

There are other input/output formats, like GeoJSON, WKT, etc.

这篇关于Postgis-如何通过JDBC处理数据类型“地理"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆