use of de.lmu.ifi.dbs.elki.data.ExternalID in project elki by elki-project.
the class SimplePolygonParser method parseLine.
/**
* Parse a single line.
*
* @return {@code true} if the line was read successful.
*/
private boolean parseLine() {
cureid = null;
curpoly = null;
curlbl = null;
polys.clear();
coords.clear();
labels.clear();
Matcher m = COORD.matcher(reader.getBuffer());
for (; /* initialized by nextLineExceptComments */
tokenizer.valid(); tokenizer.advance()) {
m.region(tokenizer.getStart(), tokenizer.getEnd());
if (m.find()) {
try {
double c1 = ParseUtil.parseDouble(m.group(1));
double c2 = ParseUtil.parseDouble(m.group(2));
if (m.group(3) != null) {
double c3 = ParseUtil.parseDouble(m.group(3));
coords.add(new double[] { c1, c2, c3 });
} else {
coords.add(new double[] { c1, c2 });
}
continue;
} catch (NumberFormatException e) {
LOG.warning("Looked like a coordinate pair but didn't parse: " + tokenizer.getSubstring());
}
}
// Match polygon separator:
// FIXME: Avoid unnecessary subSequence call.
final int len = tokenizer.getEnd() - tokenizer.getStart();
if (//
POLYGON_SEPARATOR.length() == len && reader.getBuffer().subSequence(tokenizer.getStart(), tokenizer.getEnd()).equals(POLYGON_SEPARATOR)) {
if (!coords.isEmpty()) {
polys.add(new Polygon(new ArrayList<>(coords)));
}
continue;
}
String cur = tokenizer.getSubstring();
// First label will become the External ID
if (cureid == null) {
cureid = new ExternalID(cur);
} else {
labels.add(cur);
}
}
// Complete polygon
if (!coords.isEmpty()) {
polys.add(new Polygon(coords));
}
curpoly = new PolygonsObject(polys);
curlbl = (haslabels || !labels.isEmpty()) ? LabelList.make(labels) : null;
return true;
}
Aggregations