MySQL Forums
Forum List  »  GIS

Getting aggregate Envelope from a table
Posted by: Chris Ingrassia
Date: May 02, 2006 09:00AM

Forgive me if this has been covered or if I'm missing something blatantly obvious here, but I didn't see anything in the docs or other posts to cover this...

What I want to do is get the Envelope/MBR for a collection of geometries in a table.

Example:
----

CREATE TABLE bunchapoints (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
g GEOMETRY);
INSERT INTO bunchapoints (g) VALUES(GeomFromText('POINT(0 0)'));
INSERT INTO bunchapoints (g) VALUES(GeomFromText('POINT(2 0)'));
INSERT INTO bunchapoints (g) VALUES(GeomFromText('POINT(2 2)'));
INSERT INTO bunchapoints (g) VALUES(GeomFromText('POINT(0 2)'));

I then want to be able to do something like:

SELECT AsText(Envelope(g)) from bunchapoints;

And get back something like:

POLYGON(0 0, 2 0, 2 2, 0 2, 0 0)

but since Envelope() isn't an aggregate function, I end up getting back 1-dimensional polygons for every point in the table.

In this particular example, I can extract the min/max X/Y coordinate values from the points and get what I want, but that doesn't work so well if the geometries are things like polygons. I can manually wrap things in my code or probably though a MySQL function to extract those point values from different types of geometries, but I was hoping for something that worked generically across all types of geometries and wasn't horribly inefficient.

My tables are anywhere from hundreds to hundreds of thousands of geometries, so efficiency is rather important (when isn't it?).

Anyone have any ideas? Am I just going to have to wrap everything in something that extracts point values from every geometry in the table and then gives me back min/max X/Y coords?

Options: ReplyQuote


Subject
Views
Written By
Posted
Getting aggregate Envelope from a table
4436
May 02, 2006 09:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.