[Georuby-devel] Aggregate Envelopes in MySQL
Chris Ingrassia
Chris.Ingrassia at fortiusone.com
Thu May 18 11:00:57 EDT 2006
I think I've mentioned this before, but I was looking for a way to
get an aggregate Envelope for a collection of geometries from a MySQL
table. I haven't really had any luck finding a built-in way to do
that, but it was holding me up with something I needed to get done,
so I came up with a way to hack it, although I think it's really ugly.
Basically you have to extract the points from the exterior ring of
the polygon envelope geometries returned from MySQL and do MIN([X|Y)
(...)) on them.
Here's a snippet from one of my models with an example ('geometry'
is the name of the relevant geometry column):
def minx
calculate(:min, :all, :select => 'X(StartPoint(ExteriorRing
(Envelope(geometry))))').to_f
end
def maxy
calculate(:max, :all, :select => 'Y(PointN(ExteriorRing(Envelope
(geometry)), 3))').to_f
end
I find that solution to be really, really ugly, but I don't think I'm
going to do much better. I end up combining the min/max x and y
values into a polygon later on.
I was hoping that somebody out there might see that and might see
something that I didn't and be able to point out a better way of
doing this so I wouldn't be afraid to look at my code next week, but
I'm not holding my breath :)
Couple questions:
1. If anybody has a PostGIS database handy, can you confirm for me
that it behaves differently, and that when you do something like:
SELECT Extent(the_geom) from some_spatial_table;
it returns a single row with the aggregate extent?
2. Would having an aggregate extent function built into the mysql
part of spatial_adapter be useful? If so, I'll clean up my code and
can probably get a patch out within the next day or two
Thanks!
-Chris
More information about the Georuby-devel
mailing list