将 MySQL 中的 WKT 多边形转换为 Google 地图多边形
我在 MySQL 中有一列 WKT POLYGON 值(我继承了数据库)。在 Google 地图上查询并渲染多边形。由于 Google 地图多边形叠加需要点数组,因此之前的用户将 WKT 值转换为坐标对并将其存储在另一列中。这实际上效果相当好,但还不够好。
其一,转换偶尔会出现错误;其二,我正在寻找加快转换速度的方法。
关于。第一个问题,我必须重新实现它,并且正在寻找一个将 WKT 多边形转换为坐标字符串的转换器。我想我可以用它来编写一个存储过程来查询 WKT 列并吐出一串可以轻松转换为 Google 地图多边形的 JSON 文本,或者甚至预处理所有 WKT 多边形并将它们存储为文本,例如它已经完成了,但这次使用了正确的值。
所以,我真的在寻找一个函数来将 WKT 转换为其组成点坐标的字符串,有点像
SELECT AsStringOfCoords(WKT_Column) FROM table WHERE condition
AsStringOfCoords()
是我的自定义函数。
I have a column of WKT POLYGON values in MySQL (I inherited the db). The polys are queried and rendered on Google Maps. Since Google Maps polygon overlay requires an array of points, the previous user converted the WKT values to coordinate pairs and stored them in another column. This actually works rather well, but not well enough.
For one, the conversion was occasionally faulty, and for two, I am looking for ways to make this faster.
Re. the first issue, I have to re-implement this, and am looking for a converter that will convert a WKT poly into a string of coordinates. I am thinking I could use this to either write a stored procedure that will query the WKT column and spit out a string of JSON text that could be readily converted to Google Maps polys, or even preprocess all the WKT polys and store them as text like it is already done, but this time with correct values.
So, I am really looking for a function to convert WKT to a string of its constituent point coordinates, kinda like so
SELECT AsStringOfCoords(WKT_Column) FROM table WHERE condition
where AsStringOfCoords()
would be my custom function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我编写了一个小 C++ 程序来将 MySQL WKT 多边形转换为 KML 多边形。
这个东西的工作原理如下:
源代码在这里...
我希望这可以帮助你。很容易将其转换为 MySQL 存储过程,或者在 PHP 或其他语言中使用它......我也有一些 php/javascript 脚本来用点做同样的事情。
I'd wrote a little C++ program to do MySQL WKT polygons to KML polygons.
This thing works as follows:
The source code is here...
I hope this can help you. Is easy to translate this to MySQL stored proc, or use it inside PHP or another languages... I also have some php/javascript scripts to do the same things with points.