MySQL选择空间字段值并使用PHP转换为WKT

时间:2021-07-01 20:17:14

If selecting a spatial field value from MySQL without converting it to text in the query, I get an "unreadable" string in PHP. Which function can I use to convert this to WKT?

如果从MySQL中选择空间字段值而不将其转换为查询中的文本,我在PHP中会得到一个“不可读”的字符串。我可以使用哪个功能将其转换为WKT?

Example:

SELECT AsText(polygon_field) FROM Table; // gives a nice WKT string.
SELECT polygon_field FROM Table; // gives an unreadable (binary?) string.

Due to limitations in the framework we use, it would be great if that string could be converted to WKT using PHP. Any ideas on what function to use? Can't seem to find anything, because all examples I find rely on the MySQL function AsText :-(

由于我们使用的框架的限制,如果使用PHP将该字符串转换为WKT将会很棒。关于使用什么功能的任何想法?似乎找不到任何东西,因为我找到的所有例子都依赖于MySQL函数AsText :-(

1 个解决方案

#1


1  

The result is the internal format of the column of MySQL (see the manual on fetching values). This format is neither WKB (well known binary) nor WKT (well known text).

结果是MySQL列的内部格式(请参阅有关获取值的手册)。这种格式既不是WKB(众所周知的二进制)也不是WKT(众所周知的文本)。

I would not expect any other software to be able to parse those values, especially since MySQL provides the helper functions AsText and AsBinary, which are easy to use (if one does not use a hindering framework).

我不希望任何其他软件能够解析这些值,特别是因为MySQL提供了易于使用的辅助函数AsText和AsBinary(如果不使用阻碍框架)。

You can create a view, which contains the AsText output of the column as the column itself. This only helps you while selecting, but maybe that is all you need.

您可以创建一个视图,其中包含列的AsText输出作为列本身。这只会在您选择时帮助您,但也许这就是您所需要的。

#1


1  

The result is the internal format of the column of MySQL (see the manual on fetching values). This format is neither WKB (well known binary) nor WKT (well known text).

结果是MySQL列的内部格式(请参阅有关获取值的手册)。这种格式既不是WKB(众所周知的二进制)也不是WKT(众所周知的文本)。

I would not expect any other software to be able to parse those values, especially since MySQL provides the helper functions AsText and AsBinary, which are easy to use (if one does not use a hindering framework).

我不希望任何其他软件能够解析这些值,特别是因为MySQL提供了易于使用的辅助函数AsText和AsBinary(如果不使用阻碍框架)。

You can create a view, which contains the AsText output of the column as the column itself. This only helps you while selecting, but maybe that is all you need.

您可以创建一个视图,其中包含列的AsText输出作为列本身。这只会在您选择时帮助您,但也许这就是您所需要的。