MySQL spatial functions on MaisonBissonhttps://maisonbisson.com/tags/mysql-spatial-functions/Recent content in MySQL spatial functions on MaisonBissonHugo -- gohugo.ioen-usFri, 13 Jun 2008 19:34:31 +0000Find Stuff By Minimum Bounding Rectanglehttps://maisonbisson.com/post/find-stuff-by-minimum-bounding-rectangle/Fri, 13 Jun 2008 19:34:31 +0000https://maisonbisson.com/post/find-stuff-by-minimum-bounding-rectangle/MySQL offers ENVELOPE() to find the minimum bounding rectangle of a geometric object.
The result is a polygon with four segments, defined by five points. It took me a while to make sense of it, partially because the only documentation that I’ve run across so far for POLYGON() syntax is in the ENVELOPE() function mentioned above. I also had to draw a picture to think it through.
They write this: POLYGON(( MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY )), I think this (in pseudocode-ish form): POLYGON(( $point_a, $point_b, $point_c, $point_d, $point_a )), with the $point_s corresponding to the diagram.Working With Spatial Data in MySQLhttps://maisonbisson.com/post/working-with-spatial-data-in-mysql/Thu, 12 Jun 2008 16:41:45 +0000https://maisonbisson.com/post/working-with-spatial-data-in-mysql/It’s MySQL spatial data week here, though I am spreading out the posts to, um, ease the pain (or boredom). Anyway, here are some commands/functions I don’t want to forget about later:
Start with an existing table called geometry, add a spatial column and index it:
``` ALTER TABLE geometry ADD coord POINT NOT NULL; CREATE SPATIAL INDEX coord ON geometry (coord); ``` Insert some data; think in terms of POINT(X Y) or POINT(lat lon):Calculating Distance Between Points In MySQLhttps://maisonbisson.com/post/calculating-distance-between-points-in-mysql/Wed, 11 Jun 2008 02:15:57 +0000https://maisonbisson.com/post/calculating-distance-between-points-in-mysql/MySQL has some powerful, and perhaps underused spatial extensions, but the most interesting functions are still unimplemented: “Note: Currently, MySQL does not implement these functions…”
Among those as-yet unimplemented functions is DISTANCE(). Alternatives can be found here and here, though neither is clean or simple. I wonder if a simple MBRContains() is good enough, though…MySQL Documentationhttps://maisonbisson.com/post/mysql-documentation/Mon, 09 Jun 2008 01:44:03 +0000https://maisonbisson.com/post/mysql-documentation/Found in the MySQL 5.0 Reference Manual:
Related(g1,g2,pattern_matrix)
Returns 1 or 0 to indicate whether the spatial relationship specified by pattern_matrix exists between g1 and g2. Returns –1 if the arguments are NULL. The pattern matrix is a string. Its specification will be noted here if this function is implemented.
(emphasis mine.)