# Geometry columns

**URL:** <https://www.ruby-forum.com/t/geometry-columns/169519>\
**Category:** Rails\
**Created:** [June 4, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/geometry-columns/169519 "2009-06-04T20:22:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![magic\_hat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@magic\_hat](https://www.ruby-forum.com/u/magic_hat)\
**Post date:** [June 4, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/geometry-columns/169519/1 "2009-06-04T20:22:41Z")

</div>

Hi all. I’m building an app with postgres, postgis and rails. Rails  
seems to be choking when I try to do stuff that involves manipulating  
the geometry column. For example:

self.the\_geom=ActiveRecord::Base.connection.execute(“select  
ST\_PointFromText(‘POINT(’ || #{self.lng}|| ’ ’ || #{self.lat} || ‘)’,  
4326);”)

self.neighborhood\_id=ActiveRecord::Base.connection.execute(“SELECT  
neighborhoods.id FROM neighborhoods, items WHERE ST\_Contains  
(neighborhoods.the\_geom,#{self.the\_geom}.);”)

Anyone got suggestions on how to get this going?

---

<div class="post-metadata">

**Author:** ![magic\_hat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@magic\_hat](https://www.ruby-forum.com/u/magic_hat)\
**Post date:** [June 4, 2009, 11:24pm UTC](https://www.ruby-forum.com/t/geometry-columns/169519/2 "2009-06-04T23:24:46Z")

</div>

magic\_hat wrote:

> Hi all. I’m building an app with postgres, postgis and rails. Rails  
> seems to be choking when I try to do stuff that involves manipulating  
> the geometry column.  
> […]

Use GeoRuby and/or Spatial adapter. If you like, take a look at the  
codebase for Quorum ( [GitHub - marnen/quorum2: The Quorum calendar system.](http://github.com/marnen/quorum2) ), in which I use  
PostgreSQL, PostGIS, GeoRuby, Spatial Adapter, and YM4R.

If you have any questions, let me know.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![magic\_hat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@magic\_hat](https://www.ruby-forum.com/u/magic_hat)\
**Post date:** [June 5, 2009, 1:44am UTC](https://www.ruby-forum.com/t/geometry-columns/169519/3 "2009-06-05T01:44:58Z")

</div>

Hi, Marnen. Thanks for your thoughts. I have GeoRuby and spatial-  
adapter installed, but I’m not seeing anything in the documentation  
that looks similar to what I’m trying to do.

On Jun 4, 4:24 pm, Marnen Laibow-Koser \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![magic\_hat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@magic\_hat](https://www.ruby-forum.com/u/magic_hat)\
**Post date:** [June 5, 2009, 5:31am UTC](https://www.ruby-forum.com/t/geometry-columns/169519/4 "2009-06-05T05:31:11Z")

</div>

magic\_hat wrote:

> Hi, Marnen. Thanks for your thoughts. I have GeoRuby and spatial-  
> adapter installed, but I’m not seeing anything in the documentation  
> that looks similar to what I’m trying to do.

Well, your first query just seems to be constructing a Point, so you  
could probably use one of the constructors on Point for that.

I _think_ that your second query shouldn’t be hard either, but let me  
check the docs myself before I say that.

And both queries are subject to SQL injection. Never use string  
interpolation like this in your queries – always parameterize!

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![magic\_hat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@magic\_hat](https://www.ruby-forum.com/u/magic_hat)\
**Post date:** [June 5, 2009, 9:20pm UTC](https://www.ruby-forum.com/t/geometry-columns/169519/5 "2009-06-05T21:20:43Z")

</div>

Yeah, it’s the second one that’s really giving me trouble. Any  
thoughts would be appreciated!

On Jun 4, 10:31 pm, Marnen Laibow-Koser \<rails-mailing-list@andreas-
