Working on a web project, which uses postgresql 9.3 postgis 2.1.
There is a column of type geography in the table, it just store a point.
Now I need to insert / select the type via JDBC with Java object.
After reading postgis manual, didn't find much information relevant.
The questions are:
mybatis is used, then does it effect answers to above questions?You don't need special types for POINT geometries. Just use primitive data types like double for the coordinates.
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;
There are other input/output formats, like GeoJSON, WKT, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With