Geometry columns

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?

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. ), 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
[email protected]

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-

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
[email protected]

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-