title: RGeo contains? on Model
body: <p>I need to find all the instances of a class <code>Place</code> where its polygon attribute contains a point supplied, as in <code>Place.for_point(pt)</code>.</p>
  
  <p>==== added ====</p>
  
  <p>Ok, I can get this query to execute, but with the wrong result:</p>
  
  <pre><code>Place.all.where("ST_Contains(poly, ST_Point(#{up_pt.join(',')}))")
  Place Load (0.5ms)  SELECT  "places".* FROM "places" WHERE (ST_Contains(poly, ST_Point(25.1,25.09999999999999))) LIMIT $1  [["LIMIT", 11]]
  =&gt; #&lt;ActiveRecord::Relation []&gt;
  </code></pre>
  
  <p>It seems clear that the coordinates are correctly supplied: the coordinates in the point supplied are in latlon format. But the coordinates are from the centroid of one of the polygons in the table, so they should be inside that polygon, and that means I should be getting a returned set of Place records... But I'm not.</p>
  
  <p>Why? What am I missing?</p>
  
  <p>Here's the polygon I'm expecting to contain the point: </p>
  
  <pre><code>f.unproject(Place.last[:poly])
    Place Load (0.3ms)  SELECT  "places".* FROM "places" ORDER BY "places"."id" DESC LIMIT $1  [["LIMIT", 1]]
  =&gt; #&lt;RGeo::Geographic::ProjectedPolygonImpl:0x3fcdc30f807c "POLYGON ((24.999999999999996 24.999999999999996, 25.2 24.999999999999996, 25.2 25.20000000000001, 24.999999999999996 25.20000000000001, 24.999999999999996 24.999999999999996))"&gt;
  irb(main):134:0&gt; 
  </code></pre>
  
  <p>==== original post ====</p>
  
  <p>I cannot get my head around how to structure this. For an individual instance I have a method <code>contains?(pt)</code> as an instance method of <code>Place</code> that works fine when called as <code>place.contains?(@f.project(@pt_inside))</code> and <code>@pt_inside</code> is defined thusly: <code>@pt_inside = @f.point(25.1,25.1)</code>, where @f is the factory for the object. </p>
  
  <p>The schema for <code>Place</code> looks like this:</p>
  
  <pre><code>  create_table "places", force: :cascade do |t|
  t.geometry "loc", limit: {:srid=&gt;3857, :type=&gt;"st_point"}
  t.geometry "poly", limit: {:srid=&gt;3857, :type=&gt;"st_polygon"}
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
  </code></pre>
  
  <p>end</p>
  
  <p>My rails is very rusty, but I cannot make a query to the class Place work....</p>