Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

i want to extract lat long form WKT data and stores into arary list i have tried one solution which is proposed by a user but it has some problems

    String str = tv.getText().toString();

    str = str.replaceAll("\\(", "");
    str = str.replaceAll("\\)", "");


    String[] a = str.split(",");
    for (String b : a) {
        System.out.println("-" + b + "-");
        coordinates.add(b);
    }

my data is like

POINT(73.0185097465598 33.6810265037665)

MULTILINESTRING((73.0111429810373 33.6783008666403,73.0116544995556 33.6785708996273),(73.0119205001311 33.6783781002692,73.0118432996287 33.678392400389,73.0117917999517 33.6784137997571,73.0117403002747 33.6784638002642,73.0116544995556 33.6785708996273),(73.0131224998036 33.679001500419,73.0119635003153 33.678392400389,73.0119205001311 33.6783781002692),(73.0131224998036 33.679001500419,73.0136031002029 33.6783443999742),(73.0136031002029 33.6783443999742,73.0147099372139 33.67685138958),(73.0147099372139 33.67685138958,73.0150124997272 33.6770292997624,73.0154158996241 33.6773507003746,73.0157677998441 33.6776577999676,73.016042399737 33.6779721004322,73.0162998999205 33.6783149004124,73.0167443997343 33.6789772996627),(73.0167443997343 33.6789772996627,73.0171146002587 33.6794933999005,73.0173738999856 33.6798920001158),(73.0173738999856 33.6798920001158,73.0175952995835 33.6801933998056,73.017689300321 33.6802989001741),(73.017689300321 33.6802989001741,73.017964400237 33.680586200293,73.0185097465598 33.6810265037665))

MULTILINESTRING((73.0185097465598 33.6810265037665,73.0186117996948 33.681108899756),(73.0186117996948 33.681108899756,73.0186413001559 33.681120000088,73.0186946002756 33.681164699991),(73.0186946002756 33.681164699991,73.0187495002893 33.681095800231),(73.0187495002893 33.681095800231,73.0193249000242 33.6803637997496),(73.0193249000242 33.6803637997496,73.0195480002401 33.6800851996723),(73.0195480002401 33.6800851996723,73.0197712002807 33.6797852002269),(73.0197712002807 33.6797852002269,73.0200115000308 33.6794780997346),(73.0200115000308 33.6794780997346,73.020199700256 33.6792233002152),(73.020199700256 33.6792233002152,73.0206966997929 33.679470600288),(73.0209198998336 33.6791562998234,73.0206966997929 33.679470600288),(73.0211343998328 33.6788777995708,73.0209198998336 33.6791562998234),(73.0218726002404 33.6792491997908,73.0211343998328 33.6788777995708),(73.0218726002404 33.6792491997908,73.0218305002774 33.6789161997229),(73.0218305002774 33.6789161997229,73.0218210996641 33.6788205999907),(73.0218210996641 33.6788205999907,73.021797999678 33.6786753001251,73.0217789997012 33.6784876997476),(73.0217789997012 33.6784876997476,73.0217188998074 33.6780734000674),(73.0217188998074 33.6780734000674,73.0217095000934 33.6779850003076),(73.0217095000934 33.6779850003076,73.0217035996415 33.6778538998377,73.0217102995907 33.6776591003872),(73.0217102995907 33.6776591003872,73.0217008998767 33.6775563996082),(73.0217008998767 33.6775563996082,73.0217635997104 33.6773682002823,73.0217961003098 33.6773020002871),(73.0217961003098 33.6773020002871,73.0218382002728 33.6772349998954),(73.0214683032023 33.6770434798131,73.0218382002728 33.6772349998954))

is stores values like [0] = POINT(73.0166738279393 33.6788721326803) MULTILINESTRING((73.0131224998036 33.679001500419; [1] = 73.0119635003153 33.678392400389; then again [2] = POINT(73.0166738279393 33.6788721326803) MULTILINESTRING((73.0131224998036 33.679001500419; and so on i want to draw this data on google map

anyone help me my platform is android

share|improve this question

3 Answers 3

up vote 3 down vote accepted

I would recommend a different strategy, that consists on using the Java library JTS Topology Suite, which is open source software.

By using the class WKTReader you can get, for example, an instance of the MultiLineString class from the WKT you have. This class has methods to get the coordinates you need.

share|improve this answer

While this is not Android-specific, the PySAL guys have a great little module that deals with WKTs available here. This is in Python, but should be easy to translate into Java/Dalvik.

If OpenJUMP can run on Android, you may want to consider their WKTReader, which you then feed directly to the Maps API.

Hope this helps. My Android development skills are limited.

share|improve this answer

First, chop off the "MULTILINESTRING(" part from the beginning and then chop off the last character of the string which is the closing ")" of the MULTILINESTRING. This way you managed to get rid of the Multilinestring that wrapped the data. The data format now looks like this: (lng1 lat1, lng2 lat2),(lng3 lat3, lng4 lat4) and so on... Now you can explode this string by the occurences of "),(" so therefore you will have values like this in the results array: (lng1 lat1,lng2 lat2 for example. This command will leave 2 brackets in your string: One at the very beginning and one at the very end. You can easily get rid of them, by replacing them with "". Once you have done that you will have an array, that stores the polylines that the multilinestring consisted of. --

array([lng1 lat1,lng2 lat2], [lng3 lat3,lng4 lat4, lng5 lat5])

and so on, which is way nicer than the initial format. From this point loop thru the array, explode it by the "," and assign the result array to a new array. This time you will have an array of arrays in the following format:

array(array([lng1 lat1], [lng2 lat2]), array([lng3 lat3], [lng4 lat4], [lng5 lat5]))

Now that you have the coordinates of the multilinestring as a separate array member you can format them any way you want. I know this is a bit crude, and my apologies for that, but if it helped you even just a little, I am happy ;) However if something is unclear drop a comment and I will try to explain it better!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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