final String singleSpace = " ";
text = text.replaceAll(anyBlankSeq, singleSpace);
//first tokenize by tuple seperators
StringTokenizer tuples = new StringTokenizer(text, ts);
CoordinateSequence seq = null;
int i = 0;
int ncoords = tuples.countTokens(); //number of coordinates
while (tuples.hasMoreTokens()) {
String tuple = tuples.nextToken();
//next tokenize by coordinate seperator
String[] oords = tuple.split(cs);
//next tokenize by decimal
String x = null;
//next tokenize by decimal
String y = null;
//next tokenize by decimal
String z = null;
//must be at least 1D
x = ".".equals(decimal) ? oords[0] : oords[0].replaceAll(decimal, ".");
//check for 2 and 3 D
if (oords.length > 1) {
y = ".".equals(decimal) ? oords[1] : oords[1].replaceAll(decimal, ".");
}
if (oords.length > 2) {
z = ".".equals(decimal) ? oords[2] : oords[2].replaceAll(decimal, ".");
}
if (seq == null) {
seq = csFactory.create(ncoords, oords.length);
}
seq.setOrdinate(i, CoordinateSequence.X, Double.parseDouble(x));
if (y != null) {
seq.setOrdinate(i, CoordinateSequence.Y, Double.parseDouble(y));
}
if (z != null) {
seq.setOrdinate(i, CoordinateSequence.Z, Double.parseDouble(z));
}
i++;
}