Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ST_线使用ST_3距离定位点_Ruby On Rails_Postgis - Fatal编程技术网

Ruby on rails ST_线使用ST_3距离定位点

Ruby on rails ST_线使用ST_3距离定位点,ruby-on-rails,postgis,Ruby On Rails,Postgis,我有一个功能谁的工作与2D线字符串伟大。。。我试着用3D linestring做同样的事情。。。但结果是零:( 出了什么问题,我该如何解决 def distance_to(poi2, way) distance_sql = <<-SQL SELECT ST_3DDistance(way.path::geometry, pta.lonlat::geometry) + ST_3DDistance(way.path::geometry, ptb.lonl

我有一个功能谁的工作与2D线字符串伟大。。。我试着用3D linestring做同样的事情。。。但结果是零:(

出了什么问题,我该如何解决

def distance_to(poi2, way)
  distance_sql = <<-SQL
    SELECT
      ST_3DDistance(way.path::geometry, pta.lonlat::geometry) +
      ST_3DDistance(way.path::geometry, ptb.lonlat::geometry) +
      ST_Length(ST_LineSubstring(
        way.path,
        least(ST_LineLocatePoint(way.path, pta.lonlat::geometry), ST_LineLocatePoint(way.path, ptb.lonlat::geometry)),
        greatest(ST_LineLocatePoint(way.path, pta.lonlat::geometry), ST_LineLocatePoint(way.path, ptb.lonlat::geometry)))::geography)  AS dst_line
     FROM ways way, pois pta, pois ptb
     WHERE way.id = #{way.id}
       AND pta.id = #{self.id}
       AND ptb.id = #{poi2.id}
  SQL
  Poi.find_by_sql(distance_sql).first.dst_line
end
def距离(poi2,路)

distance_sql=请添加有关您的数据的信息。如果我们不知道数据看起来如何,则很难找到它不工作的原因。我创建了一些测试数据和函数返回结果,因此如果函数返回nil,您的geom可能为空值。问题是St_lineLocatePoint仅与2D linestringNo一起工作,它与3D al一起工作因此(确保在PostGIS 2.3中)检查自己选择ST_LineLocatePoint(ST_geomfromtext('LINESTRING(0 0 0,100 0 10)),ST_geomfromtext('POINT(1 1 1 1)))我在PostGIS 2.2中:返回一个介于0和1之间的浮点值,表示线串上最接近给定点的位置,作为总二维线长度的一部分:(无关-即使不为null,结果也将不正确-从几何体中重新计算点和线串之间的距离(因此它将以该几何体的单位为单位,4326的单位为度而不是米),从地理中重新计算线串的长度(以米为单位而不是以度为单位)。因此,您将添加“a(度)+b(度)+c(米)=非常奇怪的结果”