Find Y value of an interpolated point in a Linestring given an X value on Postgis

倾然丶 夕夏残阳落幕 提交于 2019-12-13 00:03:04

问题


I would like to know what's the best way to find the Y value of an interpolated point inside the Linestring, when given the X.

The X coordinates of my input Linestring will always be incremental and non sequential (as in the example below). The Y values could be any real number.

LINESTRING(223 -59,228 -59.3,233 -59.7,242 -60,263 -60.4,
           268 -61.7,275 -62.1,280 -62.5)

Given an X value (let's say 270 for example), the query would output the interpolated value inside the Linestring (in this case it would be -61.81428571, using points [268 -61.7] and [275 -62.1] for the interpolation)

If the X value already belongs to the Linestring, the it would just output its corresponding Y value. 268: -61.7

The input table will just have a single column with a single row with the linestring. The X value would be part of the query.

I'm using PostGIS.


回答1:


Probably the easiest way will be to generate a vertical line and check intersection between it and the geom. It will be good to make sure the line is as long as the bounding box of the linestring.

SELECT ST_INTERSECTION(geom, ST_MakeLine(ST_MakePoint(268, ST_YMin(geom)), ST_MakePoint(268,ST_YMax(geom)))) 
FROM
    linestrings;


来源:https://stackoverflow.com/questions/25477669/find-y-value-of-an-interpolated-point-in-a-linestring-given-an-x-value-on-postgi

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