[postgis-users] Cut lat/lon to six decimal digits

Martin Feuchtwanger feumar at shaw.ca
Tue Apr 16 10:00:57 PDT 2013


If you're really concerned about output format, rather than the actual 
value, consider the *to_char*() function:

select to_char (42.4734992980957, '999D999999')
--> "  42.473499"

where you also get right justification for free.

Martin Feuchtwanger  feumar at shaw.ca  604-254-0361
Vancouver, BC  V5N 1J6
http://members.shaw.ca/geomatics.developer
On 16/04/2013 7:22 AM, Carsten Hogertz wrote:

> Perfect! Thank you guys.
> Carsten
>
> 2013/4/16 Hugues François <hugues.francois at irstea.fr 
> <mailto:hugues.francois at irstea.fr>>
>
>     And what about round(st_y(geom)::numeric, 6) ?
>
>     ------------------------------------------------------------------------
>     *From:* postgis-users-bounces at lists.osgeo.org
>     <mailto:postgis-users-bounces at lists.osgeo.org>
>     [mailto:postgis-users-bounces at lists.osgeo.org
>     <mailto:postgis-users-bounces at lists.osgeo.org>] *On Behalf Of
>     *Carsten Hogertz
>     *Sent:* Tuesday, April 16, 2013 4:05 PM
>     *To:* PostGIS Users Discussion
>     *Subject:* Re: [postgis-users] Cut lat/lon to six decimal digits
>     Thanks.
>     Indead I did. I also tried
>     trunc(ST_Y(geom), 6)
>     But it gives back:
>     Function round(double precision, integer) does not exist
>
>     2013/4/16 Hugues François <hugues.francois at irstea.fr
>     <mailto:hugues.francois at irstea.fr>>
>
>         Did you simply try
>         round(ST_Y(geom), 6) as lat
>         round(ST_X(geom), 6) as lon
>         ------------------------------------------------------------------------
>         *From:* postgis-users-bounces at lists.osgeo.org
>         <mailto:postgis-users-bounces at lists.osgeo.org>
>         [mailto:postgis-users-bounces at lists.osgeo.org
>         <mailto:postgis-users-bounces at lists.osgeo.org>] *On Behalf Of
>         *Carsten Hogertz
>         *Sent:* Tuesday, April 16, 2013 3:51 PM
>         *To:* PostGIS Users Discussion
>         *Subject:* [postgis-users] Cut lat/lon to six decimal digits
>
>         Hi everyone,
>         I've got the following SQL to extract the lat/lon of a polygone:
>         SELECT
>         ROW_NUMBER () over () as id,
>         name,
>         geom,
>         ST_Y(geom) as lat,
>         ST_X(geom) as lon
>         FROM (SELECT name, (ST_DumpPoints(geom)).* FROM
>         timezones20032013) as foo
>         It gives me back the lat and lon as a number with a lot of
>         digits, e.g.:
>         42.4734992980957
>         1.71096694469452
>         Instead what I need is:
>         42.473499
>         1.710967
>         How could I change my SQL to get the result cut/rounded?
>         Any help would be appreciated.
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20130416/42a3d173/attachment.html>


More information about the postgis-users mailing list