简体   繁体   English

如何在mysql中从LINESTRING提取X和Y坐标

[英]How to extract X and Y coordinates from LINESTRING in mysql

I am trying to extract X and Y coordinates for specific point inside linestring, but without success. 我试图提取线串内特定点的X和Y坐标,但是没有成功。 I want to get same results like when I am running SELECT X(POINT(56.7, 53.34)) query and get 56.7 result, but for linestring. 我想获得与运行SELECT X(POINT(56.7,53.34))查询时相同的结果,并获得56.7结果,但对于线串。 Here is the example code: 这是示例代码:

SET @ls = 'LineString(1 1,2 2,3 3)';
SELECT AsText(PointN(GeomFromText(@ls),2));//here is the result POINT(2 2)  
select X(AsText(PointN(GeomFromText(@ls),2))));//here I am expecting result 2, but I get null

Could anyone help me with this? 有人可以帮我吗?

Thanks in advance! 提前致谢!

You can don't need the AsText function call. 您不需要AsText函数调用。 Use simply 简单使用

SET @ls = 'LineString(1 1,2 2,3 3)';
SELECT X(PointN(GeomFromText(@ls),2)); -- returns 2

The function PointN returns a Point object and you need exactly that, not the text representation of it. PointN函数返回一个Point对象,而您确实需要该对象,而不是其文本表示形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM