How could I transfer the value of point's X and Y?

梦想的初衷 提交于 2020-01-06 23:42:14

问题


The function as follows:

create or replace function point_to_M(x float,y float, i integer)
    returns float AS
    $$
    DECLARE
        geo geometry;
        geo1 geometry;
    begin
      select testo.geom into geo from testo where lineid=i;
      geo1=st_astext(st_line_interpolate_point(st_geometryN(geo,1),'point(x y)')');
      return st_X(geo1);
    end;
    $$
    language plpgsql;

when I input the SQL:

select point_to_M(80,0,0);

The error is:

ERROR:  invalid input syntax for type double precision: "point(x y)"
LINE 1: ...ext(st_line_interpolate_point(st_geometryN(geo,1),'point(x y...

So I think the reason maybe is that the paramater didn't transfer into the function, but I am not sure, so does anyone had this problem? Could you tell me the solution? Thanks very much.


回答1:


Just convert lat long to point

create or replace function point_to_M(x float,y float, i integer)
    returns float AS
    $$
    DECLARE
        geo geometry;
        geo1 geometry;
    begin
      select testo.geom into geo from testo where lineid=i;
      geo1=st_astext(st_line_interpolate_point(st_geometryN(geo,1),st_makepoint(x y)));
      return st_X(geo1);
    end;
    $$
    language plpgsql;


来源:https://stackoverflow.com/questions/31247765/how-could-i-transfer-the-value-of-points-x-and-y

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!