Forum: Ruby on Rails geometry columns

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C3e347393bfc91e02e52656bbea76140?d=identicon&s=25 magic_hat (Guest)
on 2009-06-04 20:22
(Received via mailing list)
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?
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-06-04 23:24
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 ( 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
marnen@marnen.org
C3e347393bfc91e02e52656bbea76140?d=identicon&s=25 magic_hat (Guest)
on 2009-06-05 01:44
(Received via mailing list)
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-
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-06-05 05:31
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
marnen@marnen.org
C3e347393bfc91e02e52656bbea76140?d=identicon&s=25 magic_hat (Guest)
on 2009-06-05 21:20
(Received via mailing list)
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-
This topic is locked and can not be replied to.