In MySql database I have points (pairs of latitudes and longitudes represented as doubles) like this:

45.045664| 46.084528
26.938933| 60.903848

Now, what I need is to get these points from my database (which is not a problem at all) and echo them in a WKT format or WKT line (this part I don't know). This PHP script is going to be a part of an API used by Windows App.

How can I convert points to WKT format?

Perhaps there is a plugin I can use.


You can just use string concatenation to create the WKT you need. So if you want points just do:

"POINT("+lat+" "+lon+")"

or for LineStrings:

line = "LINESTRING(";
for(int i=0;i<coords.length;i++){
    line+=coords[i].x+" "+coords[i].y+",";
line=line.substring(0:len-1); //remove last comma
| improve this answer | |
  • Oh, I also thought about this way but it seemed so simple to me. Thank you. – NutCracker Sep 3 '16 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.