Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
74af3fb
WIP line simplifier for use in geo_line
craigtaverner Mar 24, 2023
9063a0d
Generalize error calc including triangle area
craigtaverner Mar 28, 2023
1af51da
Support polygon and multipolygon simplification
craigtaverner Mar 28, 2023
ab71c3a
Refinements and more negative tests
craigtaverner Mar 30, 2023
ad147df
Remove system.out.println
craigtaverner Mar 30, 2023
164481f
Update docs/changelog/94859.yaml
craigtaverner Mar 29, 2023
2b96996
Export new simplification code from geo module
craigtaverner Apr 5, 2023
80e65fb
Util for selecting calculator
craigtaverner Apr 5, 2023
74d1b91
Initial microbenchmarks for geo simplification
craigtaverner Apr 5, 2023
0c1d3cb
Add spherical area calculation for simplification
craigtaverner Apr 6, 2023
e274cef
Fixed numerical error in flat triangle areas
craigtaverner Apr 11, 2023
6fe869e
Add lucene license notice
craigtaverner Apr 11, 2023
4c241a0
Fixed bug with co-located points in frechet error
craigtaverner Apr 11, 2023
1791330
Remove dependency on lucene
craigtaverner Apr 24, 2023
605d5a3
Added support for simplifier monitor
craigtaverner May 5, 2023
6499b8b
Refinements in support of visualization monitor
craigtaverner May 5, 2023
3286ab7
Don't create more objects than actually needed
craigtaverner May 8, 2023
65cf706
Benchmark triangleheight
craigtaverner May 8, 2023
a0b5e05
Support back-paths in simple-frechet error
craigtaverner May 8, 2023
362176a
Added GeometryCollection support
craigtaverner May 9, 2023
0cf3ed1
Generalize Point simplifier to identity simplifier
craigtaverner May 9, 2023
8f62e44
Use identity simplifier for Rectangle, Circle and MultiPoint
craigtaverner May 9, 2023
fc48ad0
Split out streaming simplifier for clarity
craigtaverner May 9, 2023
cf6a254
Renamed Frechet error and removed registry
craigtaverner May 10, 2023
bd5721e
Improved comments
craigtaverner May 10, 2023
1b8689b
WIP Added spherical height and backpath calculator
craigtaverner May 10, 2023
3307dc6
Test for spherical backpath calculator
craigtaverner May 10, 2023
26a1da5
spotless
craigtaverner May 10, 2023
d2bc91c
Javadocs warning of invalid polygons
craigtaverner May 11, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.benchmark.spatial;

import org.elasticsearch.geometry.LinearRing;
import org.elasticsearch.geometry.simplify.GeometrySimplifier;
import org.elasticsearch.geometry.simplify.SimplificationErrorCalculator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;

@Fork(1)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Thread)
public class GeometrySimplificationBenchmark {
@Param({ "cartesiantrianglearea", "triangleArea", "triangleheight", "heightandbackpathdistance" })
public String calculatorName;

@Param({ "10", "100", "1000", "10000", "20000" })
public int maxPoints;

private GeometrySimplifier<LinearRing> simplifier;
private static LinearRing ring;

@Setup
public void setup() throws ParseException, IOException {
SimplificationErrorCalculator calculator = SimplificationErrorCalculator.byName(calculatorName);
this.simplifier = new GeometrySimplifier.LinearRingSimplifier(maxPoints, calculator);
if (ring == null) {
ring = loadRing("us.json.gz");
}
}

@Benchmark
public void simplify(Blackhole bh) {
bh.consume(simplifier.simplify(ring));
}

private static LinearRing loadRing(@SuppressWarnings("SameParameterValue") String name) throws IOException, ParseException {
String json = loadJsonFile(name);
org.apache.lucene.geo.Polygon[] lucenePolygons = org.apache.lucene.geo.Polygon.fromGeoJSON(json);
LinearRing ring = null;
for (org.apache.lucene.geo.Polygon lucenePolygon : lucenePolygons) {
double[] x = lucenePolygon.getPolyLons();
double[] y = lucenePolygon.getPolyLats();
if (ring == null || x.length > ring.length()) {
ring = new LinearRing(x, y);
}
}
return ring;
}

private static String loadJsonFile(String name) throws IOException {
InputStream is = GeometrySimplificationBenchmark.class.getResourceAsStream(name);
if (is == null) {
throw new FileNotFoundException("classpath resource not found: " + name);
}
if (name.endsWith(".gz")) {
is = new GZIPInputStream(is);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
StringBuilder builder = new StringBuilder();
reader.lines().forEach(builder::append);
return builder.toString();
}
}
Binary file not shown.
5 changes: 5 additions & 0 deletions docs/changelog/94859.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 94859
summary: Geometry simplifier
area: Geo
type: feature
issues: []
1 change: 1 addition & 0 deletions libs/geo/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
module org.elasticsearch.geo {
exports org.elasticsearch.geometry;
exports org.elasticsearch.geometry.utils;
exports org.elasticsearch.geometry.simplify;
}
Loading