Go to content Go to navigation and search

Home

Current MySQL Spatial Blog Articles

    Spatial Functions for MySQL
    ST_Round for MySQL Spatial
    ST_Scale for MySQL Spatial
    ST_Rotate for MySQL Spatial
    ST_Move for MySQL Spatial

Search

    Browse

RSS / Atom

Email me

textpattern

Creative Commons License
All Blog Articles, Data Models and Free Source Code by Simon Greener, The SpatialDB Advisor is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

ST_Round for MySQL Spatial

Saturday December 23 2017 at 10:20

Keywordsround ordinates coordinates geometry decimal digits precision
Summary

Function to round the X and Y ordinates of a geometry to the supplied number of decimal digits of precision.

A version of my (ordinate) Round function for SQL Server Spatial and Oracle Spatial is available for MySQL.

Function Declaration

  1. DELIMITER $$
  2. CREATE FUNCTION `ST_Round`
  3. (
  4.   p_geometry geometry,
  5.   p_round    INT
  6. )
  7. RETURNS geometry
  8. BEGIN
  9.   -- Processing steps hidden
  10.   RETURN geometry;
  11. END;
  12. DELIMITER ;

Function Testing

  1. -- Point
  2. SELECT ST_AsText(ST_Round(ST_GeomFromText('POINT(100.12223 100.345456)',0),2)) AS rGeom;
  3. -- # rGeom
  4. -- 'POINT(100.12 100.35)'
  5. -- Point
  6. SELECT ST_AsText(ST_Round(ST_GeomFromText('POINT(200.00000000000088 400.00000000000045)',0),2)) AS rGeom;
  7. -- # rGeom
  8. -- 'POINT(200 400)'
  9. -- MultiPoint
  10. SELECT ST_AsText(ST_Round(ST_GeomFromText('MULTIPOINT((100.12223 100.345456),(38832.839 4949.40400))',0),2)) AS rGeom;
  11. -- # rGeom
  12. -- 'MULTIPOINT((100.12 100.12),(38832.84 38832.84))'
  13. -- Linestring
  14. SELECT ST_AsText(ST_Round(ST_GeomFromText('LINESTRING(0.1342 0.2322,1.2324 45.122)',0),2)) AS rGeom;
  15. -- # rGeom
  16. -- 'LINESTRING(0.13 0.13,1.23 1.23)'
  17. -- Polygon
  18. SELECT ST_AsText(
  19.         ST_Round(
  20.           ST_GeomFromText('POLYGON((160 400, 200.00000000000088 400.00000000000045, 200.00000000000088 480.00000000000017, 160 480, 160 400))',0),
  21.           1)) AS rGeom;
  22. -- # rGeom
  23. -- 'POLYGON((160 160,200 200,200 200,160 160,160 160))'
  24. -- MultiPolygon
  25. SELECT ST_AsText(
  26.         ST_Round(
  27.           ST_GeomFromText('MULTIPOLYGON (((160 400, 200.00000000000088 400.00000000000045, 200.00000000000088 480.00000000000017, 160 480, 160 400)), ((100 200, 180.00000000000119 300.0000000000008, 100 300, 100 200)))',0),
  28.           1)) AS rGeom;
  29. -- # rGeom
  30. -- 'MULTIPOLYGON(((160 160,200 200,200 200,160 160,160 160)),((100 100,180 180,100 100,100 100)))'

If you think this is of use to you, make a donation and I will release the code to you along with any other MySQL functions I have created.

Creative Commons License

post this at del.icio.uspost this at Diggpost this at Technoratipost this at Redditpost this at Farkpost this at Yahoo! my webpost this at Windows Livepost this at Google Bookmarkspost this to Twitter

Comment