Is there anything like http://jsonlint.com or http://geojsonlint.com for WKT? How can I validate a complex WKT string, say e.g. a Multipolygon?
[GIS] Well-known text (wkt) validator
validationwell-known-text
Related Solutions
At the moment I got it working like this. But i have the feeling it's not the best way to do it.
If anybody have a better way to do it, please say it.
I'm using gson 2.3.1
InputStream in = new FileInputStream(context.getExternalFilesDir(null).getPath() + "/" + jsonDatabaseFile);
JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"))
;
if (tag.equals("geometry")) {
reader.beginObject();
while (reader.hasNext()) {
tag = reader.nextName();
// geometry type
// ----------------------------------------------------------------------------------
if (tag.equals("type")) {
type = reader.nextString();
}
// geometry coordinates
// ----------------------------------------------------------------------------------
else if (tag.equals("coordinates")) {
coordinates.append("(");
reader.beginArray();
while (reader.hasNext()) {
coordinates.append("(");
reader.beginArray();
while (reader.hasNext()) {
coordinates.append("(");
reader.beginArray();
while (reader.hasNext()) {
reader.beginArray();
while (reader.hasNext()) {
if(!even){
coordinates.append((reader.nextString()));
coordinates.append(" ");
even = true;
}
else{
coordinates.append((reader.nextString()));
coordinates.append(",");
even = false;
}
}
reader.endArray();
}
reader.endArray();
coordinates.deleteCharAt(coordinates.length() -1);
coordinates.append("),");
}
reader.endArray();
coordinates.deleteCharAt(coordinates.length() -1);
coordinates.append("),");
}
coordinates.deleteCharAt(coordinates.length() -1);
reader.endArray();
}
else {
reader.skipValue();
}
}
reader.endObject();
coordinates.append(")");
}
(...)
wkt = type.toUpperCase() + coordinates;
Best Answer
One possible WKT validator can be PostGIS or a whatever spatial DBMS you like. For instance:
is executed successfully, because
POINT(-71.064544 42.28787)
is a valid WKT representation. Instead:returns:
because
POINT(-71.064544, 42.28787)
is not a valid WKT. Hope this helps.