Postgis-如何通过JDBC处理数据类型“地理" [英] Postgis - How to work with data type 'geography' via 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.
问题是:
- 在java pojo模型类中,该列应使用哪种Java数据类型?
- 如何编写插入sql?
- 如何编写select sql以检索值并将其放入Java对象?
- 如果使用
mybatis
,那么是否会回答上述问题?
- In java pojo model class, what Java data type should be used for the column?
- How to write the insert sql?
- How to write the select sql to retrieve the value and put into Java object?
- 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.
例如,要通过lon
和lat
参数插入新的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屋!