5. Geospatial Functions : AsTextRound
 
Share this page                  
AsTextRound
ASTEXTROUND(g Geometry [, p integer])
Alias: ST_ASTEXTROUND
Result type: string
Returns g in Well Known Text (WKT) where every number has exactly a precision of p (p digits after the decimal point).
Note:  If p is a large number, such as 200, the server may crash. For example:
SELECT ASTEXTROUND(BUFFER(LINEFROMTEXT('LINESTRING(0 0, 10 10)'), 1), 200);
Examples:
No precision specified:
SELECT ASTEXTROUND(BUFFER(LINEFROMTEXT('LINESTRING(0 0, 10 10)'), 1));
---------------------------------
col1
---------------------------------
POLYGON ((9.2928932188134521 10.7071067811865479, 9.4444297669803987 10.8314696123025467, 9.6173165676349122 10.9238795325112878, 9.804909677983872 10.9807852804032304, 10.0000000000000018 11, 10.1950903220161297 10.9807852804032304, 10.3826834323650896 10.9238795325112861, 10.5555702330196031 10.8314696123025449, 10.7071067811865479 10.7071067811865479, 10.8314696123025449 10.5555702330196031, 10.9238795325112861 10.3826834323650896, 10.9807852804032304 10.1950903220161297, 11 10, 10.9807852804032304 9.804909677983872, 10.9238795325112878 9.6173165676349122, 10.8314696123025467 9.4444297669803987, 10.7071067811865479 9.2928932188134521, 0.7071067811865475 -0.7071067811865475, 0.5555702330196012 -0.8314696123025459, 0.3826834323650888 -0.9238795325112872, 0.1950903220161274 -0.9807852804032307, -0 -1, -0.1950903220161286 -0.9807852804032304, -0.3826834323650899 -0.9238795325112867, -0.555570233019602 -0.8314696123025455, -0.7071067811865475 -0.7071067811865476, -0.8314696123025448 -0.5555702330196028, -0.9238795325112865 -0.3826834323650903, -0.9807852804032302 -0.1950903220161295, -1 -0.000000000000001, -0.9807852804032308 0.1950903220161266, -0.9238795325112873 0.3826834323650884, -0.8314696123025465 0.5555702330196004, -0.7071067811865475 0.7071067811865475, 9.2928932188134521 10.7071067811865479))
----------------------------------
Precision of 0, returning whole numbers:
SELECT ASTEXTROUND(BUFFER(LINEFROMTEXT('LINESTRING(0 0, 10 10)'), 1), 0);
--------------------------------
col1
--------------------------------
POLYGON ((9 11, 9 11, 10 11, 10 11, 10 11, 10 11, 10 11, 11 11, 11 11, 11 11, 11 10, 11 10, 11 10, 11 10, 11 10, 11 9, 11 9, 1 -1, 1 -1, 0 -1, 0 -1, -0 -1, -0 -1, -0 -1, -1 -1, -1 -1, -1 -1, -1 -0, -1 -0, -1 -0, -1 0, -1 0, -1 1, -1 1, 9 11))
---------------------------------
Precision of 5:
SELECT ASTEXTROUND(BUFFER(LINEFROMTEXT('LINESTRING(0 0, 10 10)'), 1), 5);
--------------------------------
col1
--------------------------------
POLYGON ((9.29289 10.70711, 9.44443 10.83147, 9.61732 10.92388, 9.80491 10.98079, 10.00000 11.00000, 10.19509 10.98079, 10.38268 10.92388, 10.55557 10.83147, 10.70711 10.70711, 10.83147 10.55557, 10.92388 10.38268, 10.98079 10.19509, 11.00000 10.00000, 10.98079 9.80491, 10.92388 9.61732, 10.83147 9.44443, 10.70711 9.29289, 0.70711 -0.70711, 0.55557 -0.83147, 0.38268 -0.92388, 0.19509 -0.98079, -0.00000 -1.00000, -0.19509 -0.98079, -0.38268 -0.92388, -0.55557 -0.83147, -0.70711 -0.70711, -0.83147 -0.55557, -0.92388 -0.38268, -0.98079 -0.19509, -1.00000 -0.00000, -0.98079 0.19509, -0.92388 0.38268, -0.83147 0.55557, -0.70711 0.70711, 9.29289 10.70711))
---------------------------------