@Override public Object buildLucene() { // decompose linestrings crossing dateline into array of Lines Coordinate[] coordinates = this.coordinates.toArray(new Coordinate[this.coordinates.size()]); if (wrapdateline) { ArrayList<Line> linestrings = decomposeLucene(coordinates, new ArrayList<>()); if (linestrings.size() == 1) { return linestrings.get(0); } else { return linestrings.toArray(new Line[linestrings.size()]); } } return new Line(Arrays.stream(coordinates).mapToDouble(i->normalizeLat(i.y)).toArray(), Arrays.stream(coordinates).mapToDouble(i->normalizeLon(i.x)).toArray()); }
@Override public Object buildLucene() { if (wrapdateline) { ArrayList<Line> parts = new ArrayList<>(); for (LineStringBuilder line : lines) { LineStringBuilder.decomposeLucene(line.coordinates(false), parts); } if (parts.size() == 1) { return parts.get(0); } return parts.toArray(new Line[parts.size()]); } Line[] linestrings = new Line[lines.size()]; for (int i = 0; i < lines.size(); ++i) { LineStringBuilder lsb = lines.get(i); linestrings[i] = new Line(lsb.coordinates.stream().mapToDouble(c->c.y).toArray(), lsb.coordinates.stream().mapToDouble(c->c.x).toArray()); } return linestrings; }
static ArrayList<Line> decomposeLucene(Coordinate[] coordinates, ArrayList<Line> lines) { for (Coordinate[] part : decompose(+DATELINE, coordinates)) { for (Coordinate[] line : decompose(-DATELINE, part)) { lines.add(new Line(Arrays.stream(line).mapToDouble(i->normalizeLat(i.y)).toArray(), Arrays.stream(line).mapToDouble(i->normalizeLon(i.x)).toArray())); } } return lines; }
/** parses a LINESTRING */ private static Line parseLine(StreamTokenizer stream) throws IOException, ParseException { String token = nextEmptyOrOpen(stream); if (token.equals(EMPTY)) { return null; } ArrayList<Double> lats = new ArrayList(); ArrayList<Double> lons = new ArrayList(); parseCoordinates(stream, lats, lons); return new Line(lats.stream().mapToDouble(i->i).toArray(), lons.stream().mapToDouble(i->i).toArray()); }