Skip to content

Commit

Permalink
build: update dependencies (#1831)
Browse files Browse the repository at this point in the history
  • Loading branch information
takb authored Aug 2, 2024
2 parents 3c0d2b3 + 2162ca7 commit 6319386
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 149 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ RELEASING:
## [unreleased]

### Added
- updated dependencies: spring, swagger, geotools etc. ([#1827](https://github.com/GIScience/openrouteservice/pull/1827))
### Changed
- updated dependencies: guava, commons, rest-assured etc. ([#1831](https://github.com/GIScience/openrouteservice/pull/1831))
- updated dependencies: spring, swagger, geotools etc. ([#1827](https://github.com/GIScience/openrouteservice/pull/1827))
### Deprecated
### Removed
### Fixed
Expand Down
9 changes: 0 additions & 9 deletions ors-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,10 @@
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>commons-compiler</artifactId>
<version>3.1.10</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<!-- TODO: remove this if nothing breaks
Expand Down Expand Up @@ -364,13 +362,6 @@
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
9 changes: 0 additions & 9 deletions ors-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>hppc</artifactId>
<version>0.8.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -96,11 +95,6 @@
<artifactId>gt-metadata</artifactId>
</dependency>

<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-opengis</artifactId>
</dependency>

<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
Expand Down Expand Up @@ -140,7 +134,6 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -178,14 +171,12 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${jupiter.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${jupiter.version}</version>
<scope>test</scope>
</dependency>

Expand Down
106 changes: 5 additions & 101 deletions ors-engine/src/main/java/org/heigit/ors/jts/JTS.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
*/
package org.heigit.ors.jts;

import org.geotools.geometry.GeneralDirectPosition;
import org.geotools.metadata.i18n.ErrorKeys;
import org.geotools.metadata.i18n.Errors;
import org.geotools.referencing.GeodeticCalculator;
import org.locationtech.jts.algorithm.Orientation;
import org.locationtech.jts.geom.*;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.TransformException;

import java.util.*;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* JTS Geometry utility methods, bringing Geotools to JTS.
Expand All @@ -48,29 +46,12 @@
* @since 2.2
*/
public final class JTS {
/**
* A pool of direct positions for use in {@link #orthodromicDistance}.
*/
private static final GeneralDirectPosition[] POSITIONS = new GeneralDirectPosition[4];
private static final GeometryFactory factory;

static {
for (int i = 0; i < POSITIONS.length; i++) {
POSITIONS[i] = new GeneralDirectPosition(i);
}

factory = new GeometryFactory();
}

/**
* Geodetic calculators already created for a given coordinate reference system. For use in
* {@link #orthodromicDistance}.
* <p>
* Note: We would like to use {@link org.geotools.util.CanonicalSet}, but we can't because
* {@link GeodeticCalculator} keep a reference to the CRS which is used as the key.
*/
private static final Map<CoordinateReferenceSystem, GeodeticCalculator> CALCULATORS = new HashMap<>();

/**
* Do not allow instantiation of this class.
*/
Expand All @@ -86,64 +67,10 @@ private JTS() {
*/
private static void ensureNonNull(final String name, final Object object) throws IllegalArgumentException {
if (object == null) {
throw new IllegalArgumentException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1, name));
}
}


/**
* Computes the orthodromic distance between two points. This method:
* <p>
* <ol>
* <li>Transforms both points to geographic coordinates
* (<var>latitude</var>,<var>longitude</var>).</li>
* <li>Computes the orthodromic distance between the two points using ellipsoidal calculations.</li>
* </ol>
* <p>
* The real work is performed by {@link GeodeticCalculator}. This convenience method simply
* manages a pool of pre-defined geodetic calculators for the given coordinate reference system
* in order to avoid repetitive object creation. If a large amount of orthodromic distances need
* to be computed, direct use of {@link GeodeticCalculator} provides better performance than
* this convenience method.
*
* @param p1 First point
* @param p2 Second point
* @param crs Reference system the two points are in.
* @return Orthodromic distance between the two points, in meters.
* @throws TransformException if the coordinates can't be transformed from the specified CRS to a
* {@linkplain org.opengis.referencing.crs.GeographicCRS geographic CRS}.
*/
public static synchronized double orthodromicDistance(final Coordinate p1, final Coordinate p2,
final CoordinateReferenceSystem crs) throws TransformException {
ensureNonNull("p1", p1);
ensureNonNull("p2", p2);
ensureNonNull("crs", crs);

/*
* Need to synchronize because we use a single instance of a Map (CALCULATORS) as well as
* shared instances of GeodeticCalculator and GeneralDirectPosition (POSITIONS). None of
* them are thread-safe.
*/
GeodeticCalculator gc = CALCULATORS.get(crs);

if (gc == null) {
gc = new GeodeticCalculator(crs);
CALCULATORS.put(crs, gc);
throw new IllegalArgumentException(MessageFormat.format(ErrorKeys.NULL_ARGUMENT_$1, name));
}
if (!crs.equals(gc.getCoordinateReferenceSystem())) throw new AssertionError(crs);

final GeneralDirectPosition pos = POSITIONS[Math.min(POSITIONS.length - 1, crs
.getCoordinateSystem().getDimension())];
pos.setCoordinateReferenceSystem(crs);
copy(p1, pos.ordinates);
gc.setStartingPosition(pos);
copy(p2, pos.ordinates);
gc.setDestinationPosition(pos);

return gc.getOrthodromicDistance();
}


/**
* Copies the ordinates values from the specified JTS coordinates to the specified array. The
* destination array can have any length. Only the relevant field of the source coordinate will
Expand Down Expand Up @@ -175,7 +102,6 @@ public static void copy(final Coordinate point, final double[] ordinates) {
}
}


/**
* Creates a smoothed copy of the input Geometry. This is only useful for polygonal and lineal
* geometries. Point objects will be returned unchanged. The smoothing algorithm inserts new
Expand Down Expand Up @@ -220,18 +146,15 @@ public static Geometry smooth(final Geometry geom, double fit) {
* @throws IllegalArgumentException if either {@code geom} or {@code factory} is {@code null}
*/
public static Geometry smooth(final Geometry geom, double fit, final GeometryFactory factory) {

ensureNonNull("geom", geom);
ensureNonNull("factory", factory);

// Adjust fit if necessary
fit = Math.max(0.0, Math.min(1.0, fit));
return smooth(geom, fit, factory, new GeometrySmoother(factory));
}

private static Geometry smooth(final Geometry geom, final double fit,
final GeometryFactory factory, GeometrySmoother smoother) {

return switch (geom.getGeometryType().toUpperCase()) {
case "POINT", "MULTIPOINT" ->
// For points, just return the input geometry
Expand All @@ -250,55 +173,45 @@ private static Geometry smooth(final Geometry geom, final double fit,

private static Geometry smoothLineString(GeometryFactory factory, GeometrySmoother smoother,
Geometry geom, double fit) {

if (geom instanceof LinearRing linearRing) {
// Treat as a Polygon
Polygon poly = factory.createPolygon(linearRing, null);
Polygon smoothed = smoother.smooth(poly, fit);
return smoothed.getExteriorRing();

} else {
return smoother.smooth((LineString) geom, fit);
}
}

private static Geometry smoothMultiLineString(GeometryFactory factory,
GeometrySmoother smoother, Geometry geom, double fit) {

final int N = geom.getNumGeometries();
LineString[] smoothed = new LineString[N];

for (int i = 0; i < N; i++) {
smoothed[i] = (LineString) smoothLineString(factory, smoother, geom.getGeometryN(i),
fit);
}

return factory.createMultiLineString(smoothed);
}

private static Geometry smoothMultiPolygon(GeometryFactory factory, GeometrySmoother smoother,
Geometry geom, double fit) {

final int N = geom.getNumGeometries();
Polygon[] smoothed = new Polygon[N];

for (int i = 0; i < N; i++) {
smoothed[i] = smoother.smooth((Polygon) geom.getGeometryN(i), fit);
}

return factory.createMultiPolygon(smoothed);
}

private static Geometry smoothGeometryCollection(GeometryFactory factory,
GeometrySmoother smoother, Geometry geom, double fit) {

final int N = geom.getNumGeometries();
Geometry[] smoothed = new Geometry[N];

for (int i = 0; i < N; i++) {
smoothed[i] = smooth(geom.getGeometryN(i), fit, factory, smoother);
}

return factory.createGeometryCollection(smoothed);
}

Expand All @@ -313,13 +226,10 @@ static LineString removeCollinearVertices(final LineString ls) {
if (ls == null) {
throw new NullPointerException("The provided linestring is null");
}

final int N = ls.getNumPoints();
final boolean isLinearRing = ls instanceof LinearRing;

List<Coordinate> retain = new ArrayList<>();
retain.add(ls.getCoordinateN(0));

int i0 = 0;
int i1 = 1;
int i2 = 2;
Expand Down Expand Up @@ -354,7 +264,6 @@ static LineString removeCollinearVertices(final LineString ls) {

return ls;
}

return isLinearRing ? ls.getFactory()
.createLinearRing(retain.toArray(new Coordinate[size])) : ls.getFactory()
.createLineString(retain.toArray(new Coordinate[size]));
Expand Down Expand Up @@ -420,10 +329,8 @@ public static Geometry removeCollinearVertices(final Geometry g) {
part = removeCollinearVertices(part);
parts[i] = part;
}

return g.getFactory().createMultiPolygon(parts);
}

throw new IllegalArgumentException(
"This method can work on LineString, Polygon and Multipolygon: " + g.getClass());
}
Expand All @@ -445,7 +352,6 @@ public static Geometry removeCollinearVertices(final Geometry geometry, int minP
if ((minPoints <= 0) || (geometry.getNumPoints() < minPoints)) {
return geometry;
}

if (geometry instanceof LineString lineString) {
return removeCollinearVertices(lineString);
} else if (geometry instanceof Polygon polygon) {
Expand All @@ -460,7 +366,6 @@ public static Geometry removeCollinearVertices(final Geometry geometry, int minP

return geometry.getFactory().createMultiPolygon(parts);
}

throw new IllegalArgumentException(
"This method can work on LineString, Polygon and Multipolygon: "
+ geometry.getClass());
Expand All @@ -472,7 +377,6 @@ public static Polygon toGeometry(final Envelope env) {

public static Polygon toGeometry(final Envelope env, GeometryFactory factory) {
ensureNonNull("env", env);

return factory.createPolygon(factory.createLinearRing(new Coordinate[]{
new Coordinate(env.getMinX(), env.getMinY()),
new Coordinate(env.getMaxX(), env.getMinY()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@

import com.graphhopper.util.DistanceCalcEarth;
import org.apache.log4j.Logger;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.api.data.FileDataStore;
import org.geotools.api.data.FileDataStoreFinder;
import org.geotools.api.data.SimpleFeatureSource;
import org.geotools.api.feature.Property;
import org.geotools.api.feature.simple.SimpleFeature;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.feature.DefaultFeatureCollection;
import org.heigit.ors.util.CSVUtility;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.MultiLineString;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -181,7 +180,7 @@ private Map<Integer, TrafficPattern> readPatterns() {
* @return A (Geo)JSON object representing the contents of the file
*/
private SimpleFeatureCollection readHereGeometries() throws IOException {
SimpleFeatureCollection collection = new DefaultFeatureCollection();
SimpleFeatureCollection collection;
try {
File file = new File(streetGeometriesFile);
FileDataStore store = FileDataStoreFinder.getDataStore(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.graphhopper.util.DistanceCalcEarth;
import org.apache.log4j.Logger;
import org.geotools.api.feature.Property;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.opengis.feature.Property;

import java.io.InvalidObjectException;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.heigit.ors.routing.graphhopper.extensions.reader.traffic;

import org.apache.log4j.Logger;
import org.geotools.api.feature.Property;
import org.heigit.ors.routing.graphhopper.extensions.TrafficRelevantWayType;
import org.opengis.feature.Property;

import java.util.Collection;

Expand Down
Loading

0 comments on commit 6319386

Please sign in to comment.