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,

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.

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,

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