I have some lat/long coordinates eg:
(64.123456789123456, -110.12341234123412)
I store them in the table using a query that looks like this:
INSERT INTO myTable (name, geo) VALUES ('test', ST_GeogFromText('SRID=4326;POINT(-110.12341234123412 64.123456789123456)') );
but when I try to retrieve the lat-long back from the table, they seem to be rounded off, in this case, I get
lat: 64.1234567891234
and
long:-110.123412341234
select ST_X(geo::geometry) as long, ST_Y(geo::geometry) as lat from myTable;
I am probably not using the right data types resulting in loss of values, but haven't been able to figure out.
I am new to PostgreSQL.
How do I not lose the coordinate precision?
Best Answer
You're asking for a lot of precision there.
From my understanding, PostGIS stores coordinates in a double precision float, so a 64 bit floating point data type, and so that's where your precision limit is coming from.
From my testing with Python and Numpy, I tested precision of a 32 and 64 bit floating point and get this result:
So, comparing my number with yours looks like:
For some reason, you're losing two digits, and that may be because you're storing as
geography
and retrieving from a cast togeometry
, but I'm not sure. Regardless, that's just how precise the numbers are in this digital system!