[Georuby-devel] [ANN] to_yaml + find_by

Guilhem Vellut guilhem.vellut at gmail.com
Thu May 11 15:17:15 EDT 2006

== to_yaml

Following the discussion with Wayne, I have added a to_yaml method to the
class GeoRuby::SimpleFeatures::Geometry (it is actually added inside the
spatial adapter and the body of the method is different for each database).
It is in the current trunk.

It is useful if you use YAML fixtures for your unit tests, since, at some
point, you will want to input a geometry. You could transform your
geometries to a form suitable for YAML yourself every time but to_yaml does
it for you. You would use it like this, if the geom column is a point:
	 id: 1
	 data: HELLO
	 geom: <%= Point.from_x_y(123.5,321.9).to_yaml %>

== find_by

Also, even though it is not related, a find_by method redefined for
geometric columns has been added. Basically, instead of using the Rails
default '=' operator, it uses a bounding box intersection: && in PostGIS and
MBRIntersects in MySQL, which can both make use of a spatial index if one is
present. You could use this query, for example, to grab only a "map frame"
worth of data for display purpose. 

You have 2 ways to use the find_by_[geom_column]: Either by passing a
geometric object directly, or passing an array with the 2 opposite corners
of a bounding box (with 2 or 3 coordinates depending of the dimension of the

In PostGIS, since you can only perform operations on geometries with the
same SRID, you can add a third element representing the SRID of the bounding
box to the array. It is by default set to -1:


More information about the Georuby-devel mailing list