Postgis ST_DWithin in a ruby query

المشرف العام

Administrator
طاقم الإدارة
The following is being attempted in the console for a postgis enabled rails4.2 application.

@target = Target.last@meter_radius = 2500@valid_points = Target.where("ST_DWithin(#{@target.lat}, #{@target.lon}, #{@meter_radius}))lat and lon are defined as decimal values. This translates into the following query

SELECT "targets".* FROM "targets" WHERE (ST_DWithin(38.656679, 15.984094, 2500))with the error:pG::UndefinedFunction: ERROR: function st_dwithin(numeric, numeric, integer) does not exist

I believe I need to declare the data type (geometric or geographic) for these values but am not sure how. I am also wondering whether the ST_DWithin function can work off of the 3857 data type, even though the documentation does not state so.

note the @target object also has a lonlat attributes defined as a spatial value in postgresql with :srid=>3857, :type=>"point" defined.

@valid_points = Target.where("ST_DWithin(ST_GeogFromText('SRID=3857;#{@target.lonlat}'), geography(geometry), #{@meter_radius})").allreturns PG::UndefinedColumn: ERROR: column "geometry" does not exist



أكثر...
 
أعلى