简体   繁体   中英

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. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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