Last active
April 20, 2017 03:38
-
-
Save peteroupc/7fd0f0a570147b43e09550b146ee93da to your computer and use it in GitHub Desktop.
Generates polygon WKT from an array of latitude/longitude coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Any copyright to this file is released to the Public Domain. | |
http://creativecommons.org/publicdomain/zero/1.0/ | |
If you like this, you should donate | |
to Peter O. at: | |
http://peteroupc.github.io/ | |
*/ | |
public static String polygonWkt(double[] latlon){ | |
if(latlon.length%2 != 0) | |
throw new IllegalArgumentException("latlon length is not even"); | |
StringBuilder builder=new StringBuilder(); | |
builder.append("POLYGON(("); | |
for(int i=0;i<latlon.length;i+=2){ | |
if(i>0){ | |
builder.append(","); | |
} | |
builder.append(latlon[i]+" "+latlon[i+1]); | |
} | |
builder.append("))"); | |
return builder.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment