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.

1 Answer 1


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
  • Oh, I also thought about this way but it seemed so simple to me. Thank you.
    – NutCracker
    Commented Sep 3, 2016 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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